[PATCH 11/17] last: parse easy to use time formats

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 login-utils/Makemodule.am |  1 +
 login-utils/last.c        | 12 ++++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/login-utils/Makemodule.am b/login-utils/Makemodule.am
index 8d65cc5..d382ccc 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 3367038..df78436 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)
-- 
1.8.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux