really bad behavior with killall and find_pid_by_name()

Adam Slattery aslattery at sunriselinux.com
Sat Jun 30 01:17:39 UTC 2001


package: busybox
version: 0.52-pre

boot a busybox system (using busybox init).
do `killall -TERM asdf`.
The system reboots. This is bad.

The problem is that find_pid_by_name() will default to pid 1 if it can't
find a matching process, and thus killall will send SIGTERM to pid 1
(which happens to be the reboot signal).

Technically this is a problem in find_pid_by_name(), but halt, reboot, and
poweroff would need to be modified if this behavior was changed. So
instead I relied on the fact that halt, reboot, and poweroff ask for the
pid of "init" in order to correct the killall problem.

See the patch below.

This could also be fixed in kill.c by ignoring pid 1, but this might not
be a wonderful idea because if somebody called killall trying to get a
signal to init, it would fail.

The best thing that could be done would be to rewrite init to use
/dev/initctl instead of signals.. but I don't feel like doing this right
now :).



Adam Slattery
Sunrise Linux Development Team
aslattery at sunriselinux.com



--- find_pid_by_name.cedTue Jun 26 22:44:09 2001n
+++ find_pid_by_name.c.patched  Fri Jun 29 20:09:40 2001
@@ -165,8 +165,9 @@

        if (pidList)
                pidList[i]=0;
-       else {
-               /* If we found nothing, guess PID 1 and call it good */
+       if(!strcmp(pidName, "init") && !pidList) {
+               /* If we found nothing and the request is for
+                       "init" guess PID 1 and call it good */
                pidList=xrealloc( pidList, sizeof(pid_t));
                pidList[0]=1;
        }



---------------------------------------
Received: (at 1190-done) by bugs.lineo.com; 5 Jul 2001 16:28:34 +0000


More information about the busybox mailing list