]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
last: parse easy to use time formats
authorSami Kerola <kerolasa@iki.fi>
Mon, 26 Aug 2013 20:43:05 +0000 (21:43 +0100)
committerSami Kerola <kerolasa@iki.fi>
Thu, 29 Aug 2013 17:14:08 +0000 (18:14 +0100)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/Makemodule.am
login-utils/last.c

index 8d65cc58358b9adc41536262c1f1987b88c0e601..d382ccca5cd6169947c19e0be60d787fac09d3bd 100644 (file)
@@ -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
index 336703874e05f3a099a3960aa912eb33efc4deb7..df784361d04a5ebbc89bb540dcabfede6a536fa0 100644 (file)
@@ -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)