Be extra extra careful about what we dereference.
[oweals/busybox.git] / poweroff.c
index 7f9abf14a34daf566ce9dd93fd0eed9e1ebfb5cb..8bb20e9bbb949ef5a1159896c9de61ffa777fc0d 100644 (file)
  *
  */
 
-#include "internal.h"
+#include "busybox.h"
 #include <signal.h>
 
 extern int poweroff_main(int argc, char **argv)
 {
+#ifdef BB_FEATURE_LINUXRC
        /* don't assume init's pid == 1 */
-       exit(kill(findInitPid(), SIGUSR2));
+       pid_t *pid = find_pid_by_name("init");
+       if (!pid || *pid<=0)
+               error_msg_and_die("no process killed");
+       return(kill(*pid, SIGUSR2));
+#else
+       return(kill(1, SIGUSR2));
+#endif
 }