aboutsummaryrefslogtreecommitdiff
path: root/sbin/shutdown
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@FreeBSD.org>1999-06-21 16:06:21 +0000
committerRuslan Ermilov <ru@FreeBSD.org>1999-06-21 16:06:21 +0000
commit35cd460f8abe28608b9fb5fca6f0a1a9e3e136f2 (patch)
tree9e08c544ca304cb12948284e3dca0096edd15c6b /sbin/shutdown
parentc99115f476d8137bf493146777157e00ce91486b (diff)
downloadsrc-35cd460f8abe28608b9fb5fca6f0a1a9e3e136f2.tar.gz
src-35cd460f8abe28608b9fb5fca6f0a1a9e3e136f2.zip
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
Notes
Notes: svn path=/head/; revision=48078
Diffstat (limited to 'sbin/shutdown')
-rw-r--r--sbin/shutdown/shutdown.884
-rw-r--r--sbin/shutdown/shutdown.c86
2 files changed, 100 insertions, 70 deletions
diff --git a/sbin/shutdown/shutdown.8 b/sbin/shutdown/shutdown.8
index 90041f52e174..876c2874cc09 100644
--- a/sbin/shutdown/shutdown.8
+++ b/sbin/shutdown/shutdown.8
@@ -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
diff --git a/sbin/shutdown/shutdown.c b/sbin/shutdown/shutdown.c
index 8f9e7c851709..e81711aa37bf 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.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);
- }
- 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);
+ 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 */
}
- (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);
}