Home | History | Annotate | Line # | Download | only in shutdown
shutdown.c revision 1.7
      1  1.1      cgd /*
      2  1.7  mycroft  * Copyright (c) 1988, 1990, 1993
      3  1.7  mycroft  *	The Regents of the University of California.  All rights reserved.
      4  1.1      cgd  *
      5  1.1      cgd  * Redistribution and use in source and binary forms, with or without
      6  1.1      cgd  * modification, are permitted provided that the following conditions
      7  1.1      cgd  * are met:
      8  1.1      cgd  * 1. Redistributions of source code must retain the above copyright
      9  1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     10  1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     12  1.1      cgd  *    documentation and/or other materials provided with the distribution.
     13  1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     14  1.1      cgd  *    must display the following acknowledgement:
     15  1.1      cgd  *	This product includes software developed by the University of
     16  1.1      cgd  *	California, Berkeley and its contributors.
     17  1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     18  1.1      cgd  *    may be used to endorse or promote products derived from this software
     19  1.1      cgd  *    without specific prior written permission.
     20  1.1      cgd  *
     21  1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1      cgd  * SUCH DAMAGE.
     32  1.1      cgd  */
     33  1.1      cgd 
     34  1.1      cgd #ifndef lint
     35  1.7  mycroft static char copyright[] =
     36  1.7  mycroft "@(#) Copyright (c) 1988, 1990, 1993\n\
     37  1.7  mycroft 	The Regents of the University of California.  All rights reserved.\n";
     38  1.1      cgd #endif /* not lint */
     39  1.1      cgd 
     40  1.1      cgd #ifndef lint
     41  1.7  mycroft /*static char sccsid[] = "from: @(#)shutdown.c	8.2 (Berkeley) 2/16/94";*/
     42  1.7  mycroft static char *rcsid = "$Id: shutdown.c,v 1.7 1994/09/17 00:10:12 mycroft Exp $";
     43  1.1      cgd #endif /* not lint */
     44  1.1      cgd 
     45  1.1      cgd #include <sys/param.h>
     46  1.1      cgd #include <sys/time.h>
     47  1.1      cgd #include <sys/resource.h>
     48  1.1      cgd #include <sys/syslog.h>
     49  1.7  mycroft 
     50  1.7  mycroft #include <ctype.h>
     51  1.7  mycroft #include <fcntl.h>
     52  1.7  mycroft #include <pwd.h>
     53  1.1      cgd #include <setjmp.h>
     54  1.7  mycroft #include <signal.h>
     55  1.7  mycroft #include <stdio.h>
     56  1.7  mycroft #include <stdlib.h>
     57  1.7  mycroft #include <string.h>
     58  1.1      cgd #include <tzfile.h>
     59  1.7  mycroft #include <unistd.h>
     60  1.7  mycroft 
     61  1.1      cgd #include "pathnames.h"
     62  1.1      cgd 
     63  1.1      cgd #ifdef DEBUG
     64  1.1      cgd #undef _PATH_NOLOGIN
     65  1.1      cgd #define	_PATH_NOLOGIN	"./nologin"
     66  1.1      cgd #undef _PATH_FASTBOOT
     67  1.1      cgd #define	_PATH_FASTBOOT	"./fastboot"
     68  1.1      cgd #endif
     69  1.1      cgd 
     70  1.1      cgd #define	H		*60*60
     71  1.1      cgd #define	M		*60
     72  1.1      cgd #define	S		*1
     73  1.1      cgd #define	NOLOG_TIME	5*60
     74  1.1      cgd struct interval {
     75  1.1      cgd 	int timeleft, timetowait;
     76  1.1      cgd } tlist[] = {
     77  1.1      cgd 	10 H,  5 H,	 5 H,  3 H,	 2 H,  1 H,	1 H, 30 M,
     78  1.1      cgd 	30 M, 10 M,	20 M, 10 M,	10 M,  5 M,	5 M,  3 M,
     79  1.1      cgd 	 2 M,  1 M,	 1 M, 30 S,	30 S, 30 S,
     80  1.1      cgd 	 0, 0,
     81  1.7  mycroft };
     82  1.1      cgd #undef H
     83  1.1      cgd #undef M
     84  1.1      cgd #undef S
     85  1.1      cgd 
     86  1.1      cgd static time_t offset, shuttime;
     87  1.1      cgd static int dofast, dohalt, doreboot, killflg, mbuflen;
     88  1.1      cgd static char *nosync, *whom, mbuf[BUFSIZ];
     89  1.1      cgd 
     90  1.7  mycroft void badtime __P((void));
     91  1.7  mycroft void die_you_gravy_sucking_pig_dog __P((void));
     92  1.7  mycroft void doitfast __P((void));
     93  1.7  mycroft void finish __P((int));
     94  1.7  mycroft void getoffset __P((char *));
     95  1.7  mycroft void loop __P((void));
     96  1.7  mycroft void nolog __P((void));
     97  1.7  mycroft void timeout __P((int));
     98  1.7  mycroft void timewarn __P((int));
     99  1.7  mycroft void usage __P((void));
    100  1.5      cgd 
    101  1.7  mycroft int
    102  1.1      cgd main(argc, argv)
    103  1.1      cgd 	int argc;
    104  1.7  mycroft 	char *argv[];
    105  1.1      cgd {
    106  1.1      cgd 	extern int optind;
    107  1.1      cgd 	register char *p, *endp;
    108  1.7  mycroft 	struct passwd *pw;
    109  1.1      cgd 	int arglen, ch, len, readstdin;
    110  1.1      cgd 
    111  1.1      cgd #ifndef DEBUG
    112  1.1      cgd 	if (geteuid()) {
    113  1.1      cgd 		(void)fprintf(stderr, "shutdown: NOT super-user\n");
    114  1.1      cgd 		exit(1);
    115  1.1      cgd 	}
    116  1.1      cgd #endif
    117  1.1      cgd 	nosync = NULL;
    118  1.1      cgd 	readstdin = 0;
    119  1.1      cgd 	while ((ch = getopt(argc, argv, "-fhknr")) != EOF)
    120  1.1      cgd 		switch (ch) {
    121  1.1      cgd 		case '-':
    122  1.1      cgd 			readstdin = 1;
    123  1.1      cgd 			break;
    124  1.1      cgd 		case 'f':
    125  1.1      cgd 			dofast = 1;
    126  1.1      cgd 			break;
    127  1.1      cgd 		case 'h':
    128  1.1      cgd 			dohalt = 1;
    129  1.1      cgd 			break;
    130  1.1      cgd 		case 'k':
    131  1.1      cgd 			killflg = 1;
    132  1.1      cgd 			break;
    133  1.1      cgd 		case 'n':
    134  1.1      cgd 			nosync = "-n";
    135  1.1      cgd 			break;
    136  1.1      cgd 		case 'r':
    137  1.1      cgd 			doreboot = 1;
    138  1.1      cgd 			break;
    139  1.1      cgd 		case '?':
    140  1.1      cgd 		default:
    141  1.1      cgd 			usage();
    142  1.1      cgd 		}
    143  1.1      cgd 	argc -= optind;
    144  1.1      cgd 	argv += optind;
    145  1.1      cgd 
    146  1.1      cgd 	if (argc < 1)
    147  1.1      cgd 		usage();
    148  1.1      cgd 
    149  1.1      cgd 	if (dofast && nosync) {
    150  1.1      cgd 		(void)fprintf(stderr,
    151  1.1      cgd 		    "shutdown: incompatible switches -f and -n.\n");
    152  1.1      cgd 		usage();
    153  1.1      cgd 	}
    154  1.1      cgd 	if (doreboot && dohalt) {
    155  1.1      cgd 		(void)fprintf(stderr,
    156  1.1      cgd 		    "shutdown: incompatible switches -h and -r.\n");
    157  1.1      cgd 		usage();
    158  1.1      cgd 	}
    159  1.1      cgd 	getoffset(*argv++);
    160  1.1      cgd 
    161  1.1      cgd 	if (*argv) {
    162  1.1      cgd 		for (p = mbuf, len = sizeof(mbuf); *argv; ++argv) {
    163  1.1      cgd 			arglen = strlen(*argv);
    164  1.1      cgd 			if ((len -= arglen) <= 2)
    165  1.1      cgd 				break;
    166  1.1      cgd 			if (p != mbuf)
    167  1.1      cgd 				*p++ = ' ';
    168  1.1      cgd 			bcopy(*argv, p, arglen);
    169  1.1      cgd 			p += arglen;
    170  1.1      cgd 		}
    171  1.1      cgd 		*p = '\n';
    172  1.1      cgd 		*++p = '\0';
    173  1.1      cgd 	}
    174  1.1      cgd 
    175  1.1      cgd 	if (readstdin) {
    176  1.1      cgd 		p = mbuf;
    177  1.1      cgd 		endp = mbuf + sizeof(mbuf) - 2;
    178  1.1      cgd 		for (;;) {
    179  1.1      cgd 			if (!fgets(p, endp - p + 1, stdin))
    180  1.1      cgd 				break;
    181  1.1      cgd 			for (; *p &&  p < endp; ++p);
    182  1.1      cgd 			if (p == endp) {
    183  1.1      cgd 				*p = '\n';
    184  1.1      cgd 				*++p = '\0';
    185  1.1      cgd 				break;
    186  1.1      cgd 			}
    187  1.1      cgd 		}
    188  1.1      cgd 	}
    189  1.1      cgd 	mbuflen = strlen(mbuf);
    190  1.1      cgd 
    191  1.1      cgd 	if (offset)
    192  1.1      cgd 		(void)printf("Shutdown at %.24s.\n", ctime(&shuttime));
    193  1.1      cgd 	else
    194  1.1      cgd 		(void)printf("Shutdown NOW!\n");
    195  1.1      cgd 
    196  1.1      cgd 	if (!(whom = getlogin()))
    197  1.1      cgd 		whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???";
    198  1.1      cgd 
    199  1.1      cgd #ifdef DEBUG
    200  1.1      cgd 	(void)putc('\n', stdout);
    201  1.1      cgd #else
    202  1.1      cgd 	(void)setpriority(PRIO_PROCESS, 0, PRIO_MIN);
    203  1.1      cgd 	{
    204  1.1      cgd 		int forkpid;
    205  1.1      cgd 
    206  1.1      cgd 		forkpid = fork();
    207  1.1      cgd 		if (forkpid == -1) {
    208  1.1      cgd 			perror("shutdown: fork");
    209  1.1      cgd 			exit(1);
    210  1.1      cgd 		}
    211  1.1      cgd 		if (forkpid) {
    212  1.1      cgd 			(void)printf("shutdown: [pid %d]\n", forkpid);
    213  1.1      cgd 			exit(0);
    214  1.1      cgd 		}
    215  1.1      cgd 	}
    216  1.1      cgd #endif
    217  1.1      cgd 	openlog("shutdown", LOG_CONS, LOG_AUTH);
    218  1.1      cgd 	loop();
    219  1.7  mycroft 	/* NOTREACHED */
    220  1.1      cgd }
    221  1.1      cgd 
    222  1.7  mycroft void
    223  1.1      cgd loop()
    224  1.1      cgd {
    225  1.7  mycroft 	struct interval *tp;
    226  1.1      cgd 	u_int sltime;
    227  1.1      cgd 	int logged;
    228  1.1      cgd 
    229  1.1      cgd 	if (offset <= NOLOG_TIME) {
    230  1.1      cgd 		logged = 1;
    231  1.1      cgd 		nolog();
    232  1.1      cgd 	}
    233  1.1      cgd 	else
    234  1.1      cgd 		logged = 0;
    235  1.1      cgd 	tp = tlist;
    236  1.1      cgd 	if (tp->timeleft < offset)
    237  1.1      cgd 		(void)sleep((u_int)(offset - tp->timeleft));
    238  1.1      cgd 	else {
    239  1.1      cgd 		while (offset < tp->timeleft)
    240  1.1      cgd 			++tp;
    241  1.1      cgd 		/*
    242  1.7  mycroft 		 * Warn now, if going to sleep more than a fifth of
    243  1.1      cgd 		 * the next wait time.
    244  1.1      cgd 		 */
    245  1.1      cgd 		if (sltime = offset - tp->timeleft) {
    246  1.1      cgd 			if (sltime > tp->timetowait / 5)
    247  1.7  mycroft 				timewarn(offset);
    248  1.1      cgd 			(void)sleep(sltime);
    249  1.1      cgd 		}
    250  1.1      cgd 	}
    251  1.1      cgd 	for (;; ++tp) {
    252  1.7  mycroft 		timewarn(tp->timeleft);
    253  1.1      cgd 		if (!logged && tp->timeleft <= NOLOG_TIME) {
    254  1.1      cgd 			logged = 1;
    255  1.1      cgd 			nolog();
    256  1.1      cgd 		}
    257  1.1      cgd 		(void)sleep((u_int)tp->timetowait);
    258  1.1      cgd 		if (!tp->timeleft)
    259  1.1      cgd 			break;
    260  1.1      cgd 	}
    261  1.1      cgd 	die_you_gravy_sucking_pig_dog();
    262  1.1      cgd }
    263  1.1      cgd 
    264  1.1      cgd static jmp_buf alarmbuf;
    265  1.1      cgd 
    266  1.7  mycroft void
    267  1.7  mycroft timewarn(timeleft)
    268  1.5      cgd 	int timeleft;
    269  1.1      cgd {
    270  1.1      cgd 	static int first;
    271  1.1      cgd 	static char hostname[MAXHOSTNAMELEN + 1];
    272  1.7  mycroft 	FILE *pf;
    273  1.1      cgd 	char wcmd[MAXPATHLEN + 4];
    274  1.1      cgd 
    275  1.1      cgd 	if (!first++)
    276  1.1      cgd 		(void)gethostname(hostname, sizeof(hostname));
    277  1.1      cgd 
    278  1.1      cgd 	/* undoc -n option to wall suppresses normal wall banner */
    279  1.7  mycroft 	(void)snprintf(wcmd, sizeof(wcmd), "%s -n", _PATH_WALL);
    280  1.1      cgd 	if (!(pf = popen(wcmd, "w"))) {
    281  1.1      cgd 		syslog(LOG_ERR, "shutdown: can't find %s: %m", _PATH_WALL);
    282  1.1      cgd 		return;
    283  1.1      cgd 	}
    284  1.1      cgd 
    285  1.1      cgd 	(void)fprintf(pf,
    286  1.1      cgd 	    "\007*** %sSystem shutdown message from %s@%s ***\007\n",
    287  1.5      cgd 	    timeleft ? "": "FINAL ", whom, hostname);
    288  1.1      cgd 
    289  1.5      cgd 	if (timeleft > 10*60)
    290  1.1      cgd 		(void)fprintf(pf, "System going down at %5.5s\n\n",
    291  1.1      cgd 		    ctime(&shuttime) + 11);
    292  1.5      cgd 	else if (timeleft > 59)
    293  1.1      cgd 		(void)fprintf(pf, "System going down in %d minute%s\n\n",
    294  1.5      cgd 		    timeleft / 60, (timeleft > 60) ? "s" : "");
    295  1.5      cgd 	else if (timeleft)
    296  1.1      cgd 		(void)fprintf(pf, "System going down in 30 seconds\n\n");
    297  1.1      cgd 	else
    298  1.1      cgd 		(void)fprintf(pf, "System going down IMMEDIATELY\n\n");
    299  1.1      cgd 
    300  1.1      cgd 	if (mbuflen)
    301  1.1      cgd 		(void)fwrite(mbuf, sizeof(*mbuf), mbuflen, pf);
    302  1.1      cgd 
    303  1.1      cgd 	/*
    304  1.1      cgd 	 * play some games, just in case wall doesn't come back
    305  1.1      cgd 	 * probably unecessary, given that wall is careful.
    306  1.1      cgd 	 */
    307  1.1      cgd 	if (!setjmp(alarmbuf)) {
    308  1.1      cgd 		(void)signal(SIGALRM, timeout);
    309  1.1      cgd 		(void)alarm((u_int)30);
    310  1.1      cgd 		(void)pclose(pf);
    311  1.1      cgd 		(void)alarm((u_int)0);
    312  1.1      cgd 		(void)signal(SIGALRM, SIG_DFL);
    313  1.1      cgd 	}
    314  1.1      cgd }
    315  1.1      cgd 
    316  1.1      cgd void
    317  1.7  mycroft timeout(signo)
    318  1.7  mycroft 	int signo;
    319  1.1      cgd {
    320  1.1      cgd 	longjmp(alarmbuf, 1);
    321  1.1      cgd }
    322  1.1      cgd 
    323  1.7  mycroft void
    324  1.1      cgd die_you_gravy_sucking_pig_dog()
    325  1.1      cgd {
    326  1.1      cgd 
    327  1.1      cgd 	syslog(LOG_NOTICE, "%s by %s: %s",
    328  1.1      cgd 	    doreboot ? "reboot" : dohalt ? "halt" : "shutdown", whom, mbuf);
    329  1.1      cgd 	(void)sleep(2);
    330  1.1      cgd 
    331  1.1      cgd 	(void)printf("\r\nSystem shutdown time has arrived\007\007\r\n");
    332  1.1      cgd 	if (killflg) {
    333  1.1      cgd 		(void)printf("\rbut you'll have to do it yourself\r\n");
    334  1.7  mycroft 		finish(0);
    335  1.1      cgd 	}
    336  1.1      cgd 	if (dofast)
    337  1.1      cgd 		doitfast();
    338  1.1      cgd #ifdef DEBUG
    339  1.1      cgd 	if (doreboot)
    340  1.1      cgd 		(void)printf("reboot");
    341  1.1      cgd 	else if (dohalt)
    342  1.1      cgd 		(void)printf("halt");
    343  1.1      cgd 	if (nosync)
    344  1.1      cgd 		(void)printf(" no sync");
    345  1.1      cgd 	if (dofast)
    346  1.1      cgd 		(void)printf(" no fsck");
    347  1.1      cgd 	(void)printf("\nkill -HUP 1\n");
    348  1.1      cgd #else
    349  1.1      cgd 	if (doreboot) {
    350  1.1      cgd 		execle(_PATH_REBOOT, "reboot", "-l", nosync, 0);
    351  1.1      cgd 		syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_REBOOT);
    352  1.1      cgd 		perror("shutdown");
    353  1.1      cgd 	}
    354  1.1      cgd 	else if (dohalt) {
    355  1.1      cgd 		execle(_PATH_HALT, "halt", "-l", nosync, 0);
    356  1.1      cgd 		syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_HALT);
    357  1.1      cgd 		perror("shutdown");
    358  1.1      cgd 	}
    359  1.1      cgd 	(void)kill(1, SIGTERM);		/* to single user */
    360  1.1      cgd #endif
    361  1.7  mycroft 	finish(0);
    362  1.1      cgd }
    363  1.1      cgd 
    364  1.1      cgd #define	ATOI2(p)	(p[0] - '0') * 10 + (p[1] - '0'); p += 2;
    365  1.1      cgd 
    366  1.7  mycroft void
    367  1.1      cgd getoffset(timearg)
    368  1.1      cgd 	register char *timearg;
    369  1.1      cgd {
    370  1.1      cgd 	register struct tm *lt;
    371  1.1      cgd 	register char *p;
    372  1.7  mycroft 	time_t now;
    373  1.1      cgd 
    374  1.1      cgd 	if (!strcasecmp(timearg, "now")) {		/* now */
    375  1.1      cgd 		offset = 0;
    376  1.1      cgd 		return;
    377  1.1      cgd 	}
    378  1.1      cgd 
    379  1.1      cgd 	(void)time(&now);
    380  1.1      cgd 	if (*timearg == '+') {				/* +minutes */
    381  1.1      cgd 		if (!isdigit(*++timearg))
    382  1.1      cgd 			badtime();
    383  1.1      cgd 		offset = atoi(timearg) * 60;
    384  1.1      cgd 		shuttime = now + offset;
    385  1.1      cgd 		return;
    386  1.1      cgd 	}
    387  1.1      cgd 
    388  1.1      cgd 	/* handle hh:mm by getting rid of the colon */
    389  1.1      cgd 	for (p = timearg; *p; ++p)
    390  1.1      cgd 		if (!isascii(*p) || !isdigit(*p))
    391  1.1      cgd 			if (*p == ':' && strlen(p) == 3) {
    392  1.1      cgd 				p[0] = p[1];
    393  1.1      cgd 				p[1] = p[2];
    394  1.1      cgd 				p[2] = '\0';
    395  1.1      cgd 			}
    396  1.1      cgd 			else
    397  1.1      cgd 				badtime();
    398  1.1      cgd 
    399  1.1      cgd 	unsetenv("TZ");					/* OUR timezone */
    400  1.1      cgd 	lt = localtime(&now);				/* current time val */
    401  1.1      cgd 
    402  1.1      cgd 	switch(strlen(timearg)) {
    403  1.1      cgd 	case 10:
    404  1.1      cgd 		lt->tm_year = ATOI2(timearg);
    405  1.1      cgd 		/* FALLTHROUGH */
    406  1.1      cgd 	case 8:
    407  1.1      cgd 		lt->tm_mon = ATOI2(timearg);
    408  1.1      cgd 		if (--lt->tm_mon < 0 || lt->tm_mon > 11)
    409  1.1      cgd 			badtime();
    410  1.1      cgd 		/* FALLTHROUGH */
    411  1.1      cgd 	case 6:
    412  1.1      cgd 		lt->tm_mday = ATOI2(timearg);
    413  1.1      cgd 		if (lt->tm_mday < 1 || lt->tm_mday > 31)
    414  1.1      cgd 			badtime();
    415  1.1      cgd 		/* FALLTHROUGH */
    416  1.1      cgd 	case 4:
    417  1.1      cgd 		lt->tm_hour = ATOI2(timearg);
    418  1.1      cgd 		if (lt->tm_hour < 0 || lt->tm_hour > 23)
    419  1.1      cgd 			badtime();
    420  1.1      cgd 		lt->tm_min = ATOI2(timearg);
    421  1.1      cgd 		if (lt->tm_min < 0 || lt->tm_min > 59)
    422  1.1      cgd 			badtime();
    423  1.1      cgd 		lt->tm_sec = 0;
    424  1.1      cgd 		if ((shuttime = mktime(lt)) == -1)
    425  1.1      cgd 			badtime();
    426  1.1      cgd 		if ((offset = shuttime - now) < 0) {
    427  1.1      cgd 			(void)fprintf(stderr,
    428  1.1      cgd 			    "shutdown: that time is already past.\n");
    429  1.1      cgd 			exit(1);
    430  1.1      cgd 		}
    431  1.1      cgd 		break;
    432  1.1      cgd 	default:
    433  1.1      cgd 		badtime();
    434  1.1      cgd 	}
    435  1.1      cgd }
    436  1.1      cgd 
    437  1.1      cgd #define	FSMSG	"fastboot file for fsck\n"
    438  1.7  mycroft void
    439  1.1      cgd doitfast()
    440  1.1      cgd {
    441  1.1      cgd 	int fastfd;
    442  1.1      cgd 
    443  1.1      cgd 	if ((fastfd = open(_PATH_FASTBOOT, O_WRONLY|O_CREAT|O_TRUNC,
    444  1.1      cgd 	    0664)) >= 0) {
    445  1.1      cgd 		(void)write(fastfd, FSMSG, sizeof(FSMSG) - 1);
    446  1.1      cgd 		(void)close(fastfd);
    447  1.1      cgd 	}
    448  1.1      cgd }
    449  1.1      cgd 
    450  1.1      cgd #define	NOMSG	"\n\nNO LOGINS: System going down at "
    451  1.7  mycroft void
    452  1.1      cgd nolog()
    453  1.1      cgd {
    454  1.1      cgd 	int logfd;
    455  1.7  mycroft 	char *ct;
    456  1.1      cgd 
    457  1.1      cgd 	(void)unlink(_PATH_NOLOGIN);	/* in case linked to another file */
    458  1.1      cgd 	(void)signal(SIGINT, finish);
    459  1.1      cgd 	(void)signal(SIGHUP, finish);
    460  1.1      cgd 	(void)signal(SIGQUIT, finish);
    461  1.1      cgd 	(void)signal(SIGTERM, finish);
    462  1.1      cgd 	if ((logfd = open(_PATH_NOLOGIN, O_WRONLY|O_CREAT|O_TRUNC,
    463  1.1      cgd 	    0664)) >= 0) {
    464  1.1      cgd 		(void)write(logfd, NOMSG, sizeof(NOMSG) - 1);
    465  1.1      cgd 		ct = ctime(&shuttime);
    466  1.1      cgd 		(void)write(logfd, ct + 11, 5);
    467  1.1      cgd 		(void)write(logfd, "\n\n", 2);
    468  1.1      cgd 		(void)write(logfd, mbuf, strlen(mbuf));
    469  1.1      cgd 		(void)close(logfd);
    470  1.1      cgd 	}
    471  1.1      cgd }
    472  1.1      cgd 
    473  1.1      cgd void
    474  1.7  mycroft finish(signo)
    475  1.7  mycroft 	int signo;
    476  1.1      cgd {
    477  1.6  mycroft 	if (!killflg)
    478  1.6  mycroft 		(void)unlink(_PATH_NOLOGIN);
    479  1.1      cgd 	exit(0);
    480  1.1      cgd }
    481  1.1      cgd 
    482  1.7  mycroft void
    483  1.1      cgd badtime()
    484  1.1      cgd {
    485  1.1      cgd 	(void)fprintf(stderr, "shutdown: bad time format.\n");
    486  1.1      cgd 	exit(1);
    487  1.1      cgd }
    488  1.1      cgd 
    489  1.7  mycroft void
    490  1.1      cgd usage()
    491  1.1      cgd {
    492  1.1      cgd 	fprintf(stderr, "usage: shutdown [-fhknr] shutdowntime [ message ]\n");
    493  1.1      cgd 	exit(1);
    494  1.1      cgd }
    495