Lines Matching +full:reboot +full:- +full:offset
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
81 static time_t offset, shuttime;
108 errx(1, "NOT super-user");
117 * "poweroff", for which it runs 'shutdown -p now'.
124 if (getopt(argc, argv, "") != -1)
126 argc -= optind;
131 offset = 0;
136 while ((ch = getopt(argc, argv, "-chknopqr")) != -1)
138 case '-':
151 nosync = "-n";
169 argc -= optind;
176 usage("incompatible switches -c, -h, -k, -p and -r");
179 usage("-o requires -c, -h, -p or -r");
182 usage("-n requires -o");
188 usage("warning-message supplied but suppressed with -q");
192 if ((len -= arglen) <= 2)
205 endp = mbuf + sizeof(mbuf) - 2;
207 if (!fgets(p, endp - p + 1, stdin))
219 if (offset) {
228 whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???";
238 if (forkpid == -1)
257 if (offset <= NOLOG_TIME) {
264 if (tp->timeleft < offset)
265 (void)sleep((u_int)(offset - tp->timeleft));
267 while (tp->timeleft && offset < tp->timeleft)
273 if ((sltime = offset - tp->timeleft)) {
274 if (dowarn && sltime > (u_int)(tp->timetowait / 5))
275 timewarn(offset);
281 timewarn(tp->timeleft);
282 if (!logged && tp->timeleft <= NOLOG_TIME) {
286 (void)sleep((u_int)tp->timetowait);
287 if (!tp->timeleft)
311 /* undoc -n option to wall suppresses normal wall banner */
312 (void)snprintf(wcmd, sizeof(wcmd), "%s -n", _PATH_WALL);
331 (offset > 0 && offset < 30 ? "less than " : ""));
363 doreboot ? "reboot" : dohalt ? "halt" : dopower ? "power-down" :
364 docycle ? "power-cycle" : "shutdown", whom);
366 doreboot ? "reboot" : dohalt ? "halt" : dopower ? "power-down" :
367 docycle ? "power-cycle" : "shutdown", whom, mbuf);
377 (void)printf("reboot");
379 (void)printf("power-cycle");
383 (void)printf("power-down");
386 (void)printf("\nkill -HUP 1\n");
390 (void)kill(1, doreboot ? SIGINT : /* reboot */
392 dopower ? SIGUSR2 : /* power-down */
393 docycle ? SIGWINCH : /* power-cycle */
394 SIGTERM); /* single-user */
397 BOOTTRACE("exec reboot(8) -l...");
398 execle(_PATH_REBOOT, "reboot", "-l", nosync,
405 BOOTTRACE("exec halt(8) -l...");
406 execle(_PATH_HALT, "halt", "-l", nosync,
413 BOOTTRACE("exec halt(8) -l -p...");
414 execle(_PATH_HALT, "halt", "-l", "-p", nosync,
421 execle(_PATH_HALT, "halt", "-l", "-c", nosync,
428 (void)kill(1, SIGTERM); /* to single-user */
434 #define ATOI2(p) (p[0] - '0') * 10 + (p[1] - '0'); p += 2;
448 offset = 0;
457 offset = strtol(timearg, &timeunit, 10);
458 if (offset < 0 || offset == LONG_MAX || errno != 0)
463 offset *= 60;
467 offset *= 60 * 60;
471 offset *= 1;
475 shuttime = now + offset;
497 this_year = lt->tm_year;
498 lt->tm_year = ATOI2(timearg);
502 * enter n - 1 at the start of year n.
504 if (lt->tm_year < (this_year % 100) - 1)
505 lt->tm_year += 100;
507 lt->tm_year += (this_year - (this_year % 100));
510 lt->tm_mon = ATOI2(timearg);
511 if (--lt->tm_mon < 0 || lt->tm_mon > 11)
516 lt->tm_mday = ATOI2(timearg);
517 if (lt->tm_mday < 1 || lt->tm_mday > 31)
521 lt->tm_hour = ATOI2(timearg);
522 if (lt->tm_hour < 0 || lt->tm_hour > 23)
524 lt->tm_min = ATOI2(timearg);
525 if (lt->tm_min < 0 || lt->tm_min > 59)
527 lt->tm_sec = 0;
528 if ((shuttime = mktime(lt)) == -1)
531 if ((offset = shuttime - now) < 0) {
540 lt->tm_mday++;
541 if ((shuttime = mktime(lt)) == -1)
543 if ((offset = shuttime - now) < 0) {
567 (void)write(logfd, NOMSG, sizeof(NOMSG) - 1);
596 "usage: shutdown [-] [-c | -h | -p | -r | -k] [-o [-n]] [-q] time [warning-message ...]\n"