summaryrefslogtreecommitdiff
path: root/sbin/reboot
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>1997-09-03 21:18:39 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>1997-09-03 21:18:39 +0000
commitd81445307c66751a203740a9677d5e20ec62cbef (patch)
tree2d28cb9ff85dfe0e01d765c1c2547a8c1bdf4520 /sbin/reboot
parent7ce6c6c15ad0a4ae329e52cd49c832804ac2bd6c (diff)
use err()/warn()/__progname
document -d
Diffstat (limited to 'sbin/reboot')
-rw-r--r--sbin/reboot/reboot.812
-rw-r--r--sbin/reboot/reboot.c70
2 files changed, 27 insertions, 55 deletions
diff --git a/sbin/reboot/reboot.8 b/sbin/reboot/reboot.8
index ecf8b9b3fd8..1b5aa777728 100644
--- a/sbin/reboot/reboot.8
+++ b/sbin/reboot/reboot.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: reboot.8,v 1.4 1997/06/22 22:19:10 downsj Exp $
+.\" $OpenBSD: reboot.8,v 1.5 1997/09/03 21:18:38 mickey Exp $
.\" $NetBSD: reboot.8,v 1.3 1995/10/05 05:36:21 mycroft Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
@@ -44,9 +44,9 @@
stopping and restarting the system
.Sh SYNOPSIS
.Nm halt
-.Op Fl npqd
+.Op Fl dnpq
.Nm reboot
-.Op Fl nqd
+.Op Fl dnq
.Sh DESCRIPTION
The
.Nm halt
@@ -60,6 +60,11 @@ accounting file.
.Pp
The options are as follows:
.Bl -tag -width Ds
+.It Fl d
+If the
+.Fl d
+option is specified,
+system will dump crash into swap partition.
.It Fl n
If the
.Fl n
@@ -98,6 +103,7 @@ users advance warning of their impending doom.
.Xr sync 1 ,
.Xr utmp 5 ,
.Xr boot 8 ,
+.Xr savecore 8,
.Xr shutdown 8
.Sh HISTORY
A
diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c
index bde7fe57bfc..c3e22628639 100644
--- a/sbin/reboot/reboot.c
+++ b/sbin/reboot/reboot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: reboot.c,v 1.9 1997/07/25 19:13:10 mickey Exp $ */
+/* $OpenBSD: reboot.c,v 1.10 1997/09/03 21:18:38 mickey Exp $ */
/* $NetBSD: reboot.c,v 1.8 1995/10/05 05:36:22 mycroft Exp $ */
/*
@@ -44,28 +44,29 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)reboot.c 8.1 (Berkeley) 6/5/93";
#else
-static char rcsid[] = "$OpenBSD: reboot.c,v 1.9 1997/07/25 19:13:10 mickey Exp $";
+static char rcsid[] = "$OpenBSD: reboot.c,v 1.10 1997/09/03 21:18:38 mickey Exp $";
#endif
#endif /* not lint */
+#include <sys/types.h>
#include <sys/reboot.h>
#include <signal.h>
#include <pwd.h>
#include <errno.h>
+#include <err.h>
#include <syslog.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <paths.h>
+#include <util.h>
-void err __P((const char *fmt, ...));
void usage __P((void));
+extern char *__progname;
#define _PATH_RCSHUTDOWN "/etc/rc.shutdown"
-int dohalt;
-
int
main(argc, argv)
int argc;
@@ -73,23 +74,20 @@ main(argc, argv)
{
register int i;
struct passwd *pw;
- int ch, howto, lflag, nflag, pflag, qflag, sverrno;
+ int ch, howto, dohalt, lflag, nflag, pflag, qflag, sverrno;
char *p, *user;
- /* Get our name */
- p = strrchr(*argv, '/');
- if(p == NULL) p = *argv;
- else p++;
+ p = __progname;
/* Nuke login shell */
if(*p == '-') p++;
+ howto = dohalt = lflag = nflag = pflag = qflag = 0;
if (!strcmp(p, "halt")) {
dohalt = 1;
howto = RB_HALT;
- } else
- howto = 0;
- lflag = nflag = pflag = qflag = 0;
+ }
+
while ((ch = getopt(argc, argv, "dlnpq")) != -1)
switch(ch) {
case 'd':
@@ -120,11 +118,11 @@ main(argc, argv)
argv += optind;
if (geteuid())
- err("%s", strerror(EPERM));
+ errx(1, "%s", strerror(EPERM));
if (qflag) {
reboot(howto);
- err("%s", strerror(errno));
+ err(1, "reboot");
}
/* Log the reboot. */
@@ -157,7 +155,7 @@ main(argc, argv)
/* Just stop init -- if we fail, we'll restart it. */
if (kill(1, SIGTSTP) == -1)
- err("SIGTSTP init: %s", strerror(errno));
+ err(1, "SIGTSTP init");
/* Ignore the SIGHUP we get when our parent shell dies. */
(void)signal(SIGHUP, SIG_IGN);
@@ -184,8 +182,7 @@ main(argc, argv)
* single-user mode.
*/
if (errno != ESRCH) {
- (void)fprintf(stderr, "%s: SIGTERM processes: %s",
- dohalt ? "halt" : "reboot", strerror(errno));
+ warn("SIGTERM processes");
goto restart;
}
}
@@ -207,8 +204,7 @@ main(argc, argv)
goto restart;
}
if (i > 5) {
- (void)fprintf(stderr,
- "WARNING: some process(es) wouldn't die\n");
+ warnx("WARNING: some process(es) wouldn't die");
break;
}
(void)sleep(2 * i);
@@ -219,43 +215,13 @@ main(argc, argv)
restart:
sverrno = errno;
- err("%s%s", kill(1, SIGHUP) == -1 ? "(can't restart init): " : "",
- strerror(sverrno));
+ errx(1, kill(1, SIGHUP) == -1 ? "(can't restart init): " : "");
/* NOTREACHED */
}
void
usage()
{
- (void)fprintf(stderr, "usage: %s [-nqd]\n", dohalt ? "halt" : "reboot");
- exit(1);
-}
-
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#ifdef __STDC__
-err(const char *fmt, ...)
-#else
-err(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#ifdef __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- (void)fprintf(stderr, "%s: ", dohalt ? "halt" : "reboot");
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
- (void)fprintf(stderr, "\n");
+ (void)fprintf(stderr, "usage: %s [-dlnpq]\n", __progname);
exit(1);
- /* NOTREACHED */
}