[Toybox] pidof cleanups.

Rob Landley rob at landley.net
Sat Feb 18 16:10:06 PST 2012


At the design level, the new library function should really pass in a
pid_t not a char *, so I changed that.  Also, the large amount of string
manipulation you're doing boils down to a single call to snprintf().

You don't need to zero out global variables, they start prezeroed unless
set to something else by the argument parsing logic.

Sticking "<1" at the start of the option string makes it complain if you
supply less than one argument.

If you return from a command_main() toybox will exit with the value
defined in toys.exitval.  (It defaults to zero. Note that if you set it
to a value _other_ than zero, error_exit() and the various functions
that call it (perror_exit() and anything starting with x) will use that
as their exit code; if toys.exitval is 0 they'll exit with 1.

This means I can just use that global variable, initialize it to 1 and
then set it to 0 if we find any processes, and thus don't have to define
a new global variable just for this program.  (Probably doesn't save any
space in the binary, but saves several lines in the source code.)

Rob


More information about the Toybox mailing list