[Toybox] Cleanups to killall.

Rob Landley rob at landley.net
Sat Feb 18 17:04:58 PST 2012


The signames[] array was kind of ugly.  I know you were trying for
portability, but according to POSIX 2008 (also known as SUSv4 and the
Open Group Base Specifications issue 7) we can rely on the existence of
a longish range of signals:

  http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html

Only a few of the ones in your list aren't in POSIX (they're in the
comment at the end).

I made a SIGNIFY() macro that can produce the array entries, which let
me squash several of them onto each line.

I switched from a NULL terminated array to having the for loop calculate
the length of the array.  The calculation is all compile-time constants,
and according to C99 math involving compile time constants has to be
done at compile time (even tinycc did that much, since the standard
required it to), so it resolves to a single constant it checks against.

I replaced the global "matched" with toys.exitval as in pidof.

I yanked print_signals() and made sig_to_num print signals instead of
checking for them if it got NULL for the string to check for them (that
way there's only one loop iterating over the array).  I also taught
sign_to_num to be case insensitive, and handle an optional "sig" prefix
on names.

I made a couple code paths return instead of exit() when the error code
would be the same, because it's slightly smaller (not pushing a function
argument onto the stack).

Rob

 1329613498.0


More information about the Toybox mailing list