shutdown.c revision 48956
11558Srgrimes/* 21558Srgrimes * Copyright (c) 1988, 1990, 1993 31558Srgrimes * The Regents of the University of California. All rights reserved. 41558Srgrimes * 51558Srgrimes * Redistribution and use in source and binary forms, with or without 61558Srgrimes * modification, are permitted provided that the following conditions 71558Srgrimes * are met: 81558Srgrimes * 1. Redistributions of source code must retain the above copyright 91558Srgrimes * notice, this list of conditions and the following disclaimer. 101558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111558Srgrimes * notice, this list of conditions and the following disclaimer in the 121558Srgrimes * documentation and/or other materials provided with the distribution. 131558Srgrimes * 3. All advertising materials mentioning features or use of this software 141558Srgrimes * must display the following acknowledgement: 151558Srgrimes * This product includes software developed by the University of 161558Srgrimes * California, Berkeley and its contributors. 171558Srgrimes * 4. Neither the name of the University nor the names of its contributors 181558Srgrimes * may be used to endorse or promote products derived from this software 191558Srgrimes * without specific prior written permission. 201558Srgrimes * 211558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311558Srgrimes * SUCH DAMAGE. 321558Srgrimes */ 331558Srgrimes 341558Srgrimes#ifndef lint 3538036Scharnierstatic const char copyright[] = 361558Srgrimes"@(#) Copyright (c) 1988, 1990, 1993\n\ 371558Srgrimes The Regents of the University of California. All rights reserved.\n"; 381558Srgrimes#endif /* not lint */ 391558Srgrimes 401558Srgrimes#ifndef lint 4138036Scharnier#if 0 4241684Sbdestatic char sccsid[] = "@(#)shutdown.c 8.4 (Berkeley) 4/28/95"; 4338036Scharnier#endif 4438036Scharnierstatic const char rcsid[] = 4548956Sbillf "$Id: shutdown.c,v 1.19 1999/06/21 16:06:21 ru Exp $"; 461558Srgrimes#endif /* not lint */ 471558Srgrimes 481558Srgrimes#include <sys/param.h> 491558Srgrimes#include <sys/time.h> 501558Srgrimes#include <sys/resource.h> 511558Srgrimes#include <sys/syslog.h> 521558Srgrimes 531558Srgrimes#include <ctype.h> 5438036Scharnier#include <err.h> 551558Srgrimes#include <fcntl.h> 561558Srgrimes#include <pwd.h> 571558Srgrimes#include <setjmp.h> 581558Srgrimes#include <signal.h> 591558Srgrimes#include <stdio.h> 601558Srgrimes#include <stdlib.h> 611558Srgrimes#include <string.h> 621558Srgrimes#include <unistd.h> 631558Srgrimes 641558Srgrimes#include "pathnames.h" 651558Srgrimes 661558Srgrimes#ifdef DEBUG 671558Srgrimes#undef _PATH_NOLOGIN 681558Srgrimes#define _PATH_NOLOGIN "./nologin" 691558Srgrimes#endif 701558Srgrimes 711558Srgrimes#define H *60*60 721558Srgrimes#define M *60 731558Srgrimes#define S *1 741558Srgrimes#define NOLOG_TIME 5*60 751558Srgrimesstruct interval { 761558Srgrimes int timeleft, timetowait; 771558Srgrimes} tlist[] = { 7832399Salex { 10 H, 5 H }, 7932399Salex { 5 H, 3 H }, 8032399Salex { 2 H, 1 H }, 8132399Salex { 1 H, 30 M }, 8232399Salex { 30 M, 10 M }, 8332399Salex { 20 M, 10 M }, 8432399Salex { 10 M, 5 M }, 8532399Salex { 5 M, 3 M }, 8632399Salex { 2 M, 1 M }, 8732399Salex { 1 M, 30 S }, 8832399Salex { 30 S, 30 S }, 8932399Salex { 0 , 0 } 901558Srgrimes}; 911558Srgrimes#undef H 921558Srgrimes#undef M 931558Srgrimes#undef S 941558Srgrimes 951558Srgrimesstatic time_t offset, shuttime; 9648078Srustatic int dohalt, dopower, doreboot, killflg, mbuflen, oflag; 971558Srgrimesstatic char *nosync, *whom, mbuf[BUFSIZ]; 981558Srgrimes 991558Srgrimesvoid badtime __P((void)); 1001558Srgrimesvoid die_you_gravy_sucking_pig_dog __P((void)); 1011558Srgrimesvoid finish __P((int)); 1021558Srgrimesvoid getoffset __P((char *)); 1031558Srgrimesvoid loop __P((void)); 1041558Srgrimesvoid nolog __P((void)); 1051558Srgrimesvoid timeout __P((int)); 1061558Srgrimesvoid timewarn __P((int)); 10748078Sruvoid usage __P((const char *)); 1081558Srgrimes 1091558Srgrimesint 1101558Srgrimesmain(argc, argv) 1111558Srgrimes int argc; 1121558Srgrimes char *argv[]; 1131558Srgrimes{ 1141558Srgrimes register char *p, *endp; 1151558Srgrimes struct passwd *pw; 1161558Srgrimes int arglen, ch, len, readstdin; 1171558Srgrimes 1181558Srgrimes#ifndef DEBUG 11926737Scharnier if (geteuid()) 12026737Scharnier errx(1, "NOT super-user"); 1211558Srgrimes#endif 1221558Srgrimes nosync = NULL; 1231558Srgrimes readstdin = 0; 12448078Sru while ((ch = getopt(argc, argv, "-hknopr")) != -1) 1251558Srgrimes switch (ch) { 1261558Srgrimes case '-': 1271558Srgrimes readstdin = 1; 1281558Srgrimes break; 1291558Srgrimes case 'h': 1301558Srgrimes dohalt = 1; 1311558Srgrimes break; 1321558Srgrimes case 'k': 1331558Srgrimes killflg = 1; 1341558Srgrimes break; 1351558Srgrimes case 'n': 1361558Srgrimes nosync = "-n"; 1371558Srgrimes break; 13848078Sru case 'o': 13948078Sru oflag = 1; 14048078Sru break; 14141666Smsmith case 'p': 14241666Smsmith dopower = 1; 14341666Smsmith break; 1441558Srgrimes case 'r': 1451558Srgrimes doreboot = 1; 1461558Srgrimes break; 1471558Srgrimes case '?': 1481558Srgrimes default: 14948078Sru usage((char *)NULL); 1501558Srgrimes } 1511558Srgrimes argc -= optind; 1521558Srgrimes argv += optind; 1531558Srgrimes 1541558Srgrimes if (argc < 1) 15548078Sru usage((char *)NULL); 1561558Srgrimes 15748078Sru if (killflg + doreboot + dohalt + dopower > 1) 15848078Sru usage("incompatible switches -h, -k, -p and -r"); 15948062Sjkoshy 16048078Sru if (oflag && !(dohalt || dopower || doreboot)) 16148078Sru usage("-o requires -h, -p or -r"); 16248062Sjkoshy 16348078Sru if (nosync != NULL && !oflag) 16448078Sru usage("-n requires -o"); 16548078Sru 1661558Srgrimes getoffset(*argv++); 1671558Srgrimes 1681558Srgrimes if (*argv) { 1691558Srgrimes for (p = mbuf, len = sizeof(mbuf); *argv; ++argv) { 1701558Srgrimes arglen = strlen(*argv); 1711558Srgrimes if ((len -= arglen) <= 2) 1721558Srgrimes break; 1731558Srgrimes if (p != mbuf) 1741558Srgrimes *p++ = ' '; 17541684Sbde memmove(p, *argv, arglen); 1761558Srgrimes p += arglen; 1771558Srgrimes } 1781558Srgrimes *p = '\n'; 1791558Srgrimes *++p = '\0'; 1801558Srgrimes } 1811558Srgrimes 1821558Srgrimes if (readstdin) { 1831558Srgrimes p = mbuf; 1841558Srgrimes endp = mbuf + sizeof(mbuf) - 2; 1851558Srgrimes for (;;) { 1861558Srgrimes if (!fgets(p, endp - p + 1, stdin)) 1871558Srgrimes break; 1881558Srgrimes for (; *p && p < endp; ++p); 1891558Srgrimes if (p == endp) { 1901558Srgrimes *p = '\n'; 1911558Srgrimes *++p = '\0'; 1921558Srgrimes break; 1931558Srgrimes } 1941558Srgrimes } 1951558Srgrimes } 1961558Srgrimes mbuflen = strlen(mbuf); 1971558Srgrimes 1981558Srgrimes if (offset) 1991558Srgrimes (void)printf("Shutdown at %.24s.\n", ctime(&shuttime)); 2001558Srgrimes else 2011558Srgrimes (void)printf("Shutdown NOW!\n"); 2021558Srgrimes 2031558Srgrimes if (!(whom = getlogin())) 2041558Srgrimes whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???"; 2051558Srgrimes 2061558Srgrimes#ifdef DEBUG 2071558Srgrimes (void)putc('\n', stdout); 2081558Srgrimes#else 2091558Srgrimes (void)setpriority(PRIO_PROCESS, 0, PRIO_MIN); 2101558Srgrimes { 2111558Srgrimes int forkpid; 2121558Srgrimes 2131558Srgrimes forkpid = fork(); 21426737Scharnier if (forkpid == -1) 21526737Scharnier err(1, "fork"); 21626737Scharnier if (forkpid) 21726737Scharnier errx(0, "[pid %d]", forkpid); 2181558Srgrimes } 21928613Sjoerg setsid(); 2201558Srgrimes#endif 2211558Srgrimes openlog("shutdown", LOG_CONS, LOG_AUTH); 2221558Srgrimes loop(); 22338036Scharnier return(0); 2241558Srgrimes} 2251558Srgrimes 2261558Srgrimesvoid 2271558Srgrimesloop() 2281558Srgrimes{ 2291558Srgrimes struct interval *tp; 2301558Srgrimes u_int sltime; 2311558Srgrimes int logged; 2321558Srgrimes 2331558Srgrimes if (offset <= NOLOG_TIME) { 2341558Srgrimes logged = 1; 2351558Srgrimes nolog(); 2361558Srgrimes } 2371558Srgrimes else 2381558Srgrimes logged = 0; 2391558Srgrimes tp = tlist; 2401558Srgrimes if (tp->timeleft < offset) 2411558Srgrimes (void)sleep((u_int)(offset - tp->timeleft)); 2421558Srgrimes else { 24348004Sru while (tp->timeleft && offset < tp->timeleft) 2441558Srgrimes ++tp; 2451558Srgrimes /* 2461558Srgrimes * Warn now, if going to sleep more than a fifth of 2471558Srgrimes * the next wait time. 2481558Srgrimes */ 24932399Salex if ((sltime = offset - tp->timeleft)) { 2501558Srgrimes if (sltime > tp->timetowait / 5) 2511558Srgrimes timewarn(offset); 2521558Srgrimes (void)sleep(sltime); 2531558Srgrimes } 2541558Srgrimes } 2551558Srgrimes for (;; ++tp) { 2561558Srgrimes timewarn(tp->timeleft); 2571558Srgrimes if (!logged && tp->timeleft <= NOLOG_TIME) { 2581558Srgrimes logged = 1; 2591558Srgrimes nolog(); 2601558Srgrimes } 2611558Srgrimes (void)sleep((u_int)tp->timetowait); 2621558Srgrimes if (!tp->timeleft) 2631558Srgrimes break; 2641558Srgrimes } 2651558Srgrimes die_you_gravy_sucking_pig_dog(); 2661558Srgrimes} 2671558Srgrimes 2681558Srgrimesstatic jmp_buf alarmbuf; 2691558Srgrimes 27032399Salexstatic char *restricted_environ[] = { 27132399Salex "PATH=" _PATH_STDPATH, 27232399Salex NULL 27332399Salex}; 27432399Salex 2751558Srgrimesvoid 2761558Srgrimestimewarn(timeleft) 2771558Srgrimes int timeleft; 2781558Srgrimes{ 2791558Srgrimes static int first; 2801558Srgrimes static char hostname[MAXHOSTNAMELEN + 1]; 2811558Srgrimes FILE *pf; 2821558Srgrimes char wcmd[MAXPATHLEN + 4]; 28332399Salex extern char **environ; 2841558Srgrimes 2851558Srgrimes if (!first++) 2861558Srgrimes (void)gethostname(hostname, sizeof(hostname)); 2871558Srgrimes 2881558Srgrimes /* undoc -n option to wall suppresses normal wall banner */ 2891558Srgrimes (void)snprintf(wcmd, sizeof(wcmd), "%s -n", _PATH_WALL); 29032399Salex environ = restricted_environ; 2911558Srgrimes if (!(pf = popen(wcmd, "w"))) { 2921558Srgrimes syslog(LOG_ERR, "shutdown: can't find %s: %m", _PATH_WALL); 2931558Srgrimes return; 2941558Srgrimes } 2951558Srgrimes 2961558Srgrimes (void)fprintf(pf, 2971558Srgrimes "\007*** %sSystem shutdown message from %s@%s ***\007\n", 2981558Srgrimes timeleft ? "": "FINAL ", whom, hostname); 2991558Srgrimes 3001558Srgrimes if (timeleft > 10*60) 3011558Srgrimes (void)fprintf(pf, "System going down at %5.5s\n\n", 3021558Srgrimes ctime(&shuttime) + 11); 3031558Srgrimes else if (timeleft > 59) 3041558Srgrimes (void)fprintf(pf, "System going down in %d minute%s\n\n", 3051558Srgrimes timeleft / 60, (timeleft > 60) ? "s" : ""); 3061558Srgrimes else if (timeleft) 3071558Srgrimes (void)fprintf(pf, "System going down in 30 seconds\n\n"); 3081558Srgrimes else 3091558Srgrimes (void)fprintf(pf, "System going down IMMEDIATELY\n\n"); 3101558Srgrimes 3111558Srgrimes if (mbuflen) 3121558Srgrimes (void)fwrite(mbuf, sizeof(*mbuf), mbuflen, pf); 3131558Srgrimes 3141558Srgrimes /* 3151558Srgrimes * play some games, just in case wall doesn't come back 31638036Scharnier * probably unnecessary, given that wall is careful. 3171558Srgrimes */ 3181558Srgrimes if (!setjmp(alarmbuf)) { 3191558Srgrimes (void)signal(SIGALRM, timeout); 3201558Srgrimes (void)alarm((u_int)30); 3211558Srgrimes (void)pclose(pf); 3221558Srgrimes (void)alarm((u_int)0); 3231558Srgrimes (void)signal(SIGALRM, SIG_DFL); 3241558Srgrimes } 3251558Srgrimes} 3261558Srgrimes 3271558Srgrimesvoid 3281558Srgrimestimeout(signo) 3291558Srgrimes int signo; 3301558Srgrimes{ 3311558Srgrimes longjmp(alarmbuf, 1); 3321558Srgrimes} 3331558Srgrimes 3341558Srgrimesvoid 3351558Srgrimesdie_you_gravy_sucking_pig_dog() 3361558Srgrimes{ 33732399Salex char *empty_environ[] = { NULL }; 3381558Srgrimes 3391558Srgrimes syslog(LOG_NOTICE, "%s by %s: %s", 34041666Smsmith doreboot ? "reboot" : dohalt ? "halt" : dopower ? "power-down" : 34141666Smsmith "shutdown", whom, mbuf); 3421558Srgrimes (void)sleep(2); 3431558Srgrimes 3441558Srgrimes (void)printf("\r\nSystem shutdown time has arrived\007\007\r\n"); 3451558Srgrimes if (killflg) { 3461558Srgrimes (void)printf("\rbut you'll have to do it yourself\r\n"); 3474844Sats exit(0); 3481558Srgrimes } 3491558Srgrimes#ifdef DEBUG 3501558Srgrimes if (doreboot) 3511558Srgrimes (void)printf("reboot"); 3521558Srgrimes else if (dohalt) 3531558Srgrimes (void)printf("halt"); 35441666Smsmith else if (dopower) 35541666Smsmith (void)printf("power-down"); 35648078Sru if (nosync != NULL) 3571558Srgrimes (void)printf(" no sync"); 3581558Srgrimes (void)printf("\nkill -HUP 1\n"); 3591558Srgrimes#else 36048078Sru if (!oflag) { 36148078Sru (void)kill(1, doreboot ? SIGINT : /* reboot */ 36248078Sru dohalt ? SIGUSR1 : /* halt */ 36348078Sru dopower ? SIGUSR2 : /* power-down */ 36448078Sru SIGTERM); /* single-user */ 36548078Sru } else { 36648078Sru if (doreboot) { 36748078Sru execle(_PATH_REBOOT, "reboot", "-l", nosync, 36848078Sru (char *)NULL, empty_environ); 36948078Sru syslog(LOG_ERR, "shutdown: can't exec %s: %m.", 37048078Sru _PATH_REBOOT); 37148078Sru warn(_PATH_REBOOT); 37248078Sru } 37348078Sru else if (dohalt) { 37448078Sru execle(_PATH_HALT, "halt", "-l", nosync, 37548078Sru (char *)NULL, empty_environ); 37648078Sru syslog(LOG_ERR, "shutdown: can't exec %s: %m.", 37748078Sru _PATH_HALT); 37848078Sru warn(_PATH_HALT); 37948078Sru } 38048078Sru else if (dopower) { 38148078Sru execle(_PATH_HALT, "halt", "-l", "-p", nosync, 38248078Sru (char *)NULL, empty_environ); 38348078Sru syslog(LOG_ERR, "shutdown: can't exec %s: %m.", 38448078Sru _PATH_HALT); 38548078Sru warn(_PATH_HALT); 38648078Sru } 38748078Sru (void)kill(1, SIGTERM); /* to single-user */ 3881558Srgrimes } 3891558Srgrimes#endif 3901558Srgrimes finish(0); 3911558Srgrimes} 3921558Srgrimes 3931558Srgrimes#define ATOI2(p) (p[0] - '0') * 10 + (p[1] - '0'); p += 2; 3941558Srgrimes 3951558Srgrimesvoid 3961558Srgrimesgetoffset(timearg) 3971558Srgrimes register char *timearg; 3981558Srgrimes{ 3991558Srgrimes register struct tm *lt; 4001558Srgrimes register char *p; 4011558Srgrimes time_t now; 40232328Salex int this_year; 4031558Srgrimes 40448062Sjkoshy (void)time(&now); 40548062Sjkoshy 4061558Srgrimes if (!strcasecmp(timearg, "now")) { /* now */ 4071558Srgrimes offset = 0; 40848062Sjkoshy shuttime = now; 4091558Srgrimes return; 4101558Srgrimes } 4111558Srgrimes 4121558Srgrimes if (*timearg == '+') { /* +minutes */ 4131558Srgrimes if (!isdigit(*++timearg)) 4141558Srgrimes badtime(); 41548004Sru if ((offset = atoi(timearg) * 60) < 0) 41648004Sru badtime(); 4171558Srgrimes shuttime = now + offset; 4181558Srgrimes return; 4191558Srgrimes } 4201558Srgrimes 4211558Srgrimes /* handle hh:mm by getting rid of the colon */ 4221558Srgrimes for (p = timearg; *p; ++p) 42348956Sbillf if (!isascii(*p) || !isdigit(*p)) { 4241558Srgrimes if (*p == ':' && strlen(p) == 3) { 4251558Srgrimes p[0] = p[1]; 4261558Srgrimes p[1] = p[2]; 4271558Srgrimes p[2] = '\0'; 4281558Srgrimes } 4291558Srgrimes else 4301558Srgrimes badtime(); 43148956Sbillf } 4321558Srgrimes 4331558Srgrimes unsetenv("TZ"); /* OUR timezone */ 4341558Srgrimes lt = localtime(&now); /* current time val */ 4351558Srgrimes 4361558Srgrimes switch(strlen(timearg)) { 4371558Srgrimes case 10: 43832328Salex this_year = lt->tm_year; 4391558Srgrimes lt->tm_year = ATOI2(timearg); 44032328Salex /* 44132328Salex * check if the specified year is in the next century. 44232328Salex * allow for one year of user error as many people will 44332328Salex * enter n - 1 at the start of year n. 44432328Salex */ 44532328Salex if (lt->tm_year < (this_year % 100) - 1) 44632328Salex lt->tm_year += 100; 44732329Salex /* adjust for the year 2000 and beyond */ 44832328Salex lt->tm_year += (this_year - (this_year % 100)); 4491558Srgrimes /* FALLTHROUGH */ 4501558Srgrimes case 8: 4511558Srgrimes lt->tm_mon = ATOI2(timearg); 4521558Srgrimes if (--lt->tm_mon < 0 || lt->tm_mon > 11) 4531558Srgrimes badtime(); 4541558Srgrimes /* FALLTHROUGH */ 4551558Srgrimes case 6: 4561558Srgrimes lt->tm_mday = ATOI2(timearg); 4571558Srgrimes if (lt->tm_mday < 1 || lt->tm_mday > 31) 4581558Srgrimes badtime(); 4591558Srgrimes /* FALLTHROUGH */ 4601558Srgrimes case 4: 4611558Srgrimes lt->tm_hour = ATOI2(timearg); 4621558Srgrimes if (lt->tm_hour < 0 || lt->tm_hour > 23) 4631558Srgrimes badtime(); 4641558Srgrimes lt->tm_min = ATOI2(timearg); 4651558Srgrimes if (lt->tm_min < 0 || lt->tm_min > 59) 4661558Srgrimes badtime(); 4671558Srgrimes lt->tm_sec = 0; 4681558Srgrimes if ((shuttime = mktime(lt)) == -1) 4691558Srgrimes badtime(); 47026737Scharnier if ((offset = shuttime - now) < 0) 47126737Scharnier errx(1, "that time is already past."); 4721558Srgrimes break; 4731558Srgrimes default: 4741558Srgrimes badtime(); 4751558Srgrimes } 4761558Srgrimes} 4771558Srgrimes 4781558Srgrimes#define NOMSG "\n\nNO LOGINS: System going down at " 4791558Srgrimesvoid 4801558Srgrimesnolog() 4811558Srgrimes{ 4821558Srgrimes int logfd; 4831558Srgrimes char *ct; 4841558Srgrimes 4851558Srgrimes (void)unlink(_PATH_NOLOGIN); /* in case linked to another file */ 4861558Srgrimes (void)signal(SIGINT, finish); 4871558Srgrimes (void)signal(SIGHUP, finish); 4881558Srgrimes (void)signal(SIGQUIT, finish); 4891558Srgrimes (void)signal(SIGTERM, finish); 4901558Srgrimes if ((logfd = open(_PATH_NOLOGIN, O_WRONLY|O_CREAT|O_TRUNC, 4911558Srgrimes 0664)) >= 0) { 4921558Srgrimes (void)write(logfd, NOMSG, sizeof(NOMSG) - 1); 4931558Srgrimes ct = ctime(&shuttime); 4941558Srgrimes (void)write(logfd, ct + 11, 5); 4951558Srgrimes (void)write(logfd, "\n\n", 2); 4961558Srgrimes (void)write(logfd, mbuf, strlen(mbuf)); 4971558Srgrimes (void)close(logfd); 4981558Srgrimes } 4991558Srgrimes} 5001558Srgrimes 5011558Srgrimesvoid 5021558Srgrimesfinish(signo) 5031558Srgrimes int signo; 5041558Srgrimes{ 50541684Sbde if (!killflg) 50641684Sbde (void)unlink(_PATH_NOLOGIN); 5071558Srgrimes exit(0); 5081558Srgrimes} 5091558Srgrimes 5101558Srgrimesvoid 5111558Srgrimesbadtime() 5121558Srgrimes{ 51338036Scharnier errx(1, "bad time format"); 5141558Srgrimes} 5151558Srgrimes 5161558Srgrimesvoid 51748078Sruusage(cp) 51848078Sru const char *cp; 5191558Srgrimes{ 52048078Sru if (cp != NULL) 52148078Sru warnx("%s", cp); 52248078Sru (void)fprintf(stderr, 52348078Sru "usage: shutdown [-] [-h | -p | -r | -k] [-o [-n]]" 52448078Sru " time [warning-message ...]\n"); 5251558Srgrimes exit(1); 5261558Srgrimes} 527