[Toybox] vmstat spring clean
Rob Landley
rob at landley.net
Thu Apr 12 04:40:53 PDT 2012
On 04/11/2012 12:16 PM, Elie De Brauwer wrote:
> All,
>
> You can find in attachment an enhancement of the vmstat code (with
> respect to what's upstream).
Applied.
This includes:
> - spaces/tabs cleanup (mea culpa)
> - toybuf buffer issues (using xread iso fdlength, and add zero byte at
> the end (nice catch btw) )
> - query the terminal height and update this.
>
> W.r.t. this last one, i only perform the query after printing a header
> so not every loop so there is some transition from going to extremely
> large to extremely small terminal heights. But vmstat isn't doing a
> great job at handling that either. I also think that if this call fails
> on serial consoles, perhaps it makes sense to have teh ascii probing
> implemented in the library itself?
Implementing ascii programming in the library itself was what I was
referring to. (It's on my todo list...) All sorts of stuff needs it:
more, toysh, vi... Even ls wants to know the width of the screen for -C
mode.
The problem is parsing the replies, since the user could type arbitrary
stuff. It's stdout that needs to be a tty (because "ls | blah" is not
going to a tty even if stdin is a tty), but the input _could_ come back
in on stdin if that's another filehandle to the same tty... as could any
other random input. If you're filtering all your input through a line
reading function that needs to parse cursor keys to implement command
history, doing this is easy. But if _all_ you care about is the probe
response and you want to leave the rest of the input alone, it's kinda hard.
What I might wind up doing is adding it to toysh and having that export
COLUMNS and LINES environment variables. It wouldn't catch resizes in
the middle of a command, but I think I'm ok with that...
Also:
toys/vmstat.c:38: warning: format ‘%Lu’ expects type ‘long long unsigned
int *’, but argument 9 has type ‘uint64_t *’
toys/vmstat.c:42: warning: format ‘%Lu’ expects type ‘long long unsigned
int *’, but argument 3 has type ‘uint64_t *’
toys/vmstat.c:45: warning: format ‘%Lu’ expects type ‘long long unsigned
int *’, but argument 3 has type ‘uint64_t *’
Allow me to introduce you to the horror of PRIu64:
http://landley.net/c99-draft.html#B.7
uint64_t one, two;
printf("Two numbers: %"PRIu64" and %"PRIu64"\n", one, two);
(Yes, intended to be used with automatic string concatenation. The same
people who thought uint64_t was a good name did this. Oh well.)
Rob
--
GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code.
Either it's "mere aggregation", or a license violation. Pick one.
More information about the Toybox
mailing list