Fixes to option parsing in kill, skill, pkill.
Hi,
These are some fixes to how kill, skill and pkill handle parameters in the -SIGNUM form.
The handling was incorrect in kill/skill, it was actually not properly truncating argc/argv before removing the -SIGNUM argument. There were some hacks around the code to work around the bug, but using kill -1
on its own would end up working as if kill -1 -1
(which means kill -HUP <all processes>
) was executed. (Yes, it was painful when I accidentally typed it... more than once.)
I also made kill
print the usage if it only gets a signal number, but no pids (as in the kill -1
example.)
And pkill
had similar code but was using a buggy atoi() to try to parse the signal number, which meant that trailing garbage was accepted, so I corrected that by removing the buggy atoi() and letting the already existing code that already accepted numeric signals do its work as supposed to...
I also wanted to tackle the "pgrp" case where a negative number is passed to kill, causing it to kill a process group. The current code is buggy, for instance kill -TERM -2345
will kill process group 2 and not process group 2345 as supposed to. It should also be possible to pass it multiple pgrps or a mix of pgrps and pids. It's hard to fix that though, considering how getopt_long() works, so I'll defer that for a second pull request.
I tested this fairly well, both manually and made sure there were no regressions in the test suite, also didn't break make distcheck
.
Let me know if you have any questions or other remarks...
Cheers! Filipe