2 log - log the shutdown's and the halt's
4 Author: Edvard Tuinder <v892231@si.hhs.NL>
6 shutdown is logged in /usr/adm/wtmp and in /usr/adm/log (if desired)
7 halt is logged only in /usr/adm/wtmp as `halt' to prevent last from
8 reporting halt's as crashes.
12 #define _POSIX_SOURCE 1
13 #include <sys/types.h>
21 #include <sys/utsname.h>
24 static char WTMP
[] = "/usr/adm/wtmp"; /* Record of logins and logouts. */
25 static char SHUT_LOG
[] = "/usr/adm/log";
29 static char *month
[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
30 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
32 void write_log
_ARGS(( void ));
37 static struct utmp wtmp
;
38 static struct passwd
*pwd
;
42 struct utsname utsname
;
43 char *host
= "localhost";
48 if (uname(&utsname
) >= 0) host
= utsname
.nodename
;
50 pwd
= getpwuid(getuid());
51 if (pwd
== (struct passwd
*)0)
54 strcpy (who
,pwd
->pw_name
);
55 fd
= open(WTMP
,O_APPEND
|O_WRONLY
,1);
57 if (strcmp(prog
,"reboot"))
58 strcpy (wtmp
.ut_user
, prog
);
60 strcpy (wtmp
.ut_user
, "shutdown"); /* last ... */
61 strcpy (wtmp
.ut_id
, "~~");
62 strcpy (wtmp
.ut_line
, "~");
64 wtmp
.ut_type
= BOOT_TIME
;
66 wtmp
.ut_host
[0]= '\0';
67 write (fd
, (char *) &wtmp
,sizeof(struct utmp
));
70 fd
= open(SHUT_LOG
,O_APPEND
|O_WRONLY
,1);
74 sprintf (mes
,"%s %02d %02d:%02d:%02d %s: system %s by %s@%s\n",
75 month
[tm
->tm_mon
],tm
->tm_mday
,tm
->tm_hour
,tm
->tm_min
,tm
->tm_sec
,
77 write (fd
,mes
,strlen(mes
));