Add a '-p' flag to shutdown which corresponds to the '-p' flag to halt,

requesting a system power-off after shutdown.
This commit is contained in:
Mike Smith 1998-12-10 23:54:02 +00:00
parent 7ee72fdb25
commit 7e2d04d7c3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=41666
2 changed files with 21 additions and 7 deletions

View File

@ -30,7 +30,7 @@
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" @(#)shutdown.8 8.1 (Berkeley) 6/5/93 .\" @(#)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 .Dd June 5, 1993
.Dt SHUTDOWN 8 .Dt SHUTDOWN 8
@ -71,6 +71,8 @@ system multi-user with logins disabled (for all but super-user).
Prevent the normal Prevent the normal
.Xr sync 2 .Xr sync 2
before stopping. before stopping.
.It Fl p
The system will turn the power off after shutdown if it can.
.It Fl r .It Fl r
.Nm Shutdown .Nm Shutdown
executes executes

View File

@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)shutdown.c 8.2 (Berkeley) 2/16/94"; static char sccsid[] = "@(#)shutdown.c 8.2 (Berkeley) 2/16/94";
#endif #endif
static const char rcsid[] = static const char rcsid[] =
"$Id$"; "$Id: shutdown.c,v 1.13 1998/08/03 06:22:43 charnier Exp $";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -93,7 +93,7 @@ struct interval {
#undef S #undef S
static time_t offset, shuttime; static time_t offset, shuttime;
static int dohalt, doreboot, killflg, mbuflen; static int dohalt, dopower, doreboot, killflg, mbuflen;
static char *nosync, *whom, mbuf[BUFSIZ]; static char *nosync, *whom, mbuf[BUFSIZ];
void badtime __P((void)); void badtime __P((void));
@ -121,7 +121,7 @@ main(argc, argv)
#endif #endif
nosync = NULL; nosync = NULL;
readstdin = 0; readstdin = 0;
while ((ch = getopt(argc, argv, "-hknr")) != -1) while ((ch = getopt(argc, argv, "-hknpr")) != -1)
switch (ch) { switch (ch) {
case '-': case '-':
readstdin = 1; readstdin = 1;
@ -135,6 +135,9 @@ main(argc, argv)
case 'n': case 'n':
nosync = "-n"; nosync = "-n";
break; break;
case 'p':
dopower = 1;
break;
case 'r': case 'r':
doreboot = 1; doreboot = 1;
break; break;
@ -148,8 +151,8 @@ main(argc, argv)
if (argc < 1) if (argc < 1)
usage(); usage();
if (doreboot && dohalt) { if ((doreboot + dohalt + dopower) > 1) {
warnx("incompatible switches -h and -r"); warnx("incompatible switches -h, -p and -r");
usage(); usage();
} }
getoffset(*argv++); getoffset(*argv++);
@ -326,7 +329,8 @@ die_you_gravy_sucking_pig_dog()
char *empty_environ[] = { NULL }; char *empty_environ[] = { NULL };
syslog(LOG_NOTICE, "%s by %s: %s", 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)sleep(2);
(void)printf("\r\nSystem shutdown time has arrived\007\007\r\n"); (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"); (void)printf("reboot");
else if (dohalt) else if (dohalt)
(void)printf("halt"); (void)printf("halt");
else if (dopower)
(void)printf("power-down");
if (nosync) if (nosync)
(void)printf(" no sync"); (void)printf(" no sync");
(void)printf("\nkill -HUP 1\n"); (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); syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_HALT);
warn(_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 */ (void)kill(1, SIGTERM); /* to single user */
#endif #endif
finish(0); finish(0);