public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 12/17] last: add --since time spec option
Date: Tue, 27 Aug 2013 19:06:14 +0100	[thread overview]
Message-ID: <1377626779-26030-12-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1377626779-26030-1-git-send-email-kerolasa@iki.fi>

The --since and --until options are companions often needed together.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 login-utils/last.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/login-utils/last.c b/login-utils/last.c
index df78436..c23469e 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -426,8 +426,9 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 	fputs(_(" -i, --ip             display IP numbers in numbers-and-dots notation\n"), out);
 	fputs(_(" -n, --limit <number> how many lines to show\n"), out);
 	fputs(_(" -R, --nohostname     don't display the hostname field\n"), out);
-	fputs(_(" -t, --until <YYYYMMDDHHMMSS>  display the state of the specified time\n"), out);
-	fputs(_(" -p, --present <YYYYMMDDHHMMSS>  display who where present at the specified time\n"), out);
+	fputs(_(" -s, --since <time>   display the lines since the specified time\n"), out);
+	fputs(_(" -t, --until <time>   display the lines until the specified time\n"), out);
+	fputs(_(" -p, --present <time> display who where present at the specified time\n"), out);
 	fputs(_(" -w, --fullnames      display full user and domain names\n"), out);
 	fputs(_(" -x, --system         display system shutdown entries and run level changes\n"), out);
 
@@ -480,7 +481,7 @@ static time_t parsetm(char *ts)
 }
 
 static void process_wtmp_file(char *ufile, int lastb, int extended,
-			      time_t until, time_t present)
+			      time_t since, time_t until, time_t present)
 {
 	FILE *fp;		/* Filepointer of wtmp file */
 
@@ -549,6 +550,9 @@ static void process_wtmp_file(char *ufile, int lastb, int extended,
 		if (uread(fp, &ut, &quit) != 1)
 			break;
 
+		if (since && ut.ut_time < since)
+			continue;
+
 		if (until && until < ut.ut_time)
 			continue;
 
@@ -734,7 +738,8 @@ int main(int argc, char **argv)
 	int lastb = 0;		/* Is this 'lastb' ? */
 	int extended = 0;	/* Lots of info. */
 
-	time_t until = 0;	/* at what time to stop parsing the file */
+	time_t since = 0;	/* at what time to start displaying the file */
+	time_t until = 0;	/* at what time to stop displaying the file */
 	time_t present = 0;	/* who where present at time_t */
 	usec_t p;
 
@@ -745,6 +750,7 @@ int main(int argc, char **argv)
 	      { "nohostname", no_argument,       NULL, 'R' },
 	      { "version",    no_argument,       NULL, 'V' },
 	      { "hostlast",   no_argument,       NULL, 'a' },
+	      { "since",      required_argument, NULL, 's' },
 	      { "until",      required_argument, NULL, 't' },
 	      { "present",    required_argument, NULL, 'p' },
 	      { "system",     no_argument,       NULL, 'x' },
@@ -761,7 +767,7 @@ int main(int argc, char **argv)
 	atexit(close_stdout);
 
 	while ((c = getopt_long(argc, argv,
-			"hVf:n:RxadFit:p:0123456789w", long_opts, NULL)) != -1) {
+			"hVf:n:RxadFit:p:s:0123456789w", long_opts, NULL)) != -1) {
 		switch(c) {
 		case 'h':
 			usage(stdout);
@@ -803,6 +809,14 @@ int main(int argc, char **argv)
 				errx(EXIT_FAILURE, _("invalid time value \"%s\""), optarg);
 			present = (time_t) (p / 1000000);
 			break;
+		case 's':
+			since = parsetm(optarg);
+			if (since != (time_t) -1)
+				break;
+			if (parse_timestamp(optarg, &p) < 0)
+				errx(EXIT_FAILURE, _("invalid time value \"%s\""), optarg);
+			since = (time_t) (p / 1000000);
+			break;
 		case 't':
 			until = parsetm(optarg);
 			if (until != (time_t) -1)
@@ -844,7 +858,7 @@ int main(int argc, char **argv)
 	}
 
 	for (i = 0; i < altc; i++) {
-		process_wtmp_file(altv[i], lastb, extended, until, present);
+		process_wtmp_file(altv[i], lastb, extended, since, until, present);
 		free(altv[i]);
 	}
 	free(altv);
-- 
1.8.4


  parent reply	other threads:[~2013-08-27 18:07 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-27 18:06 [PATCH 00/17] pull: term-utils changes with emphasis on last(1) Sami Kerola
2013-08-27 18:06 ` [PATCH 02/17] wall: send message also to sessions opened by user 'sleeper' Sami Kerola
2013-08-27 18:06 ` [PATCH 03/17] last: fix typo Sami Kerola
2013-08-27 18:06 ` [PATCH 04/17] wall: sync usage() with howto-usage-function.txt Sami Kerola
2013-08-27 18:06 ` [PATCH 05/17] mesg: " Sami Kerola
2013-08-27 18:06 ` [PATCH 06/17] wall: line wrap at column 79 also when line has tab chars Sami Kerola
2013-08-27 18:06 ` [PATCH 07/17] docs: add --present to last(1) manual page Sami Kerola
2013-08-27 18:06 ` [PATCH 08/17] docs: add note to wall(1) about sessions which will not get message Sami Kerola
2013-08-27 18:06 ` [PATCH 09/17] write: change determination can user write to a terminal Sami Kerola
2013-08-27 18:06 ` [PATCH 10/17] lib/time-util: copy time parsing functions from systemd Sami Kerola
2013-08-29 10:11   ` Karel Zak
2013-08-29 18:02     ` Sami Kerola
2013-08-27 18:06 ` [PATCH 11/17] last: parse easy to use time formats Sami Kerola
2013-08-29 10:09   ` Karel Zak
2013-08-29 18:01     ` Sami Kerola
2013-08-27 18:06 ` Sami Kerola [this message]
2013-08-27 18:06 ` [PATCH 13/17] docs: add --since and time option formats to last(1) manual Sami Kerola
2013-08-27 18:06 ` [PATCH 14/17] last: fix --present option logic error Sami Kerola
2013-08-27 18:06 ` [PATCH 15/17] last: use configuration struct Sami Kerola
2013-08-29 10:15   ` Karel Zak
2013-08-29 18:06     ` Sami Kerola
2013-09-02  9:10       ` Karel Zak
2013-08-27 18:06 ` [PATCH 16/17] last: add --time-format with iso-8601 format Sami Kerola
2013-08-27 18:06 ` [PATCH 17/17] docs: add --time-format to last(1) manual page Sami Kerola
2013-09-02  9:59 ` [PATCH 00/17] pull: term-utils changes with emphasis on last(1) Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1377626779-26030-12-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox