Deleted Added
full compact
reboot.c (293232) reboot.c (293744)
1/*
2 * Copyright (c) 1980, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 25 unchanged lines hidden (view full) ---

34 The Regents of the University of California. All rights reserved.\n";
35#endif /* not lint */
36
37#ifndef lint
38static char sccsid[] = "@(#)reboot.c 8.1 (Berkeley) 6/5/93";
39#endif /* not lint */
40#endif
41#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1980, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 25 unchanged lines hidden (view full) ---

34 The Regents of the University of California. All rights reserved.\n";
35#endif /* not lint */
36
37#ifndef lint
38static char sccsid[] = "@(#)reboot.c 8.1 (Berkeley) 6/5/93";
39#endif /* not lint */
40#endif
41#include <sys/cdefs.h>
42__FBSDID("$FreeBSD: stable/10/sbin/reboot/reboot.c 293232 2016-01-06 09:56:06Z smh $");
42__FBSDID("$FreeBSD: stable/10/sbin/reboot/reboot.c 293744 2016-01-12 10:14:57Z trasz $");
43
44#include <sys/reboot.h>
45#include <sys/time.h>
46#include <sys/types.h>
47#include <sys/sysctl.h>
48#include <signal.h>
49#include <err.h>
50#include <errno.h>

--- 21 unchanged lines hidden (view full) ---

72 const char *user, *kernel = NULL;
73
74 if (strcmp(getprogname(), "halt") == 0) {
75 dohalt = 1;
76 howto = RB_HALT;
77 } else
78 howto = 0;
79 lflag = nflag = qflag = Nflag = 0;
43
44#include <sys/reboot.h>
45#include <sys/time.h>
46#include <sys/types.h>
47#include <sys/sysctl.h>
48#include <signal.h>
49#include <err.h>
50#include <errno.h>

--- 21 unchanged lines hidden (view full) ---

72 const char *user, *kernel = NULL;
73
74 if (strcmp(getprogname(), "halt") == 0) {
75 dohalt = 1;
76 howto = RB_HALT;
77 } else
78 howto = 0;
79 lflag = nflag = qflag = Nflag = 0;
80 while ((ch = getopt(argc, argv, "dk:lNnpq")) != -1)
80 while ((ch = getopt(argc, argv, "dk:lNnpqr")) != -1)
81 switch(ch) {
82 case 'd':
83 howto |= RB_DUMP;
84 break;
85 case 'k':
86 kernel = optarg;
87 break;
88 case 'l':

--- 8 unchanged lines hidden (view full) ---

97 Nflag = 1;
98 break;
99 case 'p':
100 howto |= RB_POWEROFF;
101 break;
102 case 'q':
103 qflag = 1;
104 break;
81 switch(ch) {
82 case 'd':
83 howto |= RB_DUMP;
84 break;
85 case 'k':
86 kernel = optarg;
87 break;
88 case 'l':

--- 8 unchanged lines hidden (view full) ---

97 Nflag = 1;
98 break;
99 case 'p':
100 howto |= RB_POWEROFF;
101 break;
102 case 'q':
103 qflag = 1;
104 break;
105 case 'r':
106 howto |= RB_REROOT;
107 break;
105 case '?':
106 default:
107 usage();
108 }
109 argc -= optind;
110 argv += optind;
111
112 if ((howto & (RB_DUMP | RB_HALT)) == (RB_DUMP | RB_HALT))
113 errx(1, "cannot dump (-d) when halting; must reboot instead");
114 if (Nflag && (howto & RB_NOSYNC) != 0)
115 errx(1, "-N cannot be used with -n");
108 case '?':
109 default:
110 usage();
111 }
112 argc -= optind;
113 argv += optind;
114
115 if ((howto & (RB_DUMP | RB_HALT)) == (RB_DUMP | RB_HALT))
116 errx(1, "cannot dump (-d) when halting; must reboot instead");
117 if (Nflag && (howto & RB_NOSYNC) != 0)
118 errx(1, "-N cannot be used with -n");
119 if ((howto & RB_REROOT) != 0 && howto != RB_REROOT)
120 errx(1, "-r cannot be used with -d, -n, or -p");
116 if (geteuid()) {
117 errno = EPERM;
118 err(1, NULL);
119 }
120
121 if (qflag) {
122 reboot(howto);
123 err(1, NULL);

--- 14 unchanged lines hidden (view full) ---

138 /* Log the reboot. */
139 if (!lflag) {
140 if ((user = getlogin()) == NULL)
141 user = (pw = getpwuid(getuid())) ?
142 pw->pw_name : "???";
143 if (dohalt) {
144 openlog("halt", 0, LOG_AUTH | LOG_CONS);
145 syslog(LOG_CRIT, "halted by %s", user);
121 if (geteuid()) {
122 errno = EPERM;
123 err(1, NULL);
124 }
125
126 if (qflag) {
127 reboot(howto);
128 err(1, NULL);

--- 14 unchanged lines hidden (view full) ---

143 /* Log the reboot. */
144 if (!lflag) {
145 if ((user = getlogin()) == NULL)
146 user = (pw = getpwuid(getuid())) ?
147 pw->pw_name : "???";
148 if (dohalt) {
149 openlog("halt", 0, LOG_AUTH | LOG_CONS);
150 syslog(LOG_CRIT, "halted by %s", user);
151 } else if (howto & RB_REROOT) {
152 openlog("reroot", 0, LOG_AUTH | LOG_CONS);
153 syslog(LOG_CRIT, "rerooted by %s", user);
146 } else {
147 openlog("reboot", 0, LOG_AUTH | LOG_CONS);
148 syslog(LOG_CRIT, "rebooted by %s", user);
149 }
150 }
151 utx.ut_type = SHUTDOWN_TIME;
152 gettimeofday(&utx.ut_tv, NULL);
153 pututxline(&utx);

--- 17 unchanged lines hidden (view full) ---

171 (void)signal(SIGTSTP, SIG_IGN);
172
173 /*
174 * If we're running in a pipeline, we don't want to die
175 * after killing whatever we're writing to.
176 */
177 (void)signal(SIGPIPE, SIG_IGN);
178
154 } else {
155 openlog("reboot", 0, LOG_AUTH | LOG_CONS);
156 syslog(LOG_CRIT, "rebooted by %s", user);
157 }
158 }
159 utx.ut_type = SHUTDOWN_TIME;
160 gettimeofday(&utx.ut_tv, NULL);
161 pututxline(&utx);

--- 17 unchanged lines hidden (view full) ---

179 (void)signal(SIGTSTP, SIG_IGN);
180
181 /*
182 * If we're running in a pipeline, we don't want to die
183 * after killing whatever we're writing to.
184 */
185 (void)signal(SIGPIPE, SIG_IGN);
186
187 /*
188 * Only init(8) can perform rerooting.
189 */
190 if (howto & RB_REROOT) {
191 if (kill(1, SIGEMT) == -1)
192 err(1, "SIGEMT init");
193
194 return (0);
195 }
196
179 /* Just stop init -- if we fail, we'll restart it. */
180 if (kill(1, SIGTSTP) == -1)
181 err(1, "SIGTSTP init");
182
183 /* Send a SIGTERM first, a chance to save the buffers. */
184 if (kill(-1, SIGTERM) == -1 && errno != ESRCH)
185 err(1, "SIGTERM processes");
186

--- 65 unchanged lines hidden ---
197 /* Just stop init -- if we fail, we'll restart it. */
198 if (kill(1, SIGTSTP) == -1)
199 err(1, "SIGTSTP init");
200
201 /* Send a SIGTERM first, a chance to save the buffers. */
202 if (kill(-1, SIGTERM) == -1 && errno != ESRCH)
203 err(1, "SIGTERM processes");
204

--- 65 unchanged lines hidden ---