Filewatcher File Search
FTP Search
  
Directory (beta)
  
Content Search (beta)
   
pkg://SysVinit-2.85-4.2.src.rpm:118594/sysvinit-2.84-lasttime.patch  info  downloads

diff -ru sysvinit-2.79/man/last.1 sysvinit-2.79.new/man/last.1
--- sysvinit-2.79/man/last.1	Thu Jul 29 06:50:34 1999
+++ sysvinit-2.79.new/man/last.1	Thu Nov 29 09:20:17 2001
@@ -14,6 +14,7 @@
 .RB "[ \-\fBn\fP \fInum\fP ]"
 .RB [ \-adiox ]
 .RB "[ \-\fBf\fP \fIfile\fP ]"
+.RB "[ \-\fBt\fP \fIYYYYMMDDHHMMSS\fP ]"
 .RI [ name... ]
 .RI [ tty... ]
 .br
@@ -22,6 +23,7 @@
 .RB [ \-\fInum\fP ]
 .RB "[ \-\fBn\fP \fInum\fP ]"
 .RB "[ \-\fBf\fP \fIfile\fP ]"
+.RB "[ \-\fBt\fP \fIYYYYMMDDHHMMSS\fP ]"
 .RB [ \-adiox ]
 .RI [ name... ]
 .RI [ tty... ]
@@ -54,6 +56,11 @@
 This is a count telling \fBlast\fP how many lines to show.
 .IP "\fB\-n\fP \fInum\fP"
 The same.
+.IP "\fB\-t\fP \fIYYYYMMDDHHMMSS\fP"
+Display the state of logins as of the specified time.  This is
+useful, e.g., to determine easily who was logged in at a particular
+time -- specify that time with \fB\-t\fP and look for "still logged
+in".
 .IP \fB\-R\fP
 Suppresses the display of the hostname field.
 .IP \fB\-a\fP
diff -ru sysvinit-2.79/src/last.c sysvinit-2.79.new/src/last.c
--- sysvinit-2.79/src/last.c	Wed Jun 13 08:13:21 2001
+++ sysvinit-2.79.new/src/last.c	Thu Nov 29 09:31:45 2001
@@ -471,7 +471,7 @@
  */
 void usage(char *s)
 {
-	fprintf(stderr, "Usage: %s [-num | -n num] [-f file] "
+	fprintf(stderr, "Usage: %s [-num | -n num] [-f file] [-t YYYYMMDDHHMMSS] "
 			"[-R] [-x] [-o] [username..] [tty..]\n", s);
 	exit(1);
 }
@@ -499,10 +499,12 @@
   int extended = 0;	/* Lots of info. */
   char *altufile = NULL;/* Alternate wtmp */
 
+  time_t until = 0;     /* at what time to stop parsing the file */
+
   progname = mybasename(argv[0]);
 
   /* Process the arguments. */
-  while((c = getopt(argc, argv, "f:n:Rxadio0123456789")) != EOF)
+  while((c = getopt(argc, argv, "f:n:Rxadio0123456789t:")) != EOF)
     switch(c) {
 	case 'R':
 		showhost = 0;
@@ -537,6 +539,47 @@
 	case '5': case '6': case '7': case '8': case '9':
 		maxrecs = 10*maxrecs + c - '0';
 		break;
+	case 't': {
+		struct tm u = {0}, origu;
+
+		/* YYYYMMDDHHMMSS */
+		if (sscanf(optarg, "%4d%2d%2d%2d%2d%2d", &u.tm_year,
+			   &u.tm_mon, &u.tm_mday, &u.tm_hour, &u.tm_min,
+			   &u.tm_sec) != 6) {
+			usage(progname);
+			/*NOTREACHED*/
+		}
+
+		u.tm_year -= 1900;
+		u.tm_mon -= 1;
+		u.tm_isdst = -1;
+
+		origu = u;
+
+		until = mktime(&u);
+		if (until == (time_t)-1) {
+		badtime:
+			fprintf(stderr, "%s: Invalid time value \"%s\"\n",
+				progname, optarg);
+			usage(progname);
+			/*NOTREACHED*/
+		}
+
+		/* Unfortunately mktime() is much more forgiving than
+		   it should be.  For example, it'll gladly accept
+		   "30" as a valid month number.  This behavior is by
+		   design, but we don't like it, so we want to detect
+		   it and complain. */
+		if ((u.tm_year != origu.tm_year) ||
+		    (u.tm_mon != origu.tm_mon) ||
+		    (u.tm_mday != origu.tm_mday) ||
+		    (u.tm_hour != origu.tm_hour) ||
+		    (u.tm_min != origu.tm_min) ||
+		    (u.tm_sec != origu.tm_sec))
+			goto badtime;
+
+		break;
+	}
 	default:
 		usage(progname);
 		break;
@@ -631,6 +674,9 @@
 	if (uread(fp, &ut, &quit) != 1)
 		break;
 
+	if (until && until < ut.ut_time)
+		continue;
+
 	if (memcmp(&ut, &oldut, sizeof(struct utmp)) == 0) continue;
 	memcpy(&oldut, &ut, sizeof(struct utmp));
 	lastdate = ut.ut_time;
Results 1 - 1
Help - FTP Sites List - Software Dir.
Searching half a billion files worldwide
© 1997-2008 Oliver Maruhn