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.
This commit is contained in:
Greg Lehey 1999-05-02 08:00:30 +00:00
parent 417f97c954
commit 1976254102
1 changed files with 54 additions and 0 deletions

View File

@ -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);
}
}