=== modified file 'Makefile' --- Makefile 2004-03-01 20:56:13 +0000 +++ Makefile 2012-10-29 19:18:18 +0000 @@ -1,11 +1,12 @@ CFLAGS=-fomit-frame-pointer -O2 -s -g -Wall timeoutd: timeoutd.c Makefile - #$(CC) $(CFLAGS) -o timeoutd timeoutd.c $(CC) $(CFLAGS) -o timeoutd.o -c timeoutd.c -DTIMEOUTDX11 $(CC) $(CFLAGS) -o timeoutd -L/usr/X11R6/lib timeoutd.o -lXss -lXext - - -install: - install -o root -g system -m 2111 timeoutd /usr/etc/timeoutd - install -o man -g info -m 444 timeoutd.8 /usr/man/man8 - install -o man -g info -m 444 timeouts.5 /usr/man/man5 + +install: timeoutd + install -o root -g root -m 2111 timeoutd /usr/bin/timeoutd + install -o man -g root -m 444 timeoutd.8 /usr/share/man/man8 + install -o man -g root -m 444 timeouts.5 /usr/share/man/man5 + +clean: + rm timeoutd timeoutd.o === modified file 'timeoutd.c' --- timeoutd.c 2009-01-04 23:17:57 +0000 +++ timeoutd.c 2012-10-29 19:18:18 +0000 @@ -302,10 +302,16 @@ strncpy(dev, argv[2], sizeof(dev) - 1); dev[sizeof(dev) - 1] = '\0'; time_now = time((time_t *)0); /* get current time */ + if(time_now == ((time_t) -1)) { + openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON); + syslog(SYSLOG_DEBUG, "Cannot get time, fatal"); + closelog(); + return 1; + } now = *(localtime(&time_now)); /* Break it into bits */ now_hhmm = now.tm_hour * 100 + now.tm_min; allow_reread = 0; - read_wtmp(); /* Read in today's wtmp entries */ + read_wtmp(time_now / (24*3600)); /* Read in today's wtmp entries */ switch(chk_timeout(argv[1], dev, "", 0, 0)) { case DAYMAX: @@ -387,17 +393,17 @@ syslog(SYSLOG_DEBUG, "Finished checking utmp... sleeping for 1 minute."); closelog(); #endif - sleep(60); + int nap=60; + sleep(nap); } } /* Read in today's wtmp entries */ -void read_wtmp() +void read_wtmp(time_t since) { FILE *fp; struct utmp ut; - struct tm *tm; #ifdef DEBUG openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON); @@ -418,10 +424,8 @@ while (fread(&ut, sizeof(struct utmp), 1, fp) == 1) { - tm = localtime(&ut.ut_time); - - if (tm->tm_year != now.tm_year || tm->tm_yday != now.tm_yday) - break; + if(ut.ut_tv.tv_sec < since) + continue; #ifndef SUNOS if (ut.ut_type == USER_PROCESS || @@ -1231,9 +1235,8 @@ #ifdef DEBUG openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON); - syslog(LOG_NOTICE, "Would normally kill pid %d user %s on %s",pid,user,dev); + syslog(LOG_NOTICE, "Killing pid %d user %s on %s",pid,user,dev); closelog(); - return; #endif if (fork()) /* the parent process */