diff options
author | grog <grog@FreeBSD.org> | 1999-05-02 08:00:30 +0000 |
---|---|---|
committer | grog <grog@FreeBSD.org> | 1999-05-02 08:00:30 +0000 |
commit | 505f21361b81f16c72bf6e4b57e66f18f7bf6445 (patch) | |
tree | c14948a865268f9a4865cd5fcd1fe883f189aa51 /sbin | |
parent | e77a9a45833ec90fb5797aaa4cc55a616a88cf9d (diff) | |
download | FreeBSD-src-505f21361b81f16c72bf6e4b57e66f18f7bf6445.zip FreeBSD-src-505f21361b81f16c72bf6e4b57e66f18f7bf6445.tar.gz |
Maintain a log file, by default /var/log/vinum.history, showing what
has been done. This name can be overridden by the value of the
VINUM_HISTORY environment variable.
Print dates in log file according to the variable VINUM_DATEFORMAT, by
default %e %b %Y %H:%M:%S.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/vinum/v.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/sbin/vinum/v.c b/sbin/vinum/v.c index 2c16b18..4e92c4f 100644 --- a/sbin/vinum/v.c +++ b/sbin/vinum/v.c @@ -63,6 +63,10 @@ #include <sys/resource.h> FILE *cf; /* config file handle */ +FILE *history; /* history file */ +char *historyfile; /* and its name */ + +char *dateformat; /* format in which to store date */ char buffer[BUFSIZE]; /* buffer to read in to */ @@ -135,6 +139,23 @@ main(int argc, char *argv[], char *envp[]) } #endif + dateformat = getenv("VINUM_DATEFORMAT"); + if (dateformat == NULL) + dateformat = "%e %b %Y %H:%M:%S"; + historyfile = getenv("VINUM_HISTORY"); + if (historyfile == NULL) + historyfile = DEFAULT_HISTORYFILE; + history = fopen(historyfile, "a+"); + if (history != NULL) { + timestamp(); + fprintf(history, "*** " VINUMMOD " started ***\n"); + fflush(history); /* before we start the daemon */ + } else + fprintf(stderr, + "Can't open history file %s: %s (%d)\n", + historyfile, + strerror(errno), + errno); superdev = open(VINUM_SUPERDEV_NAME, O_RDWR); /* open vinum superdevice */ if (superdev < 0) { /* no go */ if (errno == ENODEV) { /* not configured, */ @@ -205,6 +226,8 @@ main(int argc, char *argv[], char *envp[]) if (tokens) parseline(tokens, token); /* and do what he says */ } + if (history) + fflush(history); } } return 0; /* normal completion */ @@ -268,6 +291,12 @@ parseline(int args, char *argv[]) int j; enum keyword command; /* command to execute */ + if (history != NULL) { /* save the command to history file */ + timestamp(); + for (i = 0; i < args; i++) /* all args */ + fprintf(history, "%s ", argv[i]); + fputs("\n", history); + } if ((args == 0) /* empty line */ ||(*argv[0] == '#')) /* or a comment, */ return; @@ -418,6 +447,10 @@ make_devices(void) perror(VINUMMOD ": Can't write to /dev"); return; } + if (history) { + timestamp(); + fprintf(history, "*** Created devices ***\n"); + } if (superdev >= 0) /* super device open */ close(superdev); @@ -712,3 +745,24 @@ start_daemon(void) } else if (pid < 0) /* couldn't fork */ printf("Can't fork to check daemon\n"); } + +void +timestamp() +{ + struct timeval now; + struct tm *date; + char datetext[MAXDATETEXT]; + + if (history != NULL) { + if (gettimeofday(&now, NULL) != 0) { + fprintf(stderr, "Can't get time: %s\n", strerror(errno)); + return; + } + date = localtime(&(time_t) now.tv_sec); + strftime(datetext, MAXDATETEXT, dateformat, date), + fprintf(history, + "%s.%06ld ", + datetext, + now.tv_usec); + } +} |