initctl: Show error message when trying to signal PID 1 as non-root

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2016-08-10 21:39:09 +02:00
1 parent b01fae03ec
commit 0eafe8bcd9
1 file changed
+12 -3
+12 -3
View File
@@ -21,6 +21,7 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <err.h>
#include <ctype.h> #include <ctype.h>
#include <getopt.h> #include <getopt.h>
#include <glob.h> #include <glob.h>
@@ -278,9 +279,17 @@ static int do_cond(char *cmd)
return do_cond_show(NULL); return do_cond_show(NULL);
} }
static int do_halt (char *UNUSED(arg)) { return kill(1, SIGUSR1); } static int do_signal(int signo, const char *msg)
static int do_poweroff(char *UNUSED(arg)) { return kill(1, SIGUSR2); } {
static int do_reboot (char *UNUSED(arg)) { return kill(1, SIGTERM); } if (kill(1, signo))
err(1, "Failed signalling init to %s", msg);
return 0;
}
static int do_halt (char *UNUSED(arg)) { return do_signal(SIGUSR1, "halt"); }
static int do_poweroff(char *UNUSED(arg)) { return do_signal(SIGUSR2, "power off"); }
static int do_reboot (char *UNUSED(arg)) { return do_signal(SIGTERM, "reboot"); }
static int do_utmp(char *UNUSED(cmd)) static int do_utmp(char *UNUSED(cmd))
{ {