Skip to contentSkip to conversation

pull: utmpdump iso-8601 format

PATCH Applied Sami Kerola 2 participants 13 messages Jun 20, 2016 – Jul 1, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover pull: utmpdump iso-8601 format

Hello.

This pull request is re-implementation of iso-8601 timestamp format in textual output using timeutils Karel made available as libcommon timeutils functions. The earlier submission was based on my version of timeutils, that were not merged.

----------------------------------------------------------------
The following changes since commit 7f787ced5d401ccd56a82bb2b1202f1ea7164783:
libblkid: don't check nonnull attributes for NULL [-Wnonnull-compare] (2016-06-14 14:39:16 +0200)
are available in the git repository at:
git://github.com/kerolasa/lelux-utiliteetit.git utmpdump
for you to fetch changes up to 9997c0b13fffe7d198e7d056e4279727c2b0b3ad:
tests: utmpdump add subsecond accuracy test (2016-06-20 21:31:18 +0100)
----------------------------------------------------------------

Sami Kerola (6):
utmpdump: use always UTC-0 timezone in textual output
libcommon: add ISO_8601_GMTIME that will print UTC-0 timestamps
utmpdump: use iso-8601 timestamp format with subsecond accuracy
tests: fix utmpdump timestamps to be in iso format
tests: remove utmpdump localization go-around
tests: utmpdump add subsecond accuracy test

 include/timeutils.h                     |  3 +-
 lib/timeutils.c                         | 14 ++++++--
 login-utils/Makemodule.am               |  1 +
 login-utils/utmpdump.c                  | 63 +++++++++++++++++++--------------
 tests/expected/utmp/utmpdump-subsecond  |  5 +++
 tests/expected/utmp/utmpdump-totxt      | 20 +++++------
 tests/expected/utmp/utmpdump-totxt-ipv6 |  4 +--
 tests/ts/utmp/subsec                    |  3 ++
 tests/ts/utmp/txt-a                     | 38 ++++++++++----------
 tests/ts/utmp/txt-a-old                 | 19 ++++++++++
 tests/ts/utmp/txt-b                     | 20 +++++------
 tests/ts/utmp/txt-b-old                 | 10 ++++++
 tests/ts/utmp/txt-ipv6                  |  4 +--
 tests/ts/utmp/txt-ipv6-old              |  2 ++
 tests/ts/utmp/utmpdump-circle           | 10 ++++--
 tests/ts/utmp/utmpdump-subsecond        | 34 ++++++++++++++++++
 tests/ts/utmp/utmpdump-tobin            |  2 --
 tests/ts/utmp/utmpdump-tobin-ipv6       |  2 --
 tests/ts/utmp/utmpdump-totxt            |  2 --
 tests/ts/utmp/utmpdump-totxt-ipv6       |  2 --
 20 files changed, 175 insertions(+), 83 deletions(-)
 create mode 100644 tests/expected/utmp/utmpdump-subsecond
 create mode 100644 tests/ts/utmp/subsec
 create mode 100644 tests/ts/utmp/txt-a-old
 create mode 100644 tests/ts/utmp/txt-b-old
 create mode 100644 tests/ts/utmp/txt-ipv6-old
 create mode 100755 tests/ts/utmp/utmpdump-subsecond
Signature · 1 line
2.9.0
#1 lore raw

PATCH 1/6 utmpdump: use always UTC-0 timezone in textual output

Converting a time structure from text format that has timezone markup is practically impossible. See reference links for more information. This leads to situation where multiple utmpdump(1) conversions from binary to text and back make timestamps to shift amount of timezone offset to UTC-0.

The easiest way to make multiple conversions to work without timeshifts is to always use UTC-0 timezone. Downside of this approach is that the textual format is less human readable than local timestamps would be.

Reference: http://www.catb.org/esr/time-programming/#_strptime_3_and_getdate_3
Reference: http://man7.org/linux/man-pages/man3/strptime.3.html

---
 login-utils/utmpdump.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
login-utils/utmpdump.c +3 -3
index 03cf4a9..6eaf202 100644
@@ -47,10 +47,10 @@
 
 static char *timetostr(const time_t time)
 {
-	static char s[29];	/* [Sun Sep 01 00:00:00 1998 PST] */
+	static char s[29];	/* [Tue Sep 01 00:00:00 1998 GMT] */
 	struct tm *tmp;
 
-	if (time != 0 && (tmp = localtime(&time)))
+	if (time != 0 && (tmp = gmtime(&time)))
 		strftime(s, 29, "%a %b %d %T %Y %Z", tmp);
 	else
 		s[0] = '\0';
@@ -73,7 +73,7 @@ static time_t strtotime(const char *s_time)
 	if (s_time[26] == 'D')
 		tm.tm_isdst = 1;
 
-	return mktime(&tm);
+	return timegm(&tm);
 }
 
 #define cleanse(x) xcleanse(x, sizeof(x))
Signature · 1 line
2.9.0
#3 lore raw

PATCH 2/6 libcommon: add ISO_8601_GMTIME that will print UTC-0 timestamps

In reply to Sami Kerola

When timestamps are intented to be conversable back from string to binary it is best to stick with UTC-0 timezone. This is needed in utmpdump(1).

---
 include/timeutils.h |  3 ++-
 lib/timeutils.c     | 14 ++++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)
include/timeutils.h +2 -1
index 265577f..00d1820 100644
@@ -61,7 +61,8 @@ enum {
 	ISO_8601_DOTUSEC	= (1 << 3),
 	ISO_8601_COMMAUSEC	= (1 << 4),
 	ISO_8601_TIMEZONE	= (1 << 5),
-	ISO_8601_SPACE		= (1 << 6)
+	ISO_8601_SPACE		= (1 << 6),
+	ISO_8601_GMTIME		= (1 << 7)
 };
 
 #define ISO_8601_BUFSIZ	32
lib/timeutils.c +12 -2
index 25a163e..fd9aa3e 100644
@@ -396,7 +396,12 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
 /* timeval to ISO 8601 */
 int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz)
 {
-	struct tm tm = *localtime(&tv->tv_sec);
+	struct tm tm;
+
+	if (flags & ISO_8601_GMTIME)
+		tm = *gmtime(&tv->tv_sec);
+	else
+		tm = *localtime(&tv->tv_sec);
 	return format_iso_time(&tm, tv->tv_usec, flags, buf, bufsz);
 }
 
@@ -409,7 +414,12 @@ int strtm_iso(struct tm *tm, int flags, char *buf, size_t bufsz)
 /* time_t to ISO 8601 */
 int strtime_iso(const time_t *t, int flags, char *buf, size_t bufsz)
 {
-	struct tm tm = *localtime(t);
+	struct tm tm;
+
+	if (flags & ISO_8601_GMTIME)
+		tm = *gmtime(t);
+	else
+		tm = *localtime(t);
 	return format_iso_time(&tm, 0, flags, buf, bufsz);
 }
 
Signature · 1 line
2.9.0
#4 lore raw

PATCH 3/6 utmpdump: use iso-8601 timestamp format with subsecond accuracy

In reply to Sami Kerola

Newer 'struct utmp' is using 'struct timeval' to represent login and logout times, so include the maximum accuracy to textual utmp format. Notice that this change does not remove support of converting earlier textual formats back to binary. But conversions from binary to former format will no longer be available.

---
 login-utils/Makemodule.am |  1 +
 login-utils/utmpdump.c    | 63 ++++++++++++++++++++++++++++-------------------
 2 files changed, 38 insertions(+), 26 deletions(-)
login-utils/Makemodule.am +1 -0
index 502ecd5..be07ace 100644
@@ -67,6 +67,7 @@ if BUILD_UTMPDUMP
 usrbin_exec_PROGRAMS += utmpdump
 dist_man_MANS += login-utils/utmpdump.1
 utmpdump_SOURCES = login-utils/utmpdump.c
+utmpdump_LDADD = $(LDADD) libcommon.la
 endif
 
 
login-utils/utmpdump.c +37 -26

106 lines not on this page · raw message

Signature · 1 line
2.9.0
#7 lore raw

PATCH 4/6 tests: fix utmpdump timestamps to be in iso format

In reply to Sami Kerola

The utmpdump-circle is slightly modified to use old timestamp format as basis of conversion and to do cyclic conversion via new format. This is better from test coverage point of view.

---
 tests/expected/utmp/utmpdump-totxt      | 20 ++++++++---------
 tests/expected/utmp/utmpdump-totxt-ipv6 |  4 ++--
 tests/ts/utmp/txt-a                     | 38 ++++++++++++++++-----------------
 tests/ts/utmp/txt-a-old                 | 19 +++++++++++++++++
 tests/ts/utmp/txt-b                     | 20 ++++++++---------
 tests/ts/utmp/txt-b-old                 | 10 +++++++++
 tests/ts/utmp/txt-ipv6                  |  4 ++--
 tests/ts/utmp/txt-ipv6-old              |  2 ++
 tests/ts/utmp/utmpdump-circle           |  8 ++++++-
 9 files changed, 81 insertions(+), 44 deletions(-)
 create mode 100644 tests/ts/utmp/txt-a-old
 create mode 100644 tests/ts/utmp/txt-b-old
 create mode 100644 tests/ts/utmp/txt-ipv6-old
tests/expected/utmp/utmpdump-totxt +10 -10
index 02fb22d..5deefde 100644
@@ -1,10 +1,10 @@
-[7] [17058] [ts/1] [kerolasa] [pts/1       ] [:0.0                ] [0.0.0.0        ] [Wed Jan 16 23:44:09 2013 GMT]
-[7] [22098] [ts/2] [kerolasa] [pts/2       ] [:0.0                ] [0.0.0.0        ] [Wed Jan 16 23:49:17 2013 GMT]
-[7] [24915] [ts/3] [kerolasa] [pts/3       ] [:0.0                ] [0.0.0.0        ] [Thu Jan 17 12:23:33 2013 GMT]
-[8] [24915] [ts/3] [kerolasa] [pts/3       ] [                    ] [0.0.0.0        ] [Thu Jan 17 12:24:49 2013 GMT]
-[7] [30629] [ts/3] [kerolasa] [pts/3       ] [:0.0                ] [0.0.0.0        ] [Thu Jan 17 13:12:39 2013 GMT]
-[8] [30629] [ts/3] [kerolasa] [pts/3       ] [                    ] [0.0.0.0        ] [Thu Jan 17 13:42:19 2013 GMT]
-[8] [22098] [ts/2] [kerolasa] [pts/2       ] [                    ] [0.0.0.0        ] [Thu Jan 17 13:42:48 2013 GMT]
-[8] [17058] [ts/1] [kerolasa] [pts/1       ] [                    ] [0.0.0.0        ] [Thu Jan 17 13:42:48 2013 GMT]
-[7] [31545] [ts/1] [kerolasa] [pts/1       ] [:0.0                ] [0.0.0.0        ] [Thu Jan 17 20:17:21 2013 GMT]
-[7] [28496] [ts/2] [kerolasa] [pts/2       ] [:0.0                ] [0.0.0.0        ] [Thu Jan 17 21:09:39 2013 GMT]
+[7] [17058] [ts/1] [kerolasa] [pts/1       ] [:0.0                ] [0.0.0.0        ] [2013-01-16T23:44:09,000000+0000]
+[7] [22098] [ts/2] [kerolasa] [pts/2       ] [:0.0                ] [0.0.0.0        ] [2013-01-16T23:49:17,000000+0000]
+[7] [24915] [ts/3] [kerolasa] [pts/3       ] [:0.0                ] [0.0.0.0        ] [2013-01-17T12:23:33,000000+0000]
+[8] [24915] [ts/3] [kerolasa] [pts/3       ] [                    ] [0.0.0.0        ] [2013-01-17T12:24:49,000000+0000]
+[7] [30629] [ts/3] [kerolasa] [pts/3       ] [:0.0                ] [0.0.0.0        ] [2013-01-17T13:12:39,000000+0000]
+[8] [30629] [ts/3] [kerolasa] [pts/3       ] [                    ] [0.0.0.0        ] [2013-01-17T13:42:19,000000+0000]
+[8] [22098] [ts/2] [kerolasa] [pts/2       ] [                    ] [0.0.0.0        ] [2013-01-17T13:42:48,000000+0000]
+[8] [17058] [ts/1] [kerolasa] [pts/1       ] [                    ] [0.0.0.0        ] [2013-01-17T13:42:48,000000+0000]
+[7] [31545] [ts/1] [kerolasa] [pts/1       ] [:0.0                ] [0.0.0.0        ] [2013-01-17T20:17:21,000000+0000]
+[7] [28496] [ts/2] [kerolasa] [pts/2       ] [:0.0                ] [0.0.0.0        ] [2013-01-17T21:09:39,000000+0000]
tests/expected/utmp/utmpdump-totxt-ipv6 +2 -2
index 5cce150..5894144 100644
@@ -1,2 +1,2 @@
-[7] [00010] [ipv6] [IPv6    ] [root        ] [dns-server          ] [2001:503:ba3e::2:30] [Wed Aug 28 20:30:40 2013 GMT]
-[8] [00011] [ipv6] [IPv6    ] [root        ] [dns-server          ] [2001:503:ba3e::2:30] [Wed Aug 28 20:40:50 2013 GMT]
+[7] [00010] [ipv6] [IPv6    ] [root        ] [dns-server          ] [2001:503:ba3e::2:30] [2013-08-28T20:30:40,000000+0000]
+[8] [00011] [ipv6] [IPv6    ] [root        ] [dns-server          ] [2001:503:ba3e::2:30] [2013-08-28T20:40:50,000000+0000]
tests/ts/utmp/txt-a +19 -19
index bc91d19..8501daa 100644
@@ -1,19 +1,19 @@
-[9] [00009] [ts/9] [accounting] [foo         ] [nine                ] [0.0.0.0        ] [Wed Aug 28 03:00:00 2013 GMT]
-[8] [00008] [ts/8] [dead_process] [foo         ] [eight               ] [0.0.0.0        ] [Wed Aug 28 04:00:00 2013 GMT]
-[7] [00007] [ts/7] [user_process] [foo         ] [seven               ] [0.0.0.0        ] [Wed Aug 28 05:00:00 2013 GMT]
-[6] [00006] [ts/6] [login   ] [foo         ] [six                 ] [0.0.0.0        ] [Wed Aug 28 06:00:00 2013 GMT]
-[5] [00005] [ts/5] [init    ] [foo         ] [five                ] [0.0.0.0        ] [Wed Aug 28 07:00:00 2013 GMT]
-[4] [00004] [ts/4] [oldtime ] [foo         ] [four                ] [0.0.0.0        ] [Wed Aug 28 08:00:00 2013 GMT]
-[3] [00003] [ts/3] [newtime ] [foo         ] [three               ] [0.0.0.0        ] [Wed Aug 28 09:00:00 2013 GMT]
-[2] [00002] [ts/2] [sysboot ] [foo         ] [two                 ] [0.0.0.0        ] [Wed Aug 28 10:00:00 2013 GMT]
-[1] [00001] [ts/1] [runlevel] [foo         ] [one                 ] [0.0.0.0        ] [Wed Aug 28 11:00:00 2013 GMT]
-[0] [00000] [ts/0] [nonvalid] [foo         ] [zero                ] [0.0.0.0        ] [Wed Aug 28 12:00:00 2013 GMT]
-[7] [00010] [ipv4] [IPv4    ] [root        ] [dns-server          ] [198.41.0.4     ] [Wed Aug 28 13:00:00 2013 GMT]
-[8] [00011] [ipv4] [IPv4    ] [root        ] [dns-server          ] [198.41.0.4     ] [Wed Aug 28 14:00:00 2013 GMT]
-[1] [00012] [~~  ] [shutdown] [~           ] [system-name         ] [0.0.0.0        ] [Wed Aug 28 15:00:00 2013 GMT]
-[2] [00012] [~~  ] [reboot  ] [~           ] [system-name         ] [0.0.0.0        ] [Wed Aug 28 16:00:00 2013 GMT]
-[1] [00012] [~~  ] [shutdown] [~           ] [system-name         ] [0.0.0.0        ] [Wed Aug 28 17:00:00 2013 GMT]
-[2] [00012] [~~  ] [reboot  ] [~           ] [system-name         ] [0.0.0.0        ] [Wed Aug 28 18:00:00 2013 GMT]
-[7] [00013] [ts/1] [torvalds] [linux       ] [hobby               ] [128.214.205.14 ] [Mon Aug 26 00:57:08 1991 GMT]
-[7] [00014] [long] [rick    ] [long        ] [never-gonna-logout  ] [0.0.0.0        ] [                            ]
-[8] [00014] [long] [rick    ] [long        ] [never-gonna-logout  ] [0.0.0.0        ] [Tue Jan 19 03:14:07 2038 GMT]
+[9] [00009] [ts/9] [accounting] [foo         ] [nine                ] [0.0.0.0        ] [2013-08-28T03:00:00,000000+0000]
+[8] [00008] [ts/8] [dead_process] [foo         ] [eight               ] [0.0.0.0        ] [2013-08-28T04:00:00,000000+0000]
+[7] [00007] [ts/7] [user_process] [foo         ] [seven               ] [0.0.0.0        ] [2013-08-28T05:00:00,000000+0000]
+[6] [00006] [ts/6] [login   ] [foo         ] [six                 ] [0.0.0.0        ] [2013-08-28T06:00:00,000000+0000]
+[5] [00005] [ts/5] [init    ] [foo         ] [five                ] [0.0.0.0        ] [2013-08-28T07:00:00,000000+0000]
+[4] [00004] [ts/4] [oldtime ] [foo         ] [four                ] [0.0.0.0        ] [2013-08-28T08:00:00,000000+0000]
+[3] [00003] [ts/3] [newtime ] [foo         ] [three               ] [0.0.0.0        ] [2013-08-28T09:00:00,000000+0000]
+[2] [00002] [ts/2] [sysboot ] [foo         ] [two                 ] [0.0.0.0        ] [2013-08-28T10:00:00,000000+0000]
+[1] [00001] [ts/1] [runlevel] [foo         ] [one                 ] [0.0.0.0        ] [2013-08-28T11:00:00,000000+0000]
+[0] [00000] [ts/0] [nonvalid] [foo         ] [zero                ] [0.0.0.0        ] [2013-08-28T12:00:00,000000+0000]
+[7] [00010] [ipv4] [IPv4    ] [root        ] [dns-server          ] [198.41.0.4     ] [2013-08-28T13:00:00,000000+0000]
+[8] [00011] [ipv4] [IPv4    ] [root        ] [dns-server          ] [198.41.0.4     ] [2013-08-28T14:00:00,000000+0000]
+[1] [00012] [~~  ] [shutdown] [~           ] [system-name         ] [0.0.0.0        ] [2013-08-28T15:00:00,000000+0000]
+[2] [00012] [~~  ] [reboot  ] [~           ] [system-name         ] [0.0.0.0        ] [2013-08-28T16:00:00,000000+0000]
+[1] [00012] [~~  ] [shutdown] [~           ] [system-name         ] [0.0.0.0        ] [2013-08-28T17:00:00,000000+0000]
+[2] [00012] [~~  ] [reboot  ] [~           ] [system-name         ] [0.0.0.0        ] [2013-08-28T18:00:00,000000+0000]
+[7] [00013] [ts/1] [torvalds] [linux       ] [hobby               ] [128.214.205.14 ] [1991-08-26T00:57:08,000000+0000]
+[7] [00014] [long] [rick    ] [long        ] [never-gonna-logout  ] [0.0.0.0        ] [1970-01-01T00:00:00,000000+0000]
+[8] [00014] [long] [rick    ] [long        ] [never-gonna-logout  ] [0.0.0.0        ] [2038-01-19T03:14:07,000000+0000]
tests/ts/utmp/txt-a-old new file +19 -0
new file mode 100644
index 0000000..bc91d19
@@ -0,0 +1,19 @@
+[9] [00009] [ts/9] [accounting] [foo         ] [nine                ] [0.0.0.0        ] [Wed Aug 28 03:00:00 2013 GMT]
+[8] [00008] [ts/8] [dead_process] [foo         ] [eight               ] [0.0.0.0        ] [Wed Aug 28 04:00:00 2013 GMT]
+[7] [00007] [ts/7] [user_process] [foo         ] [seven               ] [0.0.0.0        ] [Wed Aug 28 05:00:00 2013 GMT]
+[6] [00006] [ts/6] [login   ] [foo         ] [six                 ] [0.0.0.0        ] [Wed Aug 28 06:00:00 2013 GMT]
+[5] [00005] [ts/5] [init    ] [foo         ] [five                ] [0.0.0.0        ] [Wed Aug 28 07:00:00 2013 GMT]
+[4] [00004] [ts/4] [oldtime ] [foo         ] [four                ] [0.0.0.0        ] [Wed Aug 28 08:00:00 2013 GMT]
+[3] [00003] [ts/3] [newtime ] [foo         ] [three               ] [0.0.0.0        ] [Wed Aug 28 09:00:00 2013 GMT]
+[2] [00002] [ts/2] [sysboot ] [foo         ] [two                 ] [0.0.0.0        ] [Wed Aug 28 10:00:00 2013 GMT]
+[1] [00001] [ts/1] [runlevel] [foo         ] [one                 ] [0.0.0.0        ] [Wed Aug 28 11:00:00 2013 GMT]
+[0] [00000] [ts/0] [nonvalid] [foo         ] [zero                ] [0.0.0.0        ] [Wed Aug 28 12:00:00 2013 GMT]
+[7] [00010] [ipv4] [IPv4    ] [root        ] [dns-server          ] [198.41.0.4     ] [Wed Aug 28 13:00:00 2013 GMT]
+[8] [00011] [ipv4] [IPv4    ] [root        ] [dns-server          ] [198.41.0.4     ] [Wed Aug 28 14:00:00 2013 GMT]
+[1] [00012] [~~  ] [shutdown] [~           ] [system-name         ] [0.0.0.0        ] [Wed Aug 28 15:00:00 2013 GMT]
+[2] [00012] [~~  ] [reboot  ] [~           ] [system-name         ] [0.0.0.0        ] [Wed Aug 28 16:00:00 2013 GMT]
+[1] [00012] [~~  ] [shutdown] [~           ] [system-name         ] [0.0.0.0        ] [Wed Aug 28 17:00:00 2013 GMT]
+[2] [00012] [~~  ] [reboot  ] [~           ] [system-name         ] [0.0.0.0        ] [Wed Aug 28 18:00:00 2013 GMT]
+[7] [00013] [ts/1] [torvalds] [linux       ] [hobby               ] [128.214.205.14 ] [Mon Aug 26 00:57:08 1991 GMT]
+[7] [00014] [long] [rick    ] [long        ] [never-gonna-logout  ] [0.0.0.0        ] [                            ]
+[8] [00014] [long] [rick    ] [long        ] [never-gonna-logout  ] [0.0.0.0        ] [Tue Jan 19 03:14:07 2038 GMT]
tests/ts/utmp/txt-b +10 -10
index 02fb22d..5deefde 100644
@@ -1,10 +1,10 @@
-[7] [17058] [ts/1] [kerolasa] [pts/1       ] [:0.0                ] [0.0.0.0        ] [Wed Jan 16 23:44:09 2013 GMT]
-[7] [22098] [ts/2] [kerolasa] [pts/2       ] [:0.0                ] [0.0.0.0        ] [Wed Jan 16 23:49:17 2013 GMT]
-[7] [24915] [ts/3] [kerolasa] [pts/3       ] [:0.0                ] [0.0.0.0        ] [Thu Jan 17 12:23:33 2013 GMT]
-[8] [24915] [ts/3] [kerolasa] [pts/3       ] [                    ] [0.0.0.0        ] [Thu Jan 17 12:24:49 2013 GMT]
-[7] [30629] [ts/3] [kerolasa] [pts/3       ] [:0.0                ] [0.0.0.0        ] [Thu Jan 17 13:12:39 2013 GMT]
-[8] [30629] [ts/3] [kerolasa] [pts/3       ] [                    ] [0.0.0.0        ] [Thu Jan 17 13:42:19 2013 GMT]
-[8] [22098] [ts/2] [kerolasa] [pts/2       ] [                    ] [0.0.0.0        ] [Thu Jan 17 13:42:48 2013 GMT]
-[8] [17058] [ts/1] [kerolasa] [pts/1       ] [                    ] [0.0.0.0        ] [Thu Jan 17 13:42:48 2013 GMT]
-[7] [31545] [ts/1] [kerolasa] [pts/1       ] [:0.0                ] [0.0.0.0        ] [Thu Jan 17 20:17:21 2013 GMT]
-[7] [28496] [ts/2] [kerolasa] [pts/2       ] [:0.0                ] [0.0.0.0        ] [Thu Jan 17 21:09:39 2013 GMT]
+[7] [17058] [ts/1] [kerolasa] [pts/1       ] [:0.0                ] [0.0.0.0        ] [2013-01-16T23:44:09,000000+0000]
+[7] [22098] [ts/2] [kerolasa] [pts/2       ] [:0.0                ] [0.0.0.0        ] [2013-01-16T23:49:17,000000+0000]
+[7] [24915] [ts/3] [kerolasa] [pts/3       ] [:0.0                ] [0.0.0.0        ] [2013-01-17T12:23:33,000000+0000]
+[8] [24915] [ts/3] [kerolasa] [pts/3       ] [                    ] [0.0.0.0        ] [2013-01-17T12:24:49,000000+0000]
+[7] [30629] [ts/3] [kerolasa] [pts/3       ] [:0.0                ] [0.0.0.0        ] [2013-01-17T13:12:39,000000+0000]
+[8] [30629] [ts/3] [kerolasa] [pts/3       ] [                    ] [0.0.0.0        ] [2013-01-17T13:42:19,000000+0000]
+[8] [22098] [ts/2] [kerolasa] [pts/2       ] [                    ] [0.0.0.0        ] [2013-01-17T13:42:48,000000+0000]
+[8] [17058] [ts/1] [kerolasa] [pts/1       ] [                    ] [0.0.0.0        ] [2013-01-17T13:42:48,000000+0000]
+[7] [31545] [ts/1] [kerolasa] [pts/1       ] [:0.0                ] [0.0.0.0        ] [2013-01-17T20:17:21,000000+0000]
+[7] [28496] [ts/2] [kerolasa] [pts/2       ] [:0.0                ] [0.0.0.0        ] [2013-01-17T21:09:39,000000+0000]
tests/ts/utmp/txt-b-old new file +10 -0
new file mode 100644
index 0000000..02fb22d
@@ -0,0 +1,10 @@
+[7] [17058] [ts/1] [kerolasa] [pts/1       ] [:0.0                ] [0.0.0.0        ] [Wed Jan 16 23:44:09 2013 GMT]
+[7] [22098] [ts/2] [kerolasa] [pts/2       ] [:0.0                ] [0.0.0.0        ] [Wed Jan 16 23:49:17 2013 GMT]
+[7] [24915] [ts/3] [kerolasa] [pts/3       ] [:0.0                ] [0.0.0.0        ] [Thu Jan 17 12:23:33 2013 GMT]
+[8] [24915] [ts/3] [kerolasa] [pts/3       ] [                    ] [0.0.0.0        ] [Thu Jan 17 12:24:49 2013 GMT]
+[7] [30629] [ts/3] [kerolasa] [pts/3       ] [:0.0                ] [0.0.0.0        ] [Thu Jan 17 13:12:39 2013 GMT]
+[8] [30629] [ts/3] [kerolasa] [pts/3       ] [                    ] [0.0.0.0        ] [Thu Jan 17 13:42:19 2013 GMT]
+[8] [22098] [ts/2] [kerolasa] [pts/2       ] [                    ] [0.0.0.0        ] [Thu Jan 17 13:42:48 2013 GMT]
+[8] [17058] [ts/1] [kerolasa] [pts/1       ] [                    ] [0.0.0.0        ] [Thu Jan 17 13:42:48 2013 GMT]
+[7] [31545] [ts/1] [kerolasa] [pts/1       ] [:0.0                ] [0.0.0.0        ] [Thu Jan 17 20:17:21 2013 GMT]
+[7] [28496] [ts/2] [kerolasa] [pts/2       ] [:0.0                ] [0.0.0.0        ] [Thu Jan 17 21:09:39 2013 GMT]
tests/ts/utmp/txt-ipv6 +2 -2
index 5cce150..5894144 100644
@@ -1,2 +1,2 @@
-[7] [00010] [ipv6] [IPv6    ] [root        ] [dns-server          ] [2001:503:ba3e::2:30] [Wed Aug 28 20:30:40 2013 GMT]
-[8] [00011] [ipv6] [IPv6    ] [root        ] [dns-server          ] [2001:503:ba3e::2:30] [Wed Aug 28 20:40:50 2013 GMT]
+[7] [00010] [ipv6] [IPv6    ] [root        ] [dns-server          ] [2001:503:ba3e::2:30] [2013-08-28T20:30:40,000000+0000]
+[8] [00011] [ipv6] [IPv6    ] [root        ] [dns-server          ] [2001:503:ba3e::2:30] [2013-08-28T20:40:50,000000+0000]
tests/ts/utmp/txt-ipv6-old new file +2 -0
new file mode 100644
index 0000000..5cce150
@@ -0,0 +1,2 @@
+[7] [00010] [ipv6] [IPv6    ] [root        ] [dns-server          ] [2001:503:ba3e::2:30] [Wed Aug 28 20:30:40 2013 GMT]
+[8] [00011] [ipv6] [IPv6    ] [root        ] [dns-server          ] [2001:503:ba3e::2:30] [Wed Aug 28 20:40:50 2013 GMT]
tests/ts/utmp/utmpdump-circle +7 -1
index cae2995..9663dba 100755
@@ -27,9 +27,15 @@ OUT_BIN1=${TS_OUTDIR}/${TS_TESTNAME}.bin1
 OUT_BIN2=${TS_OUTDIR}/${TS_TESTNAME}.bin2
 OUT_TXT=${TS_OUTDIR}/${TS_TESTNAME}.txt
 
+# Files with -old extension are using timestamp format before utmpdump
+# started to use iso-8601 format.  This check is testing nothing is lost
+# when conversions performing following conversions.
+#
+# old text format -> binary -> new text format -> binary
+
 echo "no output expected" > $TS_OUTPUT
 for f in txt-a txt-b txt-ipv6; do
-	$TS_CMD_UTMPDUMP -r $TS_SELF/$f > $OUT_BIN1 2>/dev/null &&
+	$TS_CMD_UTMPDUMP -r $TS_SELF/$f-old > $OUT_BIN1 2>/dev/null &&
 	$TS_CMD_UTMPDUMP $OUT_BIN1 > $OUT_TXT 2>/dev/null &&
 	diff -u $TS_SELF/$f $OUT_TXT &&
 	$TS_CMD_UTMPDUMP -r $OUT_TXT > $OUT_BIN2 2>/dev/null &&
Signature · 1 line
2.9.0
#8 lore raw

PATCH 5/6 tests: remove utmpdump localization go-around

In reply to Sami Kerola

The utmpdump timestamps are unambiguous, so forcing locale environment is never needed.

---
 tests/ts/utmp/utmpdump-circle     | 2 --
 tests/ts/utmp/utmpdump-tobin      | 2 --
 tests/ts/utmp/utmpdump-tobin-ipv6 | 2 --
 tests/ts/utmp/utmpdump-totxt      | 2 --
 tests/ts/utmp/utmpdump-totxt-ipv6 | 2 --
 5 files changed, 10 deletions(-)
tests/ts/utmp/utmpdump-circle +0 -2
index 9663dba..41d7de6 100755
@@ -21,8 +21,6 @@ ts_init "$*"
 # this test is arch independent, no need for utmp_functions.sh
 ts_check_test_command "$TS_CMD_UTMPDUMP"
 
-export LANG=C
-export TZ=GMT
 OUT_BIN1=${TS_OUTDIR}/${TS_TESTNAME}.bin1
 OUT_BIN2=${TS_OUTDIR}/${TS_TESTNAME}.bin2
 OUT_TXT=${TS_OUTDIR}/${TS_TESTNAME}.txt
tests/ts/utmp/utmpdump-tobin +0 -2
index 2f14bfc..4054952 100755
@@ -21,8 +21,6 @@ ts_init "$*"
 . "$TS_SELF/utmp_functions.sh"
 [ $SIZEOF_UTMP -eq 384 ] || ts_skip "utmp struct size $SIZEOF_UTMP"
 
-export LANG=C
-export TZ=GMT
 OUTFILE=${TS_OUTDIR}/${TS_TESTNAME}.file
 $TS_CMD_UTMPDUMP -r $TS_SELF/txt-b >| $OUTFILE 2>/dev/null
 if diff -q $TS_SELF/wtmp-b.$BYTE_ORDER $OUTFILE; then
tests/ts/utmp/utmpdump-tobin-ipv6 +0 -2
index e0b19cd..3198d3c 100755
@@ -21,8 +21,6 @@ ts_init "$*"
 . "$TS_SELF/utmp_functions.sh"
 [ $SIZEOF_UTMP -eq 384 ] || ts_skip "utmp struct size $SIZEOF_UTMP"
 
-export LANG=C
-export TZ=GMT
 OUTFILE=${TS_OUTDIR}/${TS_TESTNAME}.file
 $TS_CMD_UTMPDUMP -r $TS_SELF/txt-ipv6 >| $OUTFILE 2>/dev/null
 if diff -q $TS_SELF/wtmp-ipv6.$BYTE_ORDER $OUTFILE; then
tests/ts/utmp/utmpdump-totxt +0 -2
index 37d376a..cde1f4c 100755
@@ -21,8 +21,6 @@ ts_init "$*"
 . "$TS_SELF/utmp_functions.sh"
 [ $SIZEOF_UTMP -eq 384 ] || ts_skip "utmp struct size $SIZEOF_UTMP"
 
-export LANG=C
-export TZ=GMT
 $TS_CMD_UTMPDUMP $TS_SELF/wtmp-b.$BYTE_ORDER >| $TS_OUTPUT 2>/dev/null
 
 ts_finalize
tests/ts/utmp/utmpdump-totxt-ipv6 +0 -2
index 1b21783..5fc3d9c 100755
@@ -21,8 +21,6 @@ ts_init "$*"
 . "$TS_SELF/utmp_functions.sh"
 [ $SIZEOF_UTMP -eq 384 ] || ts_skip "utmp struct size $SIZEOF_UTMP"
 
-export LANG=C
-export TZ=GMT
 $TS_CMD_UTMPDUMP $TS_SELF/wtmp-ipv6.$BYTE_ORDER >| $TS_OUTPUT 2>/dev/null
 
 ts_finalize
Signature · 1 line
2.9.0
#11 lore raw

PATCH 6/6 tests: utmpdump add subsecond accuracy test

In reply to Sami Kerola
---
 tests/expected/utmp/utmpdump-subsecond |  5 +++++
 tests/ts/utmp/subsec                   |  3 +++
 tests/ts/utmp/utmpdump-subsecond       | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+)
 create mode 100644 tests/expected/utmp/utmpdump-subsecond
 create mode 100644 tests/ts/utmp/subsec
 create mode 100755 tests/ts/utmp/utmpdump-subsecond
tests/expected/utmp/utmpdump-subsecond new file +5 -0
new file mode 100644
index 0000000..9ec40da
@@ -0,0 +1,5 @@
+last 9 is expected to disappear in conversion
+3c3
+< [0] [00000] [ts/0] [nonvalid] [foo         ] [zero                ] [0.0.0.0        ] [2013-08-28T12:00:00,123456789+0000]
+---
+> [0] [00000] [ts/0] [nonvalid] [foo         ] [zero                ] [0.0.0.0        ] [2013-08-28T12:00:00,12345678+0000]
tests/ts/utmp/subsec new file +3 -0
new file mode 100644
index 0000000..4881e7c
@@ -0,0 +1,3 @@
+[7] [00010] [ipv6] [IPv6    ] [root        ] [dns-server          ] [2001:503:ba3e::2:30] [2013-08-28T20:30:40,123456+0000]
+[8] [00011] [ipv6] [IPv6    ] [root        ] [dns-server          ] [2001:503:ba3e::2:30] [2013-08-28T20:40:50,999999+0000]
+[0] [00000] [ts/0] [nonvalid] [foo         ] [zero                ] [0.0.0.0        ] [2013-08-28T12:00:00,123456789+0000]
tests/ts/utmp/utmpdump-subsecond new file +34 -0
new file mode 100755
index 0000000..f753a6d
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="subsecond"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+# this test is arch independent, no need for utmp_functions.sh
+ts_check_test_command "$TS_CMD_UTMPDUMP"
+
+OUT_BIN=${TS_OUTDIR}/${TS_TESTNAME}.bin
+OUT_TXT=${TS_OUTDIR}/${TS_TESTNAME}.txt
+
+echo "last 9 is expected to disappear in conversion" > $TS_OUTPUT
+$TS_CMD_UTMPDUMP -r $TS_SELF/subsec > $OUT_BIN 2>/dev/null
+$TS_CMD_UTMPDUMP $OUT_BIN > $OUT_TXT 2>/dev/null
+diff $TS_SELF/subsec $OUT_TXT >> $TS_OUTPUT 2>&1
+
+rm -f "$OUT_BIN" "$OUT_TXT"
+
+ts_finalize
Signature · 1 line
2.9.0
maintainer
#2 lore raw

Re: [PATCH 1/6] utmpdump: use always UTC-0 timezone in textual output

In reply to Sami Kerola
Quoted 8 lines · Sami Kerola

Converting a time structure from text format that has timezone markup is practically impossible. See reference links for more information. This leads to situation where multiple utmpdump(1) conversions from binary to text and back make timestamps to shift amount of timezone offset to UTC-0.

The easiest way to make multiple conversions to work without timeshifts is to always use UTC-0 timezone. Downside of this approach is that the textual format is less human readable than local timestamps would be.

Makes sense, but it would be nice to have big fat note in the man page.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
maintainer
#5 lore raw

Re: [PATCH 3/6] utmpdump: use iso-8601 timestamp format with subsecond accuracy

In reply to Sami Kerola
Quoted 5 lines · Sami Kerola

Newer 'struct utmp' is using 'struct timeval' to represent login and logout times, so include the maximum accuracy to textual utmp format. Notice that this change does not remove support of converting earlier textual formats back to binary. But conversions from binary to former format will no longer be available.

It would be also nice to document that utmpdump is able to read textual utmp format generated by the current utmpdump version only and that we don't maintain any backward compatibility for the textual output.

The only binary version of the utmp is standardized.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
maintainer
#9 lore raw

Re: [PATCH 5/6] tests: remove utmpdump localization go-around

In reply to Sami Kerola
Quoted 2 lines · Sami Kerola

The utmpdump timestamps are unambiguous, so forcing locale environment is never needed.

and what about strptime()?

I think it's fine to keep tests robust and in well know environment.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#6 lore raw

Re: [PATCH 3/6] utmpdump: use iso-8601 timestamp format with subsecond accuracy

In reply to Karel Zak
Quoted 7 lines · Karel Zak
Quoted 5 lines · Sami Kerola

Newer 'struct utmp' is using 'struct timeval' to represent login and logout times, so include the maximum accuracy to textual utmp format. Notice that this change does not remove support of converting earlier textual formats back to binary. But conversions from binary to former format will no longer be available.

Quoted 6 lines

It would be also nice to document that utmpdump is able to read textual utmp format generated by the current utmpdump version only and that we don't maintain any backward compatibility for the textual output.

The only binary version of the utmp is standardized.

Fair point. How about something like

https://github.com/kerolasa/lelux-utiliteetit/commit/3d47107de5d04fe2803827d3e24c227a18d1a4b0

Signature · 2 lines
Sami Kerola
http://www.iki.fi/kerolasa/
#10 lore raw

Re: [PATCH 5/6] tests: remove utmpdump localization go-around

In reply to Karel Zak
Quoted 7 lines · Karel Zak
Quoted 2 lines · Sami Kerola

The utmpdump timestamps are unambiguous, so forcing locale environment is never needed.

and what about strptime()?

I think it's fine to keep tests robust and in well know environment.

strptime(3) is no longer expected to make timestamp to be localized. Perhaps it would
be best to give strptime(3) wrong ideas about timezone, so that one can observe gmtime(3) to do the right thing. To express same in form of change, here we go:

https://github.com/kerolasa/lelux-utiliteetit/commit/73f46aedc316efbb8e2a719c1c6c3aef364a5553

Signature · 2 lines
Sami Kerola
http://www.iki.fi/kerolasa/
maintainer Applied
#12 lore raw
In reply to Sami Kerola
Quoted 6 lines · Sami Kerola

utmpdump: use always UTC-0 timezone in textual output
libcommon: add ISO_8601_GMTIME that will print UTC-0 timestamps
utmpdump: use iso-8601 timestamp format with subsecond accuracy
tests: fix utmpdump timestamps to be in iso format
tests: remove utmpdump localization go-around
tests: utmpdump add subsecond accuracy test

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com