#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
*/
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)
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)
* 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);
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;
}
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:
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:
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:
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)
* 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;
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));
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;
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) {
return timegm(&tm);
}
-#if defined(_HAVE_UT_TV)
static suseconds_t strtousec(const char *s_time)
{
const char *s = strchr(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)
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;