* Copyright (c) 1980, 1986 The Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1980, 1986 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)reboot.c 5.13 (Berkeley) %G%";
void err
__P((const char *fmt
, ...));
int ch
, howto
, lflag
, nflag
, qflag
, sverrno
;
if (!strcmp((p
= rindex(*argv
, '/')) ? p
+ 1 : *argv
, "halt")) {
lflag
= nflag
= qflag
= 0;
while ((ch
= getopt(argc
, argv
, "lnq")) != EOF
)
case 'l': /* Undocumented; used by shutdown. */
err("%s", strerror(EPERM
));
err("%s", strerror(errno
));
if ((user
= getlogin()) == NULL
)
user
= (pw
= getpwuid(getuid())) ?
openlog("halt", 0, LOG_AUTH
| LOG_CONS
);
syslog(LOG_CRIT
, "halted by %s", user
);
openlog("reboot", 0, LOG_AUTH
| LOG_CONS
);
syslog(LOG_CRIT
, "rebooted by %s", user
);
logwtmp("~", "shutdown", "");
* Do a sync early on, so disks start transfers while we're off
* killing processes. Don't worry about writes done before the
* processes die, the reboot system call syncs the disks.
/* Just stop init -- if we fail, we'll restart it. */
if (kill(1, SIGTSTP
) == -1)
err("SIGTSTP init: %s", strerror(errno
));
/* Ignore the SIGHUP we get when our parent shell dies. */
(void)signal(SIGHUP
, SIG_IGN
);
/* Send a SIGTERM first, a chance to save the buffers. */
if (kill(-1, SIGTERM
) == -1)
err("SIGTERM processes: %s", strerror(errno
));
* After the processes receive the signal, start the rest of the
* buffers on their way. Wait 5 seconds between the SIGTERM and
* the SIGKILL to give everybody a chance.
if (kill(-1, SIGKILL
) == -1) {
"WARNING: some process(es) wouldn't die\n");
err("%s%s", kill(1, SIGHUP
) == -1 ? "(can't restart init): " : "",
(void)fprintf(stderr
, "usage: %s [-nq]\n", dohalt
? "halt" : "reboot");
err(const char *fmt
, ...)
(void)fprintf(stderr
, "%s: ", dohalt
? "halt" : "reboot");
(void)vfprintf(stderr
, fmt
, ap
);
(void)fprintf(stderr
, "\n");