/* @(#)shutdown.c 4.1 (Berkeley/Melbourne) 81/02/07 */
* /etc/shutdown when [messages]
* allow super users to tell users and remind users
* of iminent shutdown of unix
* and shut it down automatically
* and even reboot or halt the machine if they desire
* Ian Johnstone, Sydney, 1977
* Robert Elz, Melbourne, 1978
* Peter Lamb, Melbourne, 1980
* William Joy, Berkeley, 1981
#define REBOOT "/etc/reboot"
#define NLOG 20 /* no of lines possible for message */
#define NOLOGTIME 5 MINUTES
extern struct tm
*localtime();
int nlflag
= 1; /* nolog yet to be done */
char term
[sizeof tpath
+ sizeof utmp
.ut_line
];
char nolog1
[] = "\n\nNO LOGINS: System going down at %5.5s\n\n";
char nologin
[] = "nologin";
char nologin
[] = "/etc/nologin";
register char **mess
, *f
;
while (argc
> 0 && (f
= argv
[0], *f
++ == '-')) {
while (i
= *f
++) switch (i
) {
fprintf(stderr
, "shutdown: '%c' - unknown flag\n", i
);
printf("Usage: %s [-krd] shutdowntime [nologmessage]\n",
nowtime
= time((long *)0);
m
= ((stogo
= sdt
- nowtime
) + 30)/60;
printf("Shutdown at %5.5s\n", ts
+11);
printf("%d hour%s ", h
, h
!= 1 ? "s" : "");
printf("%d minute%s\n", m
, m
!= 1 ? "s" : "");
signal(SIGQUIT
, SIG_IGN
);
signal(SIGALRM
, do_nothing
);
for (i
= 0; stogo
<= interval
[i
].stogo
&& interval
[i
].sint
; i
++)
if (stogo
<= NOLOGTIME
&& nlflag
) {
if (sint
>= stogo
|| sint
== 0)
ufd
= open("/etc/utmp",0);
nowtime
= time((long *) 0);
while (read(ufd
,&utmp
,sizeof utmp
)==sizeof utmp
)
strncat(term
, utmp
.ut_line
, sizeof utmp
.ut_line
);
if ((termf
= fopen("/dev/tty", "w")) != NULL
)
if ((termf
= fopen(term
, "w")) != NULL
)
warn(termf
, sdt
, nowtime
);
if (sdt
- nowtime
> 1 MINUTES
)
for (mess
= nolog2
; *mess
; mess
++)
fprintf(termf
, "%s ", *mess
);
printf("\n\007\007System shutdown time has arrived\007\007\n");
printf("but you'll have to do it yourself\n");
execle(REBOOT
, "reboot", 0, 0);
execle(HALT
, "halt", 0, 0);
kill(1, SIGTERM
); /* sync */
kill(1, SIGTERM
); /* sync */
printf("EXTERMINATE EXTERMINATE\n");
stogo
= sdt
- time((long *) 0);
sleep(sint
<stogo
? sint
: stogo
);
tim
= time((long *) 0) + t
;
while (strlen(s
) > 2 && isdigit(*s
))
t
= lt
->tm_sec
+ lt
->tm_min
*60 + lt
->tm_hour
*3600;
if (tim
< t
|| tim
>= (24*3600)) {
/* before now or after midnight */
printf("That must be tomorrow\nCan't you wait till then?\n");
printf("Bad time format\n");
if (sdt
- nowtime
> 10 MINUTES
)
fprintf(term
, "System going down at %5.5s\n", ts
+11);
else if ( sdt
- nowtime
> 60 SECONDS
) {
fprintf(term
, "System going down in %d minute%s\n",
(sdt
-nowtime
+30)/60, (sdt
-nowtime
+30)/60 != 1 ? "s" : "");
} else if ( sdt
- nowtime
> 0 ) {
fprintf(term
, "System going down in %d seconds\n",
sdt
-nowtime
, sdt
-nowtime
!= 1 ? "s" : "");
fprintf(term
, "System going down IMMEDIATELY\n");
if ((nologf
= fopen(nologin
, "w")) != NULL
) {
fprintf(nologf
, nolog1
, (ctime(&sdt
)) + 11);
for (mess
= nolog2
; *mess
; mess
++)
fprintf(nologf
, "\t%s\n", *mess
);
signal(SIGTERM
, SIG_IGN
);
signal(SIGALRM
, do_nothing
);