projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
symbolic links
[unix-history]
/
usr
/
src
/
sbin
/
shutdown
/
shutdown.c
diff --git
a/usr/src/sbin/shutdown/shutdown.c
b/usr/src/sbin/shutdown/shutdown.c
index
9d4e428
..
f9e7014
100644
(file)
--- a/
usr/src/sbin/shutdown/shutdown.c
+++ b/
usr/src/sbin/shutdown/shutdown.c
@@
-1,4
+1,4
@@
-/* @(#)shutdown.c 4.2 (Berkeley/Melbourne) 81/02/28 */
+static char *sccsid = "@(#)shutdown.c 4.11 (Berkeley) 82/02/01";
#include <stdio.h>
#include <ctype.h>
#include <stdio.h>
#include <ctype.h>
@@
-6,6
+6,7
@@
#include <utmp.h>
#include <time.h>
#include <sys/types.h>
#include <utmp.h>
#include <time.h>
#include <sys/types.h>
+#include <whoami.h>
/*
* /etc/shutdown when [messages]
*
/*
* /etc/shutdown when [messages]
*
@@
-19,6
+20,7
@@
* Peter Lamb, Melbourne, 1980
* William Joy, Berkeley, 1981
* Michael Toy, Berkeley, 1981
* Peter Lamb, Melbourne, 1980
* William Joy, Berkeley, 1981
* Michael Toy, Berkeley, 1981
+ * Dave Presotto, Berkeley, 1981
*/
#ifdef DEBUG
#define LOGFILE "shutdown.log"
*/
#ifdef DEBUG
#define LOGFILE "shutdown.log"
@@
-31,8
+33,9
@@
#define HOURS *3600
#define MINUTES *60
#define SECONDS
#define HOURS *3600
#define MINUTES *60
#define SECONDS
-#define NLOG 20 /* no of
line
s possible for message */
+#define NLOG 20 /* no of
arg
s possible for message */
#define NOLOGTIME 5 MINUTES
#define NOLOGTIME 5 MINUTES
+#define IGNOREUSER "sleeper"
int do_nothing();
time_t getsdt();
int do_nothing();
time_t getsdt();
@@
-70,6
+73,7
@@
struct interval {
10 MINUTES, 5 MINUTES,
5 MINUTES, 3 MINUTES,
2 MINUTES, 30 SECONDS,
10 MINUTES, 5 MINUTES,
5 MINUTES, 3 MINUTES,
2 MINUTES, 30 SECONDS,
+ 40 SECONDS, 10 SECONDS,
0 SECONDS, 0 SECONDS
};
char *shutter, *getlogin();
0 SECONDS, 0 SECONDS
};
char *shutter, *getlogin();
@@
-105,10
+109,14
@@
main(argc,argv)
argc--, argv++;
}
if (argc < 1) {
argc--, argv++;
}
if (argc < 1) {
- printf("Usage: %s [
-krd] shutdowntime [nologmessage
]\n",
+ printf("Usage: %s [
-krh ] shutdowntime [ message
]\n",
argv[0]);
finish();
}
argv[0]);
finish();
}
+ if (geteuid()) {
+ fprintf(stderr, "NOT super-user\n");
+ finish();
+ }
sdt = getsdt(argv[0]);
argc--, argv++;
i = 0;
sdt = getsdt(argv[0]);
argc--, argv++;
i = 0;
@@
-133,6
+141,7
@@
main(argc,argv)
signal(SIGTERM, finish);
signal(SIGALRM, do_nothing);
nice(-20);
signal(SIGTERM, finish);
signal(SIGALRM, do_nothing);
nice(-20);
+ fflush(stdout);
#ifndef DEBUG
if (i = fork()) {
printf("[pid %d]\n", i);
#ifndef DEBUG
if (i = fork()) {
printf("[pid %d]\n", i);
@@
-153,7
+162,8
@@
main(argc,argv)
ufd = open("/etc/utmp",0);
nowtime = time((long *) 0);
while (read(ufd,&utmp,sizeof utmp)==sizeof utmp)
ufd = open("/etc/utmp",0);
nowtime = time((long *) 0);
while (read(ufd,&utmp,sizeof utmp)==sizeof utmp)
- if (utmp.ut_name[0]) {
+ if (utmp.ut_name[0] &&
+ strncmp(utmp.ut_name, IGNOREUSER, sizeof(utmp.ut_name))) {
strcpy(term, tpath);
strncat(term, utmp.ut_line, sizeof utmp.ut_line);
alarm(3);
strcpy(term, tpath);
strncat(term, utmp.ut_line, sizeof utmp.ut_line);
alarm(3);
@@
-265,17
+275,28
@@
warn(term, sdt, nowtime)
long sdt, nowtime;
{
char *ts;
long sdt, nowtime;
{
char *ts;
+ register delay = sdt - nowtime;
+
+ if (delay > 8)
+ while (delay % 5)
+ delay++;
- fprintf(term, "\007\007*** System shutdown message from %s ***\n", shutter);
+ if (shutter)
+ fprintf(term,
+ "\007\007*** System shutdown message from %s!%s ***\n",
+ sysname,shutter);
+ else
+ fprintf(term,
+ "\007\007*** System shutdown message ***\n");
ts = ctime(&sdt);
ts = ctime(&sdt);
- if (
sdt - nowtime
> 10 MINUTES)
+ if (
delay
> 10 MINUTES)
fprintf(term, "System going down at %5.5s\n", ts+11);
fprintf(term, "System going down at %5.5s\n", ts+11);
- else if (
sdt - nowtime
> 60 SECONDS ) {
+ else if (
delay
> 60 SECONDS ) {
fprintf(term, "System going down in %d minute%s\n",
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 ) {
+ (
delay+30)/60, (delay
+30)/60 != 1 ? "s" : "");
+ } else if (
delay
> 0 ) {
fprintf(term, "System going down in %d second%s\n",
fprintf(term, "System going down in %d second%s\n",
-
sdt-nowtime, sdt-nowtime
!= 1 ? "s" : "");
+
delay, delay
!= 1 ? "s" : "");
} else
fprintf(term, "System going down IMMEDIATELY\n");
}
} else
fprintf(term, "System going down IMMEDIATELY\n");
}
@@
-288,8
+309,10
@@
nolog(sdt)
if ((nologf = fopen(nologin, "w")) != NULL) {
fprintf(nologf, nolog1, (ctime(&sdt)) + 11);
if ((nologf = fopen(nologin, "w")) != NULL) {
fprintf(nologf, nolog1, (ctime(&sdt)) + 11);
+ putc('\t', nologf);
for (mess = nolog2; *mess; mess++)
for (mess = nolog2; *mess; mess++)
- fprintf(nologf, "\t%s\n", *mess);
+ fprintf(nologf, " %s", *mess);
+ putc('\n', nologf);
fclose(nologf);
}
}
fclose(nologf);
}
}
@@
-311,22
+334,34
@@
do_nothing()
* make an entry in the shutdown log
*/
* make an entry in the shutdown log
*/
-log_entry(sdt)
-time_t sdt;
+char *days[] = {
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+};
+
+char *months[] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
+ "Oct", "Nov", "Dec"
+};
+
+log_entry(now)
+time_t now;
{
{
- FILE *logf;
- char **mess;
+ register FILE *fp;
+ register char **mess;
+ struct tm *tm, *localtime();
- if ((logf = fopen(LOGFILE, "a")) == NULL)
- {
- fprintf(stderr, "*** Can't write on log file ***\n");
+ tm = localtime(&now);
+ fp = fopen(LOGFILE, "a");
+ if (fp==0)
return;
return;
- }
- f
seek(logf, 0L, 2);
-
fprintf(logf, "Shutdown by %s at %s"
,
-
shutter, ctime(&sdt)
);
+ fseek(fp, 0L, 2);
+ f
printf(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++)
for (mess = nolog2; *mess; mess++)
- fprintf(logf, "\t%s\n", *mess);
- fputc('\n', logf);
- fclose(logf);
+ fprintf(fp, " %s", *mess);
+ if (shutter)
+ fprintf(fp, " (by %s!%s)", sysname,shutter);
+ fputc('\n', fp);
+ fclose(fp);
}
}