diff options
author | Karel Zak | 2016-07-01 13:51:59 +0200 |
---|---|---|
committer | Karel Zak | 2016-07-01 13:51:59 +0200 |
commit | 29fdedc2bc99a990857200cf357447351900c117 (patch) | |
tree | fa68ff23d67b89ef5af9301816add34967e2fecd | |
parent | libblkid: Add metadata signature check for IMSM on 4Kn drives (diff) | |
parent | docs: add file format note to utmpdump manual page (diff) | |
download | kernel-qcow2-util-linux-29fdedc2bc99a990857200cf357447351900c117.tar.gz kernel-qcow2-util-linux-29fdedc2bc99a990857200cf357447351900c117.tar.xz kernel-qcow2-util-linux-29fdedc2bc99a990857200cf357447351900c117.zip |
Merge branch 'utmpdump' of git://github.com/kerolasa/lelux-utiliteetit
* 'utmpdump' of git://github.com/kerolasa/lelux-utiliteetit:
docs: add file format note to utmpdump manual page
tests: utmpdump add subsecond accuracy test
tests: challenge utmpdump localization go-around
tests: fix utmpdump timestamps to be in iso format
utmpdump: use iso-8601 timestamp format with subsecond accuracy
libcommon: add ISO_8601_GMTIME that will print UTC-0 timestamps
utmpdump: use always UTC-0 timezone in textual output
-rw-r--r-- | include/timeutils.h | 3 | ||||
-rw-r--r-- | lib/timeutils.c | 14 | ||||
-rw-r--r-- | login-utils/Makemodule.am | 1 | ||||
-rw-r--r-- | login-utils/utmpdump.1 | 12 | ||||
-rw-r--r-- | login-utils/utmpdump.c | 63 | ||||
-rw-r--r-- | tests/expected/utmp/utmpdump-subsecond | 5 | ||||
-rw-r--r-- | tests/expected/utmp/utmpdump-totxt | 20 | ||||
-rw-r--r-- | tests/expected/utmp/utmpdump-totxt-ipv6 | 4 | ||||
-rw-r--r-- | tests/ts/utmp/subsec | 3 | ||||
-rw-r--r-- | tests/ts/utmp/txt-a | 38 | ||||
-rw-r--r-- | tests/ts/utmp/txt-a-old | 19 | ||||
-rw-r--r-- | tests/ts/utmp/txt-b | 20 | ||||
-rw-r--r-- | tests/ts/utmp/txt-b-old | 10 | ||||
-rw-r--r-- | tests/ts/utmp/txt-ipv6 | 4 | ||||
-rw-r--r-- | tests/ts/utmp/txt-ipv6-old | 2 | ||||
-rwxr-xr-x | tests/ts/utmp/utmpdump-circle | 10 | ||||
-rwxr-xr-x | tests/ts/utmp/utmpdump-subsecond | 34 | ||||
-rwxr-xr-x | tests/ts/utmp/utmpdump-tobin | 2 | ||||
-rwxr-xr-x | tests/ts/utmp/utmpdump-tobin-ipv6 | 2 | ||||
-rwxr-xr-x | tests/ts/utmp/utmpdump-totxt | 2 | ||||
-rwxr-xr-x | tests/ts/utmp/utmpdump-totxt-ipv6 | 2 |
21 files changed, 192 insertions, 78 deletions
diff --git a/include/timeutils.h b/include/timeutils.h index 265577f5e..00d18200d 100644 --- a/include/timeutils.h +++ b/include/timeutils.h @@ -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 diff --git a/lib/timeutils.c b/lib/timeutils.c index 25a163e41..fd9aa3e2e 100644 --- a/lib/timeutils.c +++ b/lib/timeutils.c @@ -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); } diff --git a/login-utils/Makemodule.am b/login-utils/Makemodule.am index 502ecd503..be07ace43 100644 --- a/login-utils/Makemodule.am +++ b/login-utils/Makemodule.am @@ -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 diff --git a/login-utils/utmpdump.1 b/login-utils/utmpdump.1 index 68516d8bd..c7a843d1a 100644 --- a/login-utils/utmpdump.1 +++ b/login-utils/utmpdump.1 @@ -57,6 +57,18 @@ bogus entries, and reintegrated using: But be warned, .B utmpdump was written for debugging purposes only. +.SS File formats +.PP +The only binary version of the +.BR utmp (5) +is standardised. Textual dumps may become incompatible in future. +.PP +The version 2.28 was the last one that printed text output using +.BR ctime (3) +timestamp format. Newer dumps use millisecond precision ISO-8601 timestamp +format in UTC-0 timezone. Conversion from former timestamp format can be +made to binary, although attempt to do so can lead the timestamps to drift +amount of timezone offset. .SH BUGS You may .B not diff --git a/login-utils/utmpdump.c b/login-utils/utmpdump.c index 03cf4a94a..1849a4e93 100644 --- a/login-utils/utmpdump.c +++ b/login-utils/utmpdump.c @@ -42,22 +42,10 @@ #include "c.h" #include "nls.h" +#include "timeutils.h" #include "xalloc.h" #include "closestream.h" -static char *timetostr(const time_t time) -{ - static char s[29]; /* [Sun Sep 01 00:00:00 1998 PST] */ - struct tm *tmp; - - if (time != 0 && (tmp = localtime(&time))) - strftime(s, 29, "%a %b %d %T %Y %Z", tmp); - else - s[0] = '\0'; - - return s; -} - static time_t strtotime(const char *s_time) { struct tm tm; @@ -67,14 +55,31 @@ static time_t strtotime(const char *s_time) if (s_time[0] == ' ' || s_time[0] == '\0') return (time_t)0; - strptime(s_time, "%a %b %d %T %Y", &tm); - - /* Cheesy way of checking for DST */ - if (s_time[26] == 'D') - tm.tm_isdst = 1; + if (isdigit(s_time[0])) { + /* [1998-09-01T01:00:00,000000+00:00] + * Subseconds are parsed with strtousec(). Timezone is + * always UTC-0 */ + strptime(s_time, "%Y-%m-%dT%H:%M:%S", &tm); + } else { + /* [Tue Sep 01 00:00:00 1998 GMT] */ + strptime(s_time, "%a %b %d %T %Y", &tm); + /* Cheesy way of checking for DST. This could be needed + * with legacy dumps that used localtime(3). */ + if (s_time[26] == 'D') + tm.tm_isdst = 1; + } + return timegm(&tm); +} - return mktime(&tm); +#if defined(_HAVE_UT_TV) +static suseconds_t strtousec(const char *s_time) +{ + const char *s = strchr(s_time, ','); + if (s) + return (suseconds_t) atoi(s + 1); + return 0; } +#endif #define cleanse(x) xcleanse(x, sizeof(x)) static void xcleanse(char *s, int len) @@ -86,26 +91,31 @@ static void xcleanse(char *s, int len) static void print_utline(struct utmp *ut, FILE *out) { - const char *addr_string, *time_string; + const char *addr_string; char buffer[INET6_ADDRSTRLEN]; + char time_string[40]; + struct timeval tv; if (ut->ut_addr_v6[1] || ut->ut_addr_v6[2] || ut->ut_addr_v6[3]) addr_string = inet_ntop(AF_INET6, &(ut->ut_addr_v6), buffer, sizeof(buffer)); else addr_string = inet_ntop(AF_INET, &(ut->ut_addr_v6), buffer, sizeof(buffer)); -#if defined(_HAVE_UT_TV) - time_string = timetostr(ut->ut_tv.tv_sec); -#else - time_string = timetostr((time_t)ut->ut_time); /* ut_time is not always a time_t */ -#endif + tv.tv_sec = ut->ut_tv.tv_sec; + tv.tv_usec = ut->ut_tv.tv_usec; + + if (strtimeval_iso(&tv, + ISO_8601_DATE | ISO_8601_TIME | ISO_8601_COMMAUSEC | + ISO_8601_TIMEZONE | ISO_8601_GMTIME, time_string, + sizeof(time_string)) != 0) + return; cleanse(ut->ut_id); cleanse(ut->ut_user); cleanse(ut->ut_line); cleanse(ut->ut_host); /* pid id user line host addr time */ - fprintf(out, "[%d] [%05d] [%-4.4s] [%-*.*s] [%-*.*s] [%-*.*s] [%-15s] [%-28.28s]\n", + fprintf(out, "[%d] [%05d] [%-4.4s] [%-*.*s] [%-*.*s] [%-*.*s] [%-15s] [%s]\n", ut->ut_type, ut->ut_pid, ut->ut_id, 8, UT_NAMESIZE, ut->ut_user, 12, UT_LINESIZE, ut->ut_line, 20, UT_HOSTSIZE, ut->ut_host, addr_string, time_string); @@ -279,6 +289,7 @@ static void undump(FILE *in, FILE *out) inet_pton(AF_INET6, s_addr, &(ut.ut_addr_v6)); #if defined(_HAVE_UT_TV) ut.ut_tv.tv_sec = strtotime(s_time); + ut.ut_tv.tv_usec = strtousec(s_time); #else ut.ut_time = strtotime(s_time); #endif diff --git a/tests/expected/utmp/utmpdump-subsecond b/tests/expected/utmp/utmpdump-subsecond new file mode 100644 index 000000000..9ec40dab6 --- /dev/null +++ b/tests/expected/utmp/utmpdump-subsecond @@ -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] diff --git a/tests/expected/utmp/utmpdump-totxt b/tests/expected/utmp/utmpdump-totxt index 02fb22d5f..5deefde60 100644 --- a/tests/expected/utmp/utmpdump-totxt +++ b/tests/expected/utmp/utmpdump-totxt @@ -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] diff --git a/tests/expected/utmp/utmpdump-totxt-ipv6 b/tests/expected/utmp/utmpdump-totxt-ipv6 index 5cce1506b..589414408 100644 --- a/tests/expected/utmp/utmpdump-totxt-ipv6 +++ b/tests/expected/utmp/utmpdump-totxt-ipv6 @@ -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] diff --git a/tests/ts/utmp/subsec b/tests/ts/utmp/subsec new file mode 100644 index 000000000..4881e7cad --- /dev/null +++ b/tests/ts/utmp/subsec @@ -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] diff --git a/tests/ts/utmp/txt-a b/tests/ts/utmp/txt-a index bc91d1983..8501daab0 100644 --- a/tests/ts/utmp/txt-a +++ b/tests/ts/utmp/txt-a @@ -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] diff --git a/tests/ts/utmp/txt-a-old b/tests/ts/utmp/txt-a-old new file mode 100644 index 000000000..bc91d1983 --- /dev/null +++ b/tests/ts/utmp/txt-a-old @@ -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] diff --git a/tests/ts/utmp/txt-b b/tests/ts/utmp/txt-b index 02fb22d5f..5deefde60 100644 --- a/tests/ts/utmp/txt-b +++ b/tests/ts/utmp/txt-b @@ -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] diff --git a/tests/ts/utmp/txt-b-old b/tests/ts/utmp/txt-b-old new file mode 100644 index 000000000..02fb22d5f --- /dev/null +++ b/tests/ts/utmp/txt-b-old @@ -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] diff --git a/tests/ts/utmp/txt-ipv6 b/tests/ts/utmp/txt-ipv6 index 5cce1506b..589414408 100644 --- a/tests/ts/utmp/txt-ipv6 +++ b/tests/ts/utmp/txt-ipv6 @@ -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] diff --git a/tests/ts/utmp/txt-ipv6-old b/tests/ts/utmp/txt-ipv6-old new file mode 100644 index 000000000..5cce1506b --- /dev/null +++ b/tests/ts/utmp/txt-ipv6-old @@ -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] diff --git a/tests/ts/utmp/utmpdump-circle b/tests/ts/utmp/utmpdump-circle index cae29953e..0065f705b 100755 --- a/tests/ts/utmp/utmpdump-circle +++ b/tests/ts/utmp/utmpdump-circle @@ -22,14 +22,20 @@ ts_init "$*" ts_check_test_command "$TS_CMD_UTMPDUMP" export LANG=C -export TZ=GMT +export TZ=Asia/Tokyo 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 && diff --git a/tests/ts/utmp/utmpdump-subsecond b/tests/ts/utmp/utmpdump-subsecond new file mode 100755 index 000000000..f753a6d76 --- /dev/null +++ b/tests/ts/utmp/utmpdump-subsecond @@ -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 diff --git a/tests/ts/utmp/utmpdump-tobin b/tests/ts/utmp/utmpdump-tobin index 2f14bfc14..8b089e6f4 100755 --- a/tests/ts/utmp/utmpdump-tobin +++ b/tests/ts/utmp/utmpdump-tobin @@ -22,7 +22,7 @@ ts_init "$*" [ $SIZEOF_UTMP -eq 384 ] || ts_skip "utmp struct size $SIZEOF_UTMP" export LANG=C -export TZ=GMT +export TZ=Asia/Tokyo 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 diff --git a/tests/ts/utmp/utmpdump-tobin-ipv6 b/tests/ts/utmp/utmpdump-tobin-ipv6 index e0b19cd13..cd081398e 100755 --- a/tests/ts/utmp/utmpdump-tobin-ipv6 +++ b/tests/ts/utmp/utmpdump-tobin-ipv6 @@ -22,7 +22,7 @@ ts_init "$*" [ $SIZEOF_UTMP -eq 384 ] || ts_skip "utmp struct size $SIZEOF_UTMP" export LANG=C -export TZ=GMT +export TZ=Asia/Tokyo 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 diff --git a/tests/ts/utmp/utmpdump-totxt b/tests/ts/utmp/utmpdump-totxt index 37d376a8b..099533ca9 100755 --- a/tests/ts/utmp/utmpdump-totxt +++ b/tests/ts/utmp/utmpdump-totxt @@ -22,7 +22,7 @@ ts_init "$*" [ $SIZEOF_UTMP -eq 384 ] || ts_skip "utmp struct size $SIZEOF_UTMP" export LANG=C -export TZ=GMT +export TZ=Asia/Tokyo $TS_CMD_UTMPDUMP $TS_SELF/wtmp-b.$BYTE_ORDER >| $TS_OUTPUT 2>/dev/null ts_finalize diff --git a/tests/ts/utmp/utmpdump-totxt-ipv6 b/tests/ts/utmp/utmpdump-totxt-ipv6 index 1b2178386..bc9704e32 100755 --- a/tests/ts/utmp/utmpdump-totxt-ipv6 +++ b/tests/ts/utmp/utmpdump-totxt-ipv6 @@ -22,7 +22,7 @@ ts_init "$*" [ $SIZEOF_UTMP -eq 384 ] || ts_skip "utmp struct size $SIZEOF_UTMP" export LANG=C -export TZ=GMT +export TZ=Asia/Tokyo $TS_CMD_UTMPDUMP $TS_SELF/wtmp-ipv6.$BYTE_ORDER >| $TS_OUTPUT 2>/dev/null ts_finalize |