From: Karel Zak Date: Thu, 8 Mar 2007 22:22:06 +0000 (+0100) Subject: login: update 32bit utmp correctly on 64bit system X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75d4dbb0d7d7937f0f5f464c3bd803d4191a6c0e;p=util-linux login: update 32bit utmp correctly on 64bit system On 64-bit platforms such as x86_64, glibc is usually built with 32-bit compatibility for various structures. One of them is utmp. What this means is that gettimeofday(&ut.ut_tv, NULL) on x86_64 will end up overwriting the first parts of ut_addr_v6, leading to garbage in the utmp file. Signed-off-by: Karel Zak --- diff --git a/login-utils/login.c b/login-utils/login.c index 1715015d..d5ec1fc0 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -256,6 +256,7 @@ consoletty(int fd) { static void logbtmp(const char *line, const char *username, const char *hostname) { struct utmp ut; + struct timeval tv; memset(&ut, 0, sizeof(ut)); @@ -266,7 +267,9 @@ logbtmp(const char *line, const char *username, const char *hostname) { xstrncpy(ut.ut_line, line, sizeof(ut.ut_line)); #if defined(_HAVE_UT_TV) /* in included by */ - gettimeofday(&ut.ut_tv, NULL); + gettimeofday(&tv, NULL); + ut.ut_tv.tv_sec = tv.tv_sec; + ut.ut_tv.tv_usec = tv.tv_usec; #else { time_t t; @@ -833,6 +836,7 @@ main(int argc, char **argv) { struct utmp ut; struct utmp *utp; + struct timeval tv; utmpname(_PATH_UTMP); setutent(); @@ -872,7 +876,9 @@ Michael Riepe strncpy(ut.ut_user, username, sizeof(ut.ut_user)); xstrncpy(ut.ut_line, tty_name, sizeof(ut.ut_line)); #ifdef _HAVE_UT_TV /* in included by */ - gettimeofday(&ut.ut_tv, NULL); + gettimeofday(&tv, NULL); + ut.ut_tv.tv_sec = tv.tv_sec; + ut.ut_tv.tv_usec = tv.tv_usec; #else { time_t t;