Commit cb096341 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Fix up genlastlog to avoid Y2K like problems. Basically, syslog does

not include a year in the output, so I was using the current year to
init the tm structure. However, the log file could span from the old
year to the new year, and so all the dates could be wrong. Using Mac's
suggestion, look at the final time stamp, and if its in the future,
reset it back one year.

Also add [-a #] option to roll through the specified number of
rotation files, to make the job of reinitting all the records easier.
I ran it as "genlastlog -a 7", which makes it process logins.7.gz
through logins.0.gz, before doing the current log.
parent 7523a98c
......@@ -76,7 +76,7 @@ static int deadfl;
static void
fprintf(stderr, "Usage: %s\n", progname);
fprintf(stderr, "Usage: %s [-a]\n", progname);
......@@ -93,11 +93,26 @@ main(int argc, char **argv)
gzFile *infp;
char buf[BUFSIZ], *bp;
struct hostent *he;
int errors = 0;
int ch, errors = 0;
int backcount = 0;
progname = argv[0];
if (argc != 1)
while ((ch = getopt(argc, argv, "a:")) != -1)
switch(ch) {
case 'a':
backcount = atoi(optarg);
case 'h':
case '?':
argc -= optind;
argv += optind;
if (argc)
openlog("genlastlog", LOG_PID, LOG_USER);
......@@ -116,7 +131,8 @@ main(int argc, char **argv)
if (bp = strchr(opshostname, '.'))
*bp = 0;
sprintf(buf, "%s/%s.0.gz", USERSVAR, LOGINS);
while (backcount) {
sprintf(buf, "%s/%s.%d.gz", USERSVAR, LOGINS, backcount);
* Use setjmp and timer to prevent NFS lockup.
......@@ -133,7 +149,9 @@ main(int argc, char **argv)
sprintf(buf, "%s/%s", USERSVAR, LOGINS);
......@@ -194,6 +212,17 @@ doit(gzFile *infp)
ll_time = mktime(&tm);
* If the constructed time is in the future, then we have
* year off by one (cause we are possibly looking at files
* created in the previous year). Set the year back by one,
* and redo.
if (ll_time > curtime) {
ll_time = mktime(&tm);
* Scanf the next part, which looks like:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment