From f0e93128bc52314f850ff80a75aee6e111bb2b8c Mon Sep 17 00:00:00 2001 From: Jesse Smith Date: Fri, 23 Nov 2018 22:11:42 -0400 Subject: [PATCH] When the halt command is called with the -p flag (or as poweroff) the command now passes the "-h -P" flags to shutdown. This in turn sets the INIT_HALT environment variable to POWEROFF. Assuming this value is checked by initscripts during the shutting down procedure, it should cause the system to be powered off. If halt is called without -p then the value of INIT_HALT is not set and the default action (often set in /etc/defaut/halt) is taken. --- doc/Changelog | 9 +++++++++ src/halt.c | 8 +++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index edf4c10..e4743d6 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -5,6 +5,15 @@ sysvinit (2.93) released; urgency=low * Fixed error where pidof would not omit checking PIDs passed to it when the -o flag was used. Fixes Debian bug #913394. + * When the halt command is called with the -p flag (or as poweroff) + the command now passes the "-h -P" flags to shutdown. This + in turn sets the INIT_HALT environment variable to POWEROFF. + Assuming this value is checked by initscripts during the + shutting down procedure, it should cause the system to + be powered off. + If halt is called without -p then the value of INIT_HALT + is not set and the default action (often set in /etc/defaut/halt) + is taken. sysvinit (2.92) released; urgency=low diff --git a/src/halt.c b/src/halt.c index 98bdadf..a469147 100644 --- a/src/halt.c +++ b/src/halt.c @@ -155,13 +155,15 @@ int get_runlevel(void) /* * Switch to another runlevel. */ -void do_shutdown(char *fl, char *tm) +void do_shutdown(char *fl, int should_poweroff, char *tm) { - char *args[8]; + char *args[9]; int i = 0; args[i++] = "shutdown"; args[i++] = fl; + if ( (! strcmp(fl, "-h") ) && (should_poweroff) ) + args[i++] = "-P"; if (tm) { args[i++] = "-t"; args[i++] = tm; @@ -259,7 +261,7 @@ int main(int argc, char **argv) */ c = get_runlevel(); if (c != '0' && c != '6') - do_shutdown(do_reboot ? "-r" : "-h", tm); + do_shutdown(do_reboot ? "-r" : "-h", do_poweroff, tm); } /*