summaryrefslogtreecommitdiffstats
path: root/login-utils
diff options
context:
space:
mode:
authorRuediger Meier2016-12-01 09:52:05 +0100
committerKarel Zak2016-12-07 12:35:24 +0100
commit55771f54096eec064d8284a54a119f0b371cd7fb (patch)
treec2eab93c45484a6faf38426dee7bd98533a2649e /login-utils
parentlast: include libgen.h for basename(3p) (diff)
downloadkernel-qcow2-util-linux-55771f54096eec064d8284a54a119f0b371cd7fb.tar.gz
kernel-qcow2-util-linux-55771f54096eec064d8284a54a119f0b371cd7fb.tar.xz
kernel-qcow2-util-linux-55771f54096eec064d8284a54a119f0b371cd7fb.zip
login-utils: remove _HAVE_UT_TV fallback
_HAVE_UT_TV is glibc only. Moreover we want to move to utmpx where timeval is standard. Now utmp/subsecond (1173d0a6) should work on all supported systems. CC: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'login-utils')
-rw-r--r--login-utils/last.c32
-rw-r--r--login-utils/login.c19
-rw-r--r--login-utils/su-common.c8
-rw-r--r--login-utils/utmpdump.c8
4 files changed, 15 insertions, 52 deletions
diff --git a/login-utils/last.c b/login-utils/last.c
index 90eee68e5..42fb914d8 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -53,12 +53,6 @@
#include "timeutils.h"
#include "monotonic.h"
-#if defined(_HAVE_UT_TV)
-# define UL_UT_TIME ut_tv.tv_sec
-#else
-# define UL_UT_TIME ut_time
-#endif
-
#ifndef SHUTDOWN_TIME
# define SHUTDOWN_TIME 254
#endif
@@ -425,7 +419,7 @@ static int list(const struct last_control *ctl, struct utmp *p, time_t logout_ti
*/
fmt = &timefmts[ctl->time_fmt];
- utmp_time = p->UL_UT_TIME;
+ utmp_time = p->ut_tv.tv_sec;
if (ctl->present) {
if (ctl->present < utmp_time)
@@ -604,7 +598,7 @@ static int is_phantom(const struct last_control *ctl, struct utmp *ut)
char path[32];
int ret = 0;
- if (ut->UL_UT_TIME < ctl->boot_time.tv_sec)
+ if (ut->ut_tv.tv_sec < ctl->boot_time.tv_sec)
return 1;
pw = getpwnam(ut->ut_user);
if (!pw)
@@ -681,7 +675,7 @@ static void process_wtmp_file(const struct last_control *ctl,
* Read first structure to capture the time field
*/
if (uread(fp, &ut, NULL, filename) == 1)
- begintime = ut.UL_UT_TIME;
+ begintime = ut.ut_tv.tv_sec;
else {
if (fstat(fileno(fp), &st) != 0)
err(EXIT_FAILURE, _("stat of %s failed"), filename);
@@ -703,16 +697,16 @@ static void process_wtmp_file(const struct last_control *ctl,
if (uread(fp, &ut, &quit, filename) != 1)
break;
- if (ctl->since && ut.UL_UT_TIME < ctl->since)
+ if (ctl->since && ut.ut_tv.tv_sec < ctl->since)
continue;
- if (ctl->until && ctl->until < ut.UL_UT_TIME)
+ if (ctl->until && ctl->until < ut.ut_tv.tv_sec)
continue;
- lastdate = ut.UL_UT_TIME;
+ lastdate = ut.ut_tv.tv_sec;
if (ctl->lastb) {
- quit = list(ctl, &ut, ut.UL_UT_TIME, R_NORMAL);
+ quit = list(ctl, &ut, ut.ut_tv.tv_sec, R_NORMAL);
continue;
}
@@ -762,7 +756,7 @@ static void process_wtmp_file(const struct last_control *ctl,
strcpy(ut.ut_line, "system down");
quit = list(ctl, &ut, lastboot, R_NORMAL);
}
- lastdown = lastrch = ut.UL_UT_TIME;
+ lastdown = lastrch = ut.ut_tv.tv_sec;
down = 1;
break;
case OLD_TIME:
@@ -777,7 +771,7 @@ static void process_wtmp_file(const struct last_control *ctl,
case BOOT_TIME:
strcpy(ut.ut_line, "system boot");
quit = list(ctl, &ut, lastdown, R_REBOOT);
- lastboot = ut.UL_UT_TIME;
+ lastboot = ut.ut_tv.tv_sec;
down = 1;
break;
case RUN_LVL:
@@ -787,11 +781,11 @@ static void process_wtmp_file(const struct last_control *ctl,
quit = list(ctl, &ut, lastrch, R_NORMAL);
}
if (x == '0' || x == '6') {
- lastdown = ut.UL_UT_TIME;
+ lastdown = ut.ut_tv.tv_sec;
down = 1;
ut.ut_type = SHUTDOWN_TIME;
}
- lastrch = ut.UL_UT_TIME;
+ lastrch = ut.ut_tv.tv_sec;
break;
case USER_PROCESS:
@@ -807,7 +801,7 @@ static void process_wtmp_file(const struct last_control *ctl,
UT_LINESIZE) == 0) {
/* Show it */
if (c == 0) {
- quit = list(ctl, &ut, p->ut.UL_UT_TIME, R_NORMAL);
+ quit = list(ctl, &ut, p->ut.ut_tv.tv_sec, R_NORMAL);
c = 1;
}
if (p->next)
@@ -867,7 +861,7 @@ static void process_wtmp_file(const struct last_control *ctl,
* the entire current ulist.
*/
if (down) {
- lastboot = ut.UL_UT_TIME;
+ lastboot = ut.ut_tv.tv_sec;
whydown = (ut.ut_type == SHUTDOWN_TIME) ? R_DOWN : R_CRASH;
for (p = ulist; p; p = next) {
next = p->next;
diff --git a/login-utils/login.c b/login-utils/login.c
index 2350fc3ec..043fce129 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -426,9 +426,7 @@ static void init_tty(struct login_context *cxt)
static void log_btmp(struct login_context *cxt)
{
struct utmp ut;
-#if defined(_HAVE_UT_TV) /* in <utmpbits.h> included by <utmp.h> */
struct timeval tv;
-#endif
memset(&ut, 0, sizeof(ut));
@@ -441,17 +439,9 @@ static void log_btmp(struct login_context *cxt)
if (cxt->tty_name)
xstrncpy(ut.ut_line, cxt->tty_name, sizeof(ut.ut_line));
-#if defined(_HAVE_UT_TV) /* in <utmpbits.h> included by <utmp.h> */
gettimeofday(&tv, NULL);
ut.ut_tv.tv_sec = tv.tv_sec;
ut.ut_tv.tv_usec = tv.tv_usec;
-#else
- {
- time_t t;
- time(&t);
- ut.ut_time = t; /* ut_time is not always a time_t */
- }
-#endif
ut.ut_type = LOGIN_PROCESS; /* XXX doesn't matter */
ut.ut_pid = cxt->pid;
@@ -614,18 +604,9 @@ static void log_utmp(struct login_context *cxt)
if (cxt->tty_name)
xstrncpy(ut.ut_line, cxt->tty_name, sizeof(ut.ut_line));
-#ifdef _HAVE_UT_TV /* in <utmpbits.h> included by <utmp.h> */
gettimeofday(&tv, NULL);
ut.ut_tv.tv_sec = tv.tv_sec;
ut.ut_tv.tv_usec = tv.tv_usec;
-#else
- {
- time_t t;
- time(&t);
- ut.ut_time = t; /* ut_time is not always a time_t */
- /* glibc2 #defines it as ut_tv.tv_sec */
- }
-#endif
ut.ut_type = USER_PROCESS;
ut.ut_pid = cxt->pid;
if (cxt->hostname) {
diff --git a/login-utils/su-common.c b/login-utils/su-common.c
index ff20a2f47..c48d9510e 100644
--- a/login-utils/su-common.c
+++ b/login-utils/su-common.c
@@ -198,17 +198,9 @@ static void log_btmp(struct passwd const *pw)
if (tty_name)
xstrncpy(ut.ut_line, tty_name, sizeof(ut.ut_line));
-#if defined(_HAVE_UT_TV) /* in <utmpbits.h> included by <utmp.h> */
gettimeofday(&tv, NULL);
ut.ut_tv.tv_sec = tv.tv_sec;
ut.ut_tv.tv_usec = tv.tv_usec;
-#else
- {
- time_t t;
- time(&t);
- ut.ut_time = t; /* ut_time is not always a time_t */
- }
-#endif
ut.ut_type = LOGIN_PROCESS; /* XXX doesn't matter */
ut.ut_pid = getpid();
diff --git a/login-utils/utmpdump.c b/login-utils/utmpdump.c
index cf8a50d8f..8f438b001 100644
--- a/login-utils/utmpdump.c
+++ b/login-utils/utmpdump.c
@@ -71,7 +71,6 @@ static time_t strtotime(const char *s_time)
return timegm(&tm);
}
-#if defined(_HAVE_UT_TV)
static suseconds_t strtousec(const char *s_time)
{
const char *s = strchr(s_time, ',');
@@ -79,7 +78,6 @@ static suseconds_t strtousec(const char *s_time)
return (suseconds_t) atoi(s + 1);
return 0;
}
-#endif
#define cleanse(x) xcleanse(x, sizeof(x))
static void xcleanse(char *s, int len)
@@ -287,12 +285,10 @@ static void undump(FILE *in, FILE *out)
inet_pton(AF_INET, s_addr, &(ut.ut_addr_v6));
else
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
+
ignore_result( fwrite(&ut, sizeof(ut), 1, out) );
++count;