summaryrefslogtreecommitdiff
path: root/sbin/reboot/reboot.c
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/reboot.c
parent7ce6c6c15ad0a4ae329e52cd49c832804ac2bd6c (diff)
use err()/warn()/__progname
document -d
Diffstat (limited to 'sbin/reboot/reboot.c')
-rw-r--r--sbin/reboot/reboot.c70
1 files changed, 18 insertions, 52 deletions
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 */
}