From: Sami Kerola Date: Mon, 26 Aug 2013 20:43:05 +0000 (+0100) Subject: last: parse easy to use time formats X-Git-Tag: v2.24-rc1~315 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a4ae395a4065bfa9df29faa022f056e4217c3d8;p=thirdparty%2Futil-linux.git last: parse easy to use time formats Signed-off-by: Sami Kerola --- diff --git a/login-utils/Makemodule.am b/login-utils/Makemodule.am index 8d65cc5835..d382ccca5c 100644 --- a/login-utils/Makemodule.am +++ b/login-utils/Makemodule.am @@ -5,6 +5,7 @@ dist_man_MANS += \ login-utils/last.1 \ login-utils/lastb.1 last_SOURCES = login-utils/last.c lib/strutils.c +last_LDADD = $(LDADD) libcommon.la install-exec-hook-last: cd $(DESTDIR)$(usrsbin_execdir) && ln -sf last lastb diff --git a/login-utils/last.c b/login-utils/last.c index 336703874e..df784361d0 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -47,6 +47,7 @@ #include "closestream.h" #include "carefulputc.h" #include "strutils.h" +#include "time-util.h" #ifndef SHUTDOWN_TIME # define SHUTDOWN_TIME 254 @@ -735,6 +736,7 @@ int main(int argc, char **argv) time_t until = 0; /* at what time to stop parsing the file */ time_t present = 0; /* who where present at time_t */ + usec_t p; static const struct option long_opts[] = { { "limit", required_argument, NULL, 'n' }, @@ -795,13 +797,19 @@ int main(int argc, char **argv) break; case 'p': present = parsetm(optarg); - if (present == (time_t) -1) + if (present != (time_t) -1) + break; + if (parse_timestamp(optarg, &p) < 0) errx(EXIT_FAILURE, _("invalid time value \"%s\""), optarg); + present = (time_t) (p / 1000000); break; case 't': until = parsetm(optarg); - if (until == (time_t) -1) + if (until != (time_t) -1) + break; + if (parse_timestamp(optarg, &p) < 0) errx(EXIT_FAILURE, _("invalid time value \"%s\""), optarg); + until = (time_t) (p / 1000000); break; case 'w': if (UT_NAMESIZE > name_len)