From 7e2d04d7c34bfea4ccdc97cd4daef42e1f846210 Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Thu, 10 Dec 1998 23:54:02 +0000 Subject: [PATCH] Add a '-p' flag to shutdown which corresponds to the '-p' flag to halt, requesting a system power-off after shutdown. --- sbin/shutdown/shutdown.8 | 4 +++- sbin/shutdown/shutdown.c | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/sbin/shutdown/shutdown.8 b/sbin/shutdown/shutdown.8 index 0d40c1cddbcc..5a070b0ea56b 100644 --- a/sbin/shutdown/shutdown.8 +++ b/sbin/shutdown/shutdown.8 @@ -30,7 +30,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)shutdown.8 8.1 (Berkeley) 6/5/93 -.\" $Id$ +.\" $Id: shutdown.8,v 1.4 1998/08/03 06:22:43 charnier Exp $ .\" .Dd June 5, 1993 .Dt SHUTDOWN 8 @@ -71,6 +71,8 @@ system multi-user with logins disabled (for all but super-user). Prevent the normal .Xr sync 2 before stopping. +.It Fl p +The system will turn the power off after shutdown if it can. .It Fl r .Nm Shutdown executes diff --git a/sbin/shutdown/shutdown.c b/sbin/shutdown/shutdown.c index 025a1c68b423..a2d487d874f4 100644 --- a/sbin/shutdown/shutdown.c +++ b/sbin/shutdown/shutdown.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)shutdown.c 8.2 (Berkeley) 2/16/94"; #endif static const char rcsid[] = - "$Id$"; + "$Id: shutdown.c,v 1.13 1998/08/03 06:22:43 charnier Exp $"; #endif /* not lint */ #include @@ -93,7 +93,7 @@ struct interval { #undef S static time_t offset, shuttime; -static int dohalt, doreboot, killflg, mbuflen; +static int dohalt, dopower, doreboot, killflg, mbuflen; static char *nosync, *whom, mbuf[BUFSIZ]; void badtime __P((void)); @@ -121,7 +121,7 @@ main(argc, argv) #endif nosync = NULL; readstdin = 0; - while ((ch = getopt(argc, argv, "-hknr")) != -1) + while ((ch = getopt(argc, argv, "-hknpr")) != -1) switch (ch) { case '-': readstdin = 1; @@ -135,6 +135,9 @@ main(argc, argv) case 'n': nosync = "-n"; break; + case 'p': + dopower = 1; + break; case 'r': doreboot = 1; break; @@ -148,8 +151,8 @@ main(argc, argv) if (argc < 1) usage(); - if (doreboot && dohalt) { - warnx("incompatible switches -h and -r"); + if ((doreboot + dohalt + dopower) > 1) { + warnx("incompatible switches -h, -p and -r"); usage(); } getoffset(*argv++); @@ -326,7 +329,8 @@ die_you_gravy_sucking_pig_dog() char *empty_environ[] = { NULL }; syslog(LOG_NOTICE, "%s by %s: %s", - doreboot ? "reboot" : dohalt ? "halt" : "shutdown", whom, mbuf); + doreboot ? "reboot" : dohalt ? "halt" : dopower ? "power-down" : + "shutdown", whom, mbuf); (void)sleep(2); (void)printf("\r\nSystem shutdown time has arrived\007\007\r\n"); @@ -339,6 +343,8 @@ die_you_gravy_sucking_pig_dog() (void)printf("reboot"); else if (dohalt) (void)printf("halt"); + else if (dopower) + (void)printf("power-down"); if (nosync) (void)printf(" no sync"); (void)printf("\nkill -HUP 1\n"); @@ -355,6 +361,12 @@ die_you_gravy_sucking_pig_dog() syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_HALT); warn(_PATH_HALT); } + else if (dopower) { + execle(_PATH_HALT, "halt", "-l", "-p", nosync, + (char *)NULL, empty_environ); + syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_HALT); + warn(_PATH_HALT); + } (void)kill(1, SIGTERM); /* to single user */ #endif finish(0);