Annotation of 43BSDReno/sbin/reboot/reboot.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1980, 1986 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: char copyright[] =
                     22: "@(#) Copyright (c) 1980, 1986 The Regents of the University of California.\n\
                     23:  All rights reserved.\n";
                     24: #endif /* not lint */
                     25: 
                     26: #ifndef lint
                     27: static char sccsid[] = "@(#)reboot.c   5.9 (Berkeley) 6/1/90";
                     28: #endif /* not lint */
                     29: 
                     30: /*
                     31:  * Reboot
                     32:  */
                     33: #include <sys/types.h>
                     34: #include <sys/time.h>
                     35: #include <sys/syslog.h>
                     36: #include <sys/syscall.h>
                     37: #include <sys/reboot.h>
                     38: #include <sys/signal.h>
                     39: #include <pwd.h>
                     40: #include <stdio.h>
                     41: #include <errno.h>
                     42: 
                     43: main(argc, argv)
                     44:        int argc;
                     45:        char **argv;
                     46: {
                     47:        int howto;
                     48:        register char *argp;
                     49:        register i;
                     50:        register ok = 0;
                     51:        register qflag = 0;
                     52:        int needlog = 1;
                     53:        char *user, *getlogin();
                     54:        struct passwd *pw, *getpwuid();
                     55: 
                     56:        openlog("reboot", 0, LOG_AUTH);
                     57:        argc--, argv++;
                     58:        howto = 0;
                     59:        while (argc > 0) {
                     60:                if (!strcmp(*argv, "-q"))
                     61:                        qflag++;
                     62:                else if (!strcmp(*argv, "-n"))
                     63:                        howto |= RB_NOSYNC;
                     64:                else if (!strcmp(*argv, "-l"))
                     65:                        needlog = 0;
                     66:                else {
                     67:                        fprintf(stderr,
                     68:                            "usage: reboot [ -n ][ -q ]\n");
                     69:                        exit(1);
                     70:                }
                     71:                argc--, argv++;
                     72:        }
                     73: 
                     74:        if (needlog) {
                     75:                user = getlogin();
                     76:                if (user == (char *)0 && (pw = getpwuid(getuid())))
                     77:                        user = pw->pw_name;
                     78:                if (user == (char *)0)
                     79:                        user = "root";
                     80:                syslog(LOG_CRIT, "rebooted by %s", user);
                     81:        }
                     82: 
                     83:        signal(SIGHUP, SIG_IGN);        /* for remote connections */
                     84:        if (kill(1, SIGTSTP) == -1) {
                     85:                fprintf(stderr, "reboot: can't idle init\n");
                     86:                exit(1);
                     87:        }
                     88:        sleep(1);
                     89:        (void) kill(-1, SIGTERM);       /* one chance to catch it */
                     90:        sleep(5);
                     91: 
                     92:        if (!qflag) for (i = 1; ; i++) {
                     93:                if (kill(-1, SIGKILL) == -1) {
                     94:                        extern int errno;
                     95: 
                     96:                        if (errno == ESRCH)
                     97:                                break;
                     98: 
                     99:                        perror("reboot: kill");
                    100:                        kill(1, SIGHUP);
                    101:                        exit(1);
                    102:                }
                    103:                if (i > 5) {
                    104:                        fprintf(stderr,
                    105:                            "CAUTION: some process(es) wouldn't die\n");
                    106:                        break;
                    107:                }
                    108:                setalarm(2 * i);
                    109:                pause();
                    110:        }
                    111: 
                    112:        if (!qflag && (howto & RB_NOSYNC) == 0) {
                    113:                logwtmp("~", "shutdown", "");
                    114:                sync();
                    115:                setalarm(5);
                    116:                pause();
                    117:        }
                    118:        syscall(SYS_reboot, howto);
                    119:        perror("reboot");
                    120:        kill(1, SIGHUP);
                    121:        exit(1);
                    122: }
                    123: 
                    124: dingdong()
                    125: {
                    126:        /* RRRIIINNNGGG RRRIIINNNGGG */
                    127: }
                    128: 
                    129: setalarm(n)
                    130: {
                    131:        signal(SIGALRM, dingdong);
                    132:        alarm(n);
                    133: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.