log username, log before kill, give init a sec to TSTP
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Sun, 25 May 1986 13:46:26 +0000 (05:46 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Sun, 25 May 1986 13:46:26 +0000 (05:46 -0800)
SCCS-vsn: sbin/reboot/halt.c 5.3
SCCS-vsn: sbin/reboot/reboot.c 5.3

usr/src/sbin/reboot/halt.c
usr/src/sbin/reboot/reboot.c

index 8b79f86..26b4eb5 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 1980 Regents of the University of California.
+ * Copyright (c) 1980,1986 Regents of the University of California.
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  */
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  */
@@ -11,7 +11,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)halt.c     5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)halt.c     5.3 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -21,9 +21,10 @@ static char sccsid[] = "@(#)halt.c   5.2 (Berkeley) %G%";
 #include <sys/reboot.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/reboot.h>
 #include <sys/types.h>
 #include <sys/time.h>
+#include <sys/syslog.h>
 #include <errno.h>
 #include <signal.h>
 #include <errno.h>
 #include <signal.h>
-#include <syslog.h>
+#include <pwd.h>
 
 main(argc, argv)
        int argc;
 
 main(argc, argv)
        int argc;
@@ -33,6 +34,8 @@ main(argc, argv)
        char *ttyn = (char *)ttyname(2);
        register i;
        register qflag = 0;
        char *ttyn = (char *)ttyname(2);
        register i;
        register qflag = 0;
+       char *user, *getlogin();
+       struct passwd *pw, *getpwuid();
 
        openlog("halt", 0, LOG_AUTH);
        howto = RB_HALT;
 
        openlog("halt", 0, LOG_AUTH);
        howto = RB_HALT;
@@ -55,11 +58,19 @@ main(argc, argv)
                exit(1);
        }
 
                exit(1);
        }
 
+       user = getlogin();
+       if (user == (char *)0 && (pw = getpwuid(getuid())))
+               user = pw->pw_name;
+       if (user == (char *)0)
+               user = "root";
+       syslog(LOG_CRIT, "halted by %s", user);
+
        signal(SIGHUP, SIG_IGN);                /* for network connections */
        if (kill(1, SIGTSTP) == -1) {
                fprintf(stderr, "reboot: can't idle init\n");
                exit(1);
        }
        signal(SIGHUP, SIG_IGN);                /* for network connections */
        if (kill(1, SIGTSTP) == -1) {
                fprintf(stderr, "reboot: can't idle init\n");
                exit(1);
        }
+       sleep(1);
 
        if (!qflag) for (i = 1; ; i++) {
                if (kill(-1, SIGKILL) == -1) {
 
        if (!qflag) for (i = 1; ; i++) {
                if (kill(-1, SIGKILL) == -1) {
@@ -73,21 +84,17 @@ main(argc, argv)
                        exit(1);
                }
                if (i > 5) {
                        exit(1);
                }
                if (i > 5) {
-       fprintf(stderr, "CAUTION: some process(es) wouldn't die\n");
+                       fprintf(stderr,
+                           "CAUTION: some process(es) wouldn't die\n");
                        break;
                }
                setalarm(2 * i);
                pause();
        }
 
                        break;
                }
                setalarm(2 * i);
                pause();
        }
 
-       if ((howto & RB_NOSYNC) == 0)
-               syslog(LOG_CRIT, "halted");
-       if (!qflag) {
-               if ((howto & RB_NOSYNC)==0) {
-                       markdown();
-                       sync();
-                       sync();
-               }
+       if (!qflag && (howto & RB_NOSYNC) == 0) {
+               markdown();
+               sync();
                setalarm(5);
                pause();
        }
                setalarm(5);
                pause();
        }
index 2762b0e..a5b8465 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 1980 Regents of the University of California.
+ * Copyright (c) 1980,1986 Regents of the University of California.
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  */
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  */
@@ -11,7 +11,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)reboot.c   5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)reboot.c   5.3 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -21,9 +21,10 @@ static char sccsid[] = "@(#)reboot.c 5.2 (Berkeley) %G%";
 #include <sys/reboot.h>
 #include <errno.h>
 #include <signal.h>
 #include <sys/reboot.h>
 #include <errno.h>
 #include <signal.h>
+#include <pwd.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/time.h>
-#include <syslog.h>
+#include <sys/syslog.h>
 
 main(argc, argv)
        int argc;
 
 main(argc, argv)
        int argc;
@@ -34,6 +35,8 @@ main(argc, argv)
        register i;
        register ok = 0;
        register qflag = 0;
        register i;
        register ok = 0;
        register qflag = 0;
+       char *user, *getlogin();
+       struct passwd *pw, *getpwuid();
 
        openlog("reboot", 0, LOG_AUTH);
        argc--, argv++;
 
        openlog("reboot", 0, LOG_AUTH);
        argc--, argv++;
@@ -51,11 +54,19 @@ main(argc, argv)
                argc--, argv++;
        }
 
                argc--, argv++;
        }
 
+       user = getlogin();
+       if (user == (char *)0 && (pw = getpwuid(getuid())))
+               user = pw->pw_name;
+       if (user == (char *)0)
+               user = "root";
+       syslog(LOG_CRIT, "halted by %s", user);
+
        signal(SIGHUP, SIG_IGN);        /* for remote connections */
        if (kill(1, SIGTSTP) == -1) {
                fprintf(stderr, "reboot: can't idle init\n");
                exit(1);
        }
        signal(SIGHUP, SIG_IGN);        /* for remote connections */
        if (kill(1, SIGTSTP) == -1) {
                fprintf(stderr, "reboot: can't idle init\n");
                exit(1);
        }
+       sleep(1);
 
        if (!qflag) for (i = 1; ; i++) {
                if (kill(-1, SIGKILL) == -1) {
 
        if (!qflag) for (i = 1; ; i++) {
                if (kill(-1, SIGKILL) == -1) {
@@ -69,21 +80,17 @@ main(argc, argv)
                        exit(1);
                }
                if (i > 5) {
                        exit(1);
                }
                if (i > 5) {
-       fprintf(stderr, "CAUTION: some process(es) wouldn't die\n");
+                       fprintf(stderr,
+                           "CAUTION: some process(es) wouldn't die\n");
                        break;
                }
                setalarm(2 * i);
                pause();
        }
 
                        break;
                }
                setalarm(2 * i);
                pause();
        }
 
-       if ((howto & RB_NOSYNC) == 0)
-               syslog(LOG_CRIT, "halted for reboot");
-       if (!qflag) {
-               if (!(howto & RB_NOSYNC)) {
-                       markdown();
-                       sync();
-                       sync();
-               }
+       if (!qflag && (howto & RB_NOSYNC) == 0) {
+               markdown();
+               sync();
                setalarm(5);
                pause();
        }
                setalarm(5);
                pause();
        }