Changeset View
Changeset View
Standalone View
Standalone View
sbin/shutdown/shutdown.c
Show All 38 Lines | |||||
#ifndef lint | #ifndef lint | ||||
static char sccsid[] = "@(#)shutdown.c 8.4 (Berkeley) 4/28/95"; | static char sccsid[] = "@(#)shutdown.c 8.4 (Berkeley) 4/28/95"; | ||||
#endif /* not lint */ | #endif /* not lint */ | ||||
#endif | #endif | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/time.h> | #include <sys/boottrace.h> | ||||
#include <sys/resource.h> | #include <sys/resource.h> | ||||
#include <sys/sysctl.h> | |||||
#include <sys/syslog.h> | #include <sys/syslog.h> | ||||
#include <sys/time.h> | |||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <paths.h> | #include <paths.h> | ||||
#include <pwd.h> | #include <pwd.h> | ||||
#include <setjmp.h> | #include <setjmp.h> | ||||
▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | for (;;) { | ||||
*p = '\n'; | *p = '\n'; | ||||
*++p = '\0'; | *++p = '\0'; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
mbuflen = strlen(mbuf); | mbuflen = strlen(mbuf); | ||||
if (offset) | if (offset) { | ||||
BOOTTRACE("Shutdown at %s", ctime(&shuttime)); | |||||
(void)printf("Shutdown at %.24s.\n", ctime(&shuttime)); | (void)printf("Shutdown at %.24s.\n", ctime(&shuttime)); | ||||
else | } else { | ||||
BOOTTRACE("Shutdown NOW!"); | |||||
(void)printf("Shutdown NOW!\n"); | (void)printf("Shutdown NOW!\n"); | ||||
} | |||||
if (!(whom = getlogin())) | if (!(whom = getlogin())) | ||||
whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???"; | whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???"; | ||||
#ifdef DEBUG | #ifdef DEBUG | ||||
(void)putc('\n', stdout); | (void)putc('\n', stdout); | ||||
#else | #else | ||||
(void)setpriority(PRIO_PROCESS, 0, PRIO_MIN); | (void)setpriority(PRIO_PROCESS, 0, PRIO_MIN); | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | timeout(int signo __unused) | ||||
longjmp(alarmbuf, 1); | longjmp(alarmbuf, 1); | ||||
} | } | ||||
static void | static void | ||||
die_you_gravy_sucking_pig_dog(void) | die_you_gravy_sucking_pig_dog(void) | ||||
{ | { | ||||
char *empty_environ[] = { NULL }; | char *empty_environ[] = { NULL }; | ||||
BOOTTRACE("%s by %s", | |||||
doreboot ? "reboot" : dohalt ? "halt" : dopower ? "power-down" : | |||||
docycle ? "power-cycle" : "shutdown", whom); | |||||
syslog(LOG_NOTICE, "%s by %s: %s", | syslog(LOG_NOTICE, "%s by %s: %s", | ||||
doreboot ? "reboot" : dohalt ? "halt" : dopower ? "power-down" : | doreboot ? "reboot" : dohalt ? "halt" : dopower ? "power-down" : | ||||
docycle ? "power-cycle" : "shutdown", whom, mbuf); | docycle ? "power-cycle" : "shutdown", whom, mbuf); | ||||
(void)printf("\r\nSystem shutdown time has arrived\007\007\r\n"); | (void)printf("\r\nSystem shutdown time has arrived\007\007\r\n"); | ||||
if (killflg) { | if (killflg) { | ||||
BOOTTRACE("fake shutdown..."); | |||||
(void)printf("\rbut you'll have to do it yourself\r\n"); | (void)printf("\rbut you'll have to do it yourself\r\n"); | ||||
exit(0); | exit(0); | ||||
} | } | ||||
#ifdef DEBUG | #ifdef DEBUG | ||||
if (doreboot) | if (doreboot) | ||||
(void)printf("reboot"); | (void)printf("reboot"); | ||||
else if (docycle) | else if (docycle) | ||||
(void)printf("power-cycle"); | (void)printf("power-cycle"); | ||||
else if (dohalt) | else if (dohalt) | ||||
(void)printf("halt"); | (void)printf("halt"); | ||||
else if (dopower) | else if (dopower) | ||||
(void)printf("power-down"); | (void)printf("power-down"); | ||||
if (nosync != NULL) | if (nosync != NULL) | ||||
(void)printf(" no sync"); | (void)printf(" no sync"); | ||||
(void)printf("\nkill -HUP 1\n"); | (void)printf("\nkill -HUP 1\n"); | ||||
#else | #else | ||||
if (!oflag) { | if (!oflag) { | ||||
BOOTTRACE("signal to init(8)..."); | |||||
(void)kill(1, doreboot ? SIGINT : /* reboot */ | (void)kill(1, doreboot ? SIGINT : /* reboot */ | ||||
dohalt ? SIGUSR1 : /* halt */ | dohalt ? SIGUSR1 : /* halt */ | ||||
dopower ? SIGUSR2 : /* power-down */ | dopower ? SIGUSR2 : /* power-down */ | ||||
docycle ? SIGWINCH : /* power-cycle */ | docycle ? SIGWINCH : /* power-cycle */ | ||||
SIGTERM); /* single-user */ | SIGTERM); /* single-user */ | ||||
} else { | } else { | ||||
if (doreboot) { | if (doreboot) { | ||||
BOOTTRACE("exec reboot(8) -l..."); | |||||
execle(_PATH_REBOOT, "reboot", "-l", nosync, | execle(_PATH_REBOOT, "reboot", "-l", nosync, | ||||
(char *)NULL, empty_environ); | (char *)NULL, empty_environ); | ||||
syslog(LOG_ERR, "shutdown: can't exec %s: %m.", | syslog(LOG_ERR, "shutdown: can't exec %s: %m.", | ||||
_PATH_REBOOT); | _PATH_REBOOT); | ||||
warn(_PATH_REBOOT); | warn(_PATH_REBOOT); | ||||
} | } | ||||
else if (dohalt) { | else if (dohalt) { | ||||
BOOTTRACE("exec halt(8) -l..."); | |||||
execle(_PATH_HALT, "halt", "-l", nosync, | execle(_PATH_HALT, "halt", "-l", nosync, | ||||
(char *)NULL, empty_environ); | (char *)NULL, empty_environ); | ||||
syslog(LOG_ERR, "shutdown: can't exec %s: %m.", | syslog(LOG_ERR, "shutdown: can't exec %s: %m.", | ||||
_PATH_HALT); | _PATH_HALT); | ||||
warn(_PATH_HALT); | warn(_PATH_HALT); | ||||
} | } | ||||
else if (dopower) { | else if (dopower) { | ||||
BOOTTRACE("exec halt(8) -l -p..."); | |||||
execle(_PATH_HALT, "halt", "-l", "-p", nosync, | execle(_PATH_HALT, "halt", "-l", "-p", nosync, | ||||
(char *)NULL, empty_environ); | (char *)NULL, empty_environ); | ||||
syslog(LOG_ERR, "shutdown: can't exec %s: %m.", | syslog(LOG_ERR, "shutdown: can't exec %s: %m.", | ||||
_PATH_HALT); | _PATH_HALT); | ||||
warn(_PATH_HALT); | warn(_PATH_HALT); | ||||
} | } | ||||
else if (docycle) { | else if (docycle) { | ||||
execle(_PATH_HALT, "halt", "-l", "-c", nosync, | execle(_PATH_HALT, "halt", "-l", "-c", nosync, | ||||
(char *)NULL, empty_environ); | (char *)NULL, empty_environ); | ||||
syslog(LOG_ERR, "shutdown: can't exec %s: %m.", | syslog(LOG_ERR, "shutdown: can't exec %s: %m.", | ||||
_PATH_HALT); | _PATH_HALT); | ||||
warn(_PATH_HALT); | warn(_PATH_HALT); | ||||
} | } | ||||
BOOTTRACE("SIGTERM to init(8)..."); | |||||
(void)kill(1, SIGTERM); /* to single-user */ | (void)kill(1, SIGTERM); /* to single-user */ | ||||
} | } | ||||
#endif | #endif | ||||
finish(0); | finish(0); | ||||
} | } | ||||
#define ATOI2(p) (p[0] - '0') * 10 + (p[1] - '0'); p += 2; | #define ATOI2(p) (p[0] - '0') * 10 + (p[1] - '0'); p += 2; | ||||
▲ Show 20 Lines • Show All 164 Lines • Show Last 20 Lines |