/* @(#)shutdown.c 4.4 (Berkeley/Melbourne) 81/04/21 */
* /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
* Michael Toy, Berkeley, 1981
#define LOGFILE "shutdown.log"
#define LOGFILE "/usr/adm/shutdownlog"
#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";
char *shutter
, *getlogin();
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 (in ", ts
+11);
printf("%d hour%s ", h
, h
!= 1 ? "s" : "");
printf("%d minute%s) ", 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
= stdout
) != 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");
fprintf(term
, "\007\007*** System shutdown message from %s ***\n", shutter
);
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 second%s\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
);
* make an entry in the shutdown log
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
struct tm
*tm
, *localtime();
fp
= fopen(LOGFILE
, "a");
fprintf(fp
, "%02d:%02d %s %s %2d, %4d. Shutdown:", tm
->tm_hour
,
tm
->tm_min
, days
[tm
->tm_wday
], months
[tm
->tm_mon
],
tm
->tm_mday
, tm
->tm_year
+ 1900);
for (mess
= nolog2
; *mess
; mess
++)
fprintf(fp
, " %s", *mess
);