Signal init(8) instead of executing halt(8) or reboot(8)

when halting or rebooting the system.  It benefits from
running /etc/rc.shutdown by init(8).

``-o'' flag is provided for backward compatibility.

PR:		5451
Discussed with:	des
This commit is contained in:
ru 1999-06-21 16:06:21 +00:00
parent 9eba9bb8ab
commit 5f8c4db6e8
2 changed files with 100 additions and 70 deletions

View File

@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)shutdown.8 8.2 (Berkeley) 4/27/95
.\" $Id: shutdown.8,v 1.9 1999/01/11 09:07:42 asami Exp $
.\" $Id: shutdown.8,v 1.10 1999/06/21 06:21:04 jkoshy Exp $
.\"
.Dd Dec 11, 1998
.Dt SHUTDOWN 8
@ -40,8 +40,15 @@
.Nd "close down the system at a given time"
.Sh SYNOPSIS
.Nm shutdown
.Op Fl
.Op Fl hknpr
.Op Fl
.Oo
.Fl h | Fl p |
.Fl r | Fl k
.Oc
.Oo
.Fl o
.Op Fl n
.Oc
.Ar time
.Op Ar warning-message ...
.Sh DESCRIPTION
@ -55,11 +62,15 @@ The following options are available:
.Bl -tag -width indent
.It Fl h
The system is halted at the specified
.Ar time
when
.Nm
executes
.Xr halt 8 .
.Ar time .
.It Fl p
The system is halted and the power is turned off
.Pq hardware support required
at the specified
.Ar time .
.It Fl r
The system is rebooted at the specified
.Ar time .
.It Fl k
Kick everybody off.
The
@ -67,21 +78,30 @@ The
option
does not actually halt the system, but leaves the
system multi-user with logins disabled (for all but super-user).
.It Fl n
Prevent the normal
.Xr sync 2
before stopping.
This option is ignored if
.Fl k
is specified.
.It Fl p
The system will turn the power off after shutdown if it can.
.It Fl r
.Nm Shutdown
executes
.It Fl o
If one of the
.Fl h ,
.Fl p
or
.Fl r
is specified,
.Nm
will execute
.Xr halt 8
or
.Xr reboot 8
at the specified
.Ar time .
instead of sending signal to
.Xr init 8 .
.It Fl n
If the
.Fl o
is specified, prevent the file system cache from being flushed by passing
.Fl n
option to
.Xr halt 8
or
.Xr reboot 8 .
This option should probably not be used.
.It Ar time
.Ar Time
is the time at which
@ -108,14 +128,6 @@ is supplied as an option, the warning message is read from the standard
input.
.El
.Pp
Only one of
.Fl h ,
.Fl k ,
.Fl p ,
and
.Fl r
can be specified at a time.
.Pp
At intervals, becoming more frequent as apocalypse approaches
and starting at ten hours before shutdown, warning messages are displayed
on the terminals of all users logged in. Five minutes before
@ -131,13 +143,12 @@ removed just before
.Nm
exits.
.Pp
At shutdown time a message is written in the system log, containing the
time of shutdown, who initiated the shutdown and the reason.
A terminate
signal is then sent to
At shutdown time a message is written to the system log, containing the
time of shutdown, the person who initiated the shutdown and the reason.
Corresponding signal is then sent to
.Xr init 8
to bring the system down to single-user state (depending on above
options).
to respectively halt, reboot or bring the system down to single-user state
(depending on the above options).
The time of the shutdown and the warning message
are placed in
.Pa /var/run/nologin
@ -154,6 +165,7 @@ tells login not to let anyone log in
.Xr wall 1 ,
.Xr nologin 5 ,
.Xr halt 8 ,
.Xr init 8 ,
.Xr reboot 8
.Sh BACKWARD COMPATIBILITY
The hours and minutes in the second time format may be separated by

View File

@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)shutdown.c 8.4 (Berkeley) 4/28/95";
#endif
static const char rcsid[] =
"$Id: shutdown.c,v 1.17 1999/06/18 14:26:07 ru Exp $";
"$Id: shutdown.c,v 1.18 1999/06/21 06:21:05 jkoshy Exp $";
#endif /* not lint */
#include <sys/param.h>
@ -93,7 +93,7 @@ struct interval {
#undef S
static time_t offset, shuttime;
static int dohalt, dopower, doreboot, killflg, mbuflen;
static int dohalt, dopower, doreboot, killflg, mbuflen, oflag;
static char *nosync, *whom, mbuf[BUFSIZ];
void badtime __P((void));
@ -104,7 +104,7 @@ void loop __P((void));
void nolog __P((void));
void timeout __P((int));
void timewarn __P((int));
void usage __P((void));
void usage __P((const char *));
int
main(argc, argv)
@ -121,7 +121,7 @@ main(argc, argv)
#endif
nosync = NULL;
readstdin = 0;
while ((ch = getopt(argc, argv, "-hknpr")) != -1)
while ((ch = getopt(argc, argv, "-hknopr")) != -1)
switch (ch) {
case '-':
readstdin = 1;
@ -135,6 +135,9 @@ main(argc, argv)
case 'n':
nosync = "-n";
break;
case 'o':
oflag = 1;
break;
case 'p':
dopower = 1;
break;
@ -143,21 +146,22 @@ main(argc, argv)
break;
case '?':
default:
usage();
usage((char *)NULL);
}
argc -= optind;
argv += optind;
if (argc < 1)
usage();
usage((char *)NULL);
if (killflg + doreboot + dohalt + dopower > 1) {
warnx("incompatible switches -h, -k, -p and -r");
usage();
}
if (killflg + doreboot + dohalt + dopower > 1)
usage("incompatible switches -h, -k, -p and -r");
if (killflg && nosync)
warnx("option -n ignored with -k");
if (oflag && !(dohalt || dopower || doreboot))
usage("-o requires -h, -p or -r");
if (nosync != NULL && !oflag)
usage("-n requires -o");
getoffset(*argv++);
@ -349,29 +353,39 @@ die_you_gravy_sucking_pig_dog()
(void)printf("halt");
else if (dopower)
(void)printf("power-down");
if (nosync)
if (nosync != NULL)
(void)printf(" no sync");
(void)printf("\nkill -HUP 1\n");
#else
if (doreboot) {
execle(_PATH_REBOOT, "reboot", "-l", nosync,
(char *)NULL, empty_environ);
syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_REBOOT);
warn(_PATH_REBOOT);
if (!oflag) {
(void)kill(1, doreboot ? SIGINT : /* reboot */
dohalt ? SIGUSR1 : /* halt */
dopower ? SIGUSR2 : /* power-down */
SIGTERM); /* single-user */
} else {
if (doreboot) {
execle(_PATH_REBOOT, "reboot", "-l", nosync,
(char *)NULL, empty_environ);
syslog(LOG_ERR, "shutdown: can't exec %s: %m.",
_PATH_REBOOT);
warn(_PATH_REBOOT);
}
else if (dohalt) {
execle(_PATH_HALT, "halt", "-l", nosync,
(char *)NULL, empty_environ);
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 */
}
else if (dohalt) {
execle(_PATH_HALT, "halt", "-l", nosync,
(char *)NULL, empty_environ);
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);
}
@ -499,9 +513,13 @@ badtime()
}
void
usage()
usage(cp)
const char *cp;
{
fprintf(stderr,
"usage: shutdown [-] [-hknpr] time [warning-message ...]\n");
if (cp != NULL)
warnx("%s", cp);
(void)fprintf(stderr,
"usage: shutdown [-] [-h | -p | -r | -k] [-o [-n]]"
" time [warning-message ...]\n");
exit(1);
}