Commit Graph

42 Commits (eb74f374f258540e2ca7ae0880926f76aaaa5d1a)

Author SHA1 Message Date
Laslo Hunhold e92a1aef54 Handle { NULL } argv[] properly in manual arg-reduction
Thanks izabera for reporting this!
2017-08-05 23:50:39 +02:00
sin 50c8785497 kill: Include strings.h for strcasecmp() 2015-04-29 16:42:49 +01:00
FRIGN 11e2d472bf Add *fshut() functions to properly flush file streams
This has been a known issue for a long time. Example:

printf "word" > /dev/full

wouldn't report there's not enough space on the device.
This is due to the fact that every libc has internal buffers
for stdout which store fragments of written data until they reach
a certain size or on some callback to flush them all at once to the
You can force the libc to flush them with fflush(). In case flushing
fails, you can check the return value of fflush() and report an error.

However, previously, sbase didn't have such checks and without fflush(),
the libc silently flushes the buffers on exit without checking the errors.
No offense, but there's no way for the libc to report errors in the exit-

GNU coreutils solve this by having onexit-callbacks to handle the flushing
and report issues, but they have obvious deficiencies.
After long discussions on IRC, we came to the conclusion that checking the
return value of every io-function would be a bit too much, and having a
general-purpose fclose-wrapper would be the best way to go.

It turned out that fclose() alone is not enough to detect errors. The right
way to do it is to fflush() + check ferror on the fp and then to a fclose().
This is what fshut does and that's how it's done before each return.
The return value is obviously affected, reporting an error in case a flush
or close failed, but also when reading failed for some reason, the error-
state is caught.

the !!( ... + ...) construction is used to call all functions inside the
brackets and not "terminating" on the first.
We want errors to be reported, but there's no reason to stop flushing buffers
when one other file buffer has issues.
Obviously, functionales come before the flush and ret-logic comes after to
prevent early exits as well without reporting warnings if there are any.

One more advantage of fshut() is that it is even able to report errors
on obscure NFS-setups which the other coreutils are unable to detect,
because they only check the return-value of fflush() and fclose(),
not ferror() as well.
2015-04-05 09:13:56 +01:00
sin 756f729172 kill: No need for const int 2015-03-19 10:45:58 +00:00
FRIGN 64da0d1ebc Audit kill(1)
1) Refactor the manpage with num-options, optimize wording to be more
   concise and to the point, pid also specifies process groups.
2) Make int sig const.
3) Remove prototypes.
4) /* not reached */ consistency.
5) Refactor usage() with eprintf.
6) Refactor arg-parser with a switch, use estrtonum
7) Use return instead of exit() in main()
8) argc-argv-correctness.
2015-03-16 12:37:46 +01:00
Hiltjo Posthuma ad6776e9a1 grep, kill, renice, sort: style: put main at bottom 2015-03-08 12:51:33 +01:00
sin 71de7813c0 Include strings.h for strcasecmp()
Fixes another build error on NetBSD.
2015-02-20 16:00:58 +00:00
sin 3e1e54051e Add some missing includes 2015-02-14 20:15:01 +00:00
FRIGN 31572c8b0e Clean up #includes 2015-02-14 21:12:23 +01:00
FRIGN ec8246bbc6 Un-boolify sbase
It actually makes the binaries smaller, the code easier to read
(gems like "val == true", "val == false" are gone) and actually
predictable in the sense of that we actually know what we're
working with (one bitwise operator was quite adventurous and
should now be fixed).

This is also more consistent with the other suckless projects
around which don't use boolean types.
2014-11-14 10:54:20 +00:00
FRIGN 7d2683ddf2 Sort includes and more cleanup and fixes in util/ 2014-11-14 10:54:10 +00:00
FRIGN eee98ed3a4 Fix coding style
It was about damn time. Consistency is very important in such a
big codebase.
2014-11-13 18:08:43 +00:00
sin 63f9f1ac14 Add special signal to the sigs table instead 2014-11-11 17:43:10 +00:00
sin 3ffe690384 Handle the special-case signal 0 and "0" properly 2014-11-11 17:40:26 +00:00
sin f06ada4592 Simplify logic in kill(1) 2014-11-11 17:31:42 +00:00
sin e4e47a617e Handle "--" for -l and -s as well in kill(1) 2014-11-11 17:13:10 +00:00
sin c0f540162f Die early if signal is invalid in -signum 2014-11-11 16:34:33 +00:00
sin 0967d2e278 Factor out check for WTERMSIG 2014-11-11 16:34:28 +00:00
sin e0b0741ba1 Add name2sig() and simplify kill(1) 2014-11-11 16:29:01 +00:00
sin 88f26b222b Actually print usage if kill -l is invoked with more than 1 arg 2014-11-11 16:09:24 +00:00
sin a81544a810 kill -l accepts at most 1 arg 2014-11-11 16:08:30 +00:00
sin aee8535a71 Fix outdated comments 2014-11-11 15:55:31 +00:00
sin 23d1dc6a55 Update manpage and usage for kill(1) 2014-11-11 15:53:26 +00:00
sin 61046dd39b Remove redundant check in kill(1) 2014-11-11 15:40:58 +00:00
sin a0e9050925 Implement XSI extensions -signal_name and -signal_number for kill(1) 2014-11-11 15:37:26 +00:00
sin 237673302d Make kill(1) POSIX conformant
* XSI extensions support is missing, -signal_name and -signal_number.
2014-11-11 15:08:58 +00:00
sin 0444d16475 Fix kill -l 2014-11-10 23:56:10 +00:00
sin 0c5b7b9155 Stop using EXIT_{SUCCESS,FAILURE} 2014-10-02 23:46:59 +01:00
Hiltjo Posthuma 953ebf3573 code style
Signed-off-by: Hiltjo Posthuma <>
2014-06-01 18:02:30 +01:00
Hiltjo Posthuma f34e1ae1d0 kill: argc < 2 should be argc < 1
Signed-off-by: Hiltjo Posthuma <>
2014-03-07 18:56:32 +00:00
sin b5a511dacf Exit with EXIT_SUCCESS/EXIT_FAILURE instead of 0 and 1
Fixed for consistency purposes.
2013-10-07 16:44:22 +01:00
stateless 7216a53a7e Remove unnecessary exit(1) in usage()
Signed-off-by: Christoph Lohmann <>
2013-06-19 19:58:19 +02:00
Christoph Lohmann 4d38f60685 Eliminating the getopt disgrace. 2013-06-14 20:20:47 +02:00
Connor Lane Smith fcb8821246 revert to per-cmd usage() 2012-05-15 13:32:56 +01:00
Connor Lane Smith 146cca114e new ARGBEGIN & usage() function 2012-05-14 21:28:41 +01:00
Connor Lane Smith d7f9bda740 cc -Wextra 2011-06-21 05:05:37 +01:00
Connor Lane Smith 04162bd7b0 kill: accept $? values 2011-06-21 04:56:16 +01:00
Connor Lane Smith 954106050f rename estrtol 2011-06-10 14:55:01 +01:00
Connor Lane Smith 7c251bcd4f refactor strnum 2011-06-10 05:41:40 +01:00
Connor Lane Smith f2e86862be kill: allow signum 2011-06-10 03:12:45 +01:00
Connor Lane Smith 5156758e21 kill -l 2011-06-10 02:56:13 +01:00
Connor Lane Smith e180a91172 add kill, thanks rob 2011-06-10 02:29:10 +01:00