minix/commands/reboot/log.c

78 lines
1.8 KiB
C
Raw Normal View History

2005-04-21 16:53:53 +02:00
/*
log - log the shutdown's and the halt's
Author: Edvard Tuinder <v892231@si.hhs.NL>
shutdown is logged in /usr/adm/wtmp and in /usr/adm/log (if desired)
halt is logged only in /usr/adm/wtmp as `halt' to prevent last from
reporting halt's as crashes.
*/
#define _POSIX_SOURCE 1
#include <sys/types.h>
#include <stdio.h>
#include <utmp.h>
#include <pwd.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <sys/utsname.h>
static char SHUT_LOG[] = "/usr/adm/log";
char who[8];
extern char *prog;
static char *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
void write_log(char *wtmpfile)
2005-04-21 16:53:53 +02:00
{
int fd;
static struct utmp wtmp;
static struct passwd *pwd;
char mes[90];
struct tm *tm;
time_t now;
struct utsname utsname;
char *host = "localhost";
time(&now);
tm = localtime(&now);
if (uname(&utsname) >= 0) host = utsname.nodename;
pwd = getpwuid(getuid());
if (pwd == (struct passwd *)0)
strcpy (who,"root");
else
strcpy (who,pwd->pw_name);
fd = open(wtmpfile,O_APPEND|O_WRONLY|O_CREAT,1);
2005-04-21 16:53:53 +02:00
if (fd) {
if (strcmp(prog,"reboot"))
Build NetBSD libc library in world in ELF mode. 3 sets of libraries are built now: . ack: all libraries that ack can compile (/usr/lib/i386/) . clang+elf: all libraries with minix headers (/usr/lib/) . clang+elf: all libraries with netbsd headers (/usr/netbsd/) Once everything can be compiled with netbsd libraries and headers, the /usr/netbsd hierarchy will be obsolete and its libraries compiled with netbsd headers will be installed in /usr/lib, and its headers in /usr/include. (i.e. minix libc and current minix headers set will be gone.) To use the NetBSD libc system (libraries + headers) before it is the default libc, see: http://wiki.minix3.org/en/DevelopersGuide/UsingNetBSDCode This wiki page also documents the maintenance of the patch files of minix-specific changes to imported NetBSD code. Changes in this commit: . libsys: Add NBSD compilation and create a safe NBSD-based libc. . Port rest of libraries (except libddekit) to new header system. . Enable compilation of libddekit with new headers. . Enable kernel compilation with new headers. . Enable drivers compilation with new headers. . Port legacy commands to new headers and libc. . Port servers to new headers. . Add <sys/sigcontext.h> in compat library. . Remove dependency file in tree. . Enable compilation of common/lib/libc/atomic in libsys . Do not generate RCSID strings in libc. . Temporarily disable zoneinfo as they are incompatible with NetBSD format . obj-nbsd for .gitignore . Procfs: use only integer arithmetic. (Antoine Leca) . Increase ramdisk size to create NBSD-based images. . Remove INCSYMLINKS handling hack. . Add nbsd_include/sys/exec_elf.h . Enable ELF compilation with NBSD libc. . Add 'make nbsdsrc' in tools to download reference NetBSD sources. . Automate minix-port.patch creation. . Avoid using fstavfs() as it is *extremely* slow and unneeded. . Set err() as PRIVATE to avoid name clash with libc. . [NBSD] servers/vm: remove compilation warnings. . u32 is not a long in NBSD headers. . UPDATING info on netbsd hierarchy . commands fixes for netbsd libc
2011-04-27 15:00:52 +02:00
strcpy (wtmp.ut_name, prog);
2005-04-21 16:53:53 +02:00
else
Build NetBSD libc library in world in ELF mode. 3 sets of libraries are built now: . ack: all libraries that ack can compile (/usr/lib/i386/) . clang+elf: all libraries with minix headers (/usr/lib/) . clang+elf: all libraries with netbsd headers (/usr/netbsd/) Once everything can be compiled with netbsd libraries and headers, the /usr/netbsd hierarchy will be obsolete and its libraries compiled with netbsd headers will be installed in /usr/lib, and its headers in /usr/include. (i.e. minix libc and current minix headers set will be gone.) To use the NetBSD libc system (libraries + headers) before it is the default libc, see: http://wiki.minix3.org/en/DevelopersGuide/UsingNetBSDCode This wiki page also documents the maintenance of the patch files of minix-specific changes to imported NetBSD code. Changes in this commit: . libsys: Add NBSD compilation and create a safe NBSD-based libc. . Port rest of libraries (except libddekit) to new header system. . Enable compilation of libddekit with new headers. . Enable kernel compilation with new headers. . Enable drivers compilation with new headers. . Port legacy commands to new headers and libc. . Port servers to new headers. . Add <sys/sigcontext.h> in compat library. . Remove dependency file in tree. . Enable compilation of common/lib/libc/atomic in libsys . Do not generate RCSID strings in libc. . Temporarily disable zoneinfo as they are incompatible with NetBSD format . obj-nbsd for .gitignore . Procfs: use only integer arithmetic. (Antoine Leca) . Increase ramdisk size to create NBSD-based images. . Remove INCSYMLINKS handling hack. . Add nbsd_include/sys/exec_elf.h . Enable ELF compilation with NBSD libc. . Add 'make nbsdsrc' in tools to download reference NetBSD sources. . Automate minix-port.patch creation. . Avoid using fstavfs() as it is *extremely* slow and unneeded. . Set err() as PRIVATE to avoid name clash with libc. . [NBSD] servers/vm: remove compilation warnings. . u32 is not a long in NBSD headers. . UPDATING info on netbsd hierarchy . commands fixes for netbsd libc
2011-04-27 15:00:52 +02:00
strcpy (wtmp.ut_name, "shutdown"); /* last ... */
2005-04-21 16:53:53 +02:00
strcpy (wtmp.ut_id, "~~");
strcpy (wtmp.ut_line, "~");
wtmp.ut_pid = 0;
wtmp.ut_type = BOOT_TIME;
wtmp.ut_time = now;
wtmp.ut_host[0]= '\0';
write (fd, (char *) &wtmp,sizeof(struct utmp));
close(fd);
}
fd = open(SHUT_LOG,O_APPEND|O_WRONLY,1);
if (!fd)
perror ("open");
else {
sprintf (mes,"%s %02d %02d:%02d:%02d %s: system %s by %s@%s\n",
month[tm->tm_mon],tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
prog,prog,who,host);
write (fd,mes,strlen(mes));
close(fd);
}
return;
}