1: /*
2: * Copyright (c) 1980,1986 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #ifndef lint
8: char copyright[] =
9: "@(#) Copyright (c) 1980,1986 Regents of the University of California.\n\
10: All rights reserved.\n";
11: #endif not lint
12:
13: #ifndef lint
14: static char sccsid[] = "@(#)reboot.c 5.4 (Berkeley) 5/26/86";
15: #endif not lint
16:
17: /*
18: * Reboot
19: */
20: #include <stdio.h>
21: #include <sys/reboot.h>
22: #include <errno.h>
23: #include <signal.h>
24: #include <pwd.h>
25: #include <sys/types.h>
26: #include <sys/time.h>
27: #include <sys/syslog.h>
28:
29: main(argc, argv)
30: int argc;
31: char **argv;
32: {
33: int howto;
34: register char *argp;
35: register i;
36: register ok = 0;
37: register qflag = 0;
38: int needlog = 1;
39: char *user, *getlogin();
40: struct passwd *pw, *getpwuid();
41:
42: openlog("reboot", 0, LOG_AUTH);
43: argc--, argv++;
44: howto = 0;
45: while (argc > 0) {
46: if (!strcmp(*argv, "-q"))
47: qflag++;
48: else if (!strcmp(*argv, "-n"))
49: howto |= RB_NOSYNC;
50: else if (!strcmp(*argv, "-l"))
51: needlog = 0;
52: else {
53: fprintf(stderr,
54: "usage: reboot [ -n ][ -q ]\n");
55: exit(1);
56: }
57: argc--, argv++;
58: }
59:
60: if (needlog) {
61: user = getlogin();
62: if (user == (char *)0 && (pw = getpwuid(getuid())))
63: user = pw->pw_name;
64: if (user == (char *)0)
65: user = "root";
66: syslog(LOG_CRIT, "rebooted by %s", user);
67: }
68:
69: signal(SIGHUP, SIG_IGN); /* for remote connections */
70: if (kill(1, SIGTSTP) == -1) {
71: fprintf(stderr, "reboot: can't idle init\n");
72: exit(1);
73: }
74: sleep(1);
75: (void) kill(-1, SIGTERM); /* one chance to catch it */
76: sleep(5);
77:
78: if (!qflag) for (i = 1; ; i++) {
79: if (kill(-1, SIGKILL) == -1) {
80: extern int errno;
81:
82: if (errno == ESRCH)
83: break;
84:
85: perror("reboot: kill");
86: kill(1, SIGHUP);
87: exit(1);
88: }
89: if (i > 5) {
90: fprintf(stderr,
91: "CAUTION: some process(es) wouldn't die\n");
92: break;
93: }
94: setalarm(2 * i);
95: pause();
96: }
97:
98: if (!qflag && (howto & RB_NOSYNC) == 0) {
99: markdown();
100: sync();
101: setalarm(5);
102: pause();
103: }
104: syscall(55, howto);
105: perror("reboot");
106: kill(1, SIGHUP);
107: exit(1);
108: }
109:
110: dingdong()
111: {
112: /* RRRIIINNNGGG RRRIIINNNGGG */
113: }
114:
115: setalarm(n)
116: {
117: signal(SIGALRM, dingdong);
118: alarm(n);
119: }
120:
121: #include <utmp.h>
122: #define SCPYN(a, b) strncpy(a, b, sizeof(a))
123: char wtmpf[] = "/usr/adm/wtmp";
124: struct utmp wtmp;
125:
126: markdown()
127: {
128: register f = open(wtmpf, 1);
129: if (f >= 0) {
130: lseek(f, 0L, 2);
131: SCPYN(wtmp.ut_line, "~");
132: SCPYN(wtmp.ut_name, "shutdown");
133: SCPYN(wtmp.ut_host, "");
134: time(&wtmp.ut_time);
135: write(f, (char *)&wtmp, sizeof(wtmp));
136: close(f);
137: }
138: }
Defined functions
main
defined in line
29;
never used
Defined variables
wtmp
defined in line
124; used 6 times
Defined macros