From fab0a3c99775d55b333555bdc353f97802d430f8 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Thu, 3 Dec 2009 16:33:47 +0000 Subject: [PATCH] Also implement ut_type. I thought we couldn't emulate this field, but we can derive this field by looking at special values for ut_host, ut_line and ut_name. --- lib/libulog/ulog.h | 17 ++++++++++++++++- lib/libulog/ulog_getutxent.3 | 22 ++++++++++++++++++++++ lib/libulog/ulog_getutxent.c | 15 +++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/lib/libulog/ulog.h b/lib/libulog/ulog.h index 2a613ddf46ca..fc95c3b99ae9 100644 --- a/lib/libulog/ulog.h +++ b/lib/libulog/ulog.h @@ -63,8 +63,23 @@ struct ulog_utmpx { char *ut_host; #if 0 pid_t ut_pid; - short ut_type; #endif + short ut_type; +#define EMPTY 0 +#if 0 +#define BOOT_TIME 1 +#endif +#define OLD_TIME 2 +#define NEW_TIME 3 +#if 0 +#define USER_PROCESS 4 +#define INIT_PROCESS 5 +#endif +#define LOGIN_PROCESS 6 +#define DEAD_PROCESS 7 + +#define SHUTDOWN_TIME 8 +#define REBOOT_TIME 9 struct timeval ut_tv; }; diff --git a/lib/libulog/ulog_getutxent.3 b/lib/libulog/ulog_getutxent.3 index da71596efa6c..6b4bf010d980 100644 --- a/lib/libulog/ulog_getutxent.3 +++ b/lib/libulog/ulog_getutxent.3 @@ -52,6 +52,7 @@ struct ulog_utmpx { char *ut_user; /* Username. */ char *ut_line; /* TTY device. */ char *ut_host; /* Remote hostname. */ + short ut_type; /* Type of entry. */ struct timeval ut_tv; /* Timestamp. */ }; .Ed @@ -67,6 +68,27 @@ directory. .It Fa ut_host An optional hostname of a remote system, if the login session is provided through a networked login service. +.It Fa ut_type +The +.Fa ut_type +field contains the type of the message, which may have one of the +following values: +.Bl -tag -width LOGIN_PROCESS +.It Dv EMPTY +No valid user accounting information. +.It Dv OLD_TIME +Identifies time when system clock changed. +.It Dv NEW_TIME +Identifies time after system clock changed. +.It Dv LOGIN_PROCESS +Identifies the session leader of a logged in user. +.It Dv DEAD_PROCESS +Identifies a session leader who has exited. +.It Dv SHUTDOWN_TIME +Identifies time when system was shut down. +.It Dv REBOOT_TIME +Identifies time when system was rebooted. +.El .It Fa ut_tv Timestamp indicating when the entry was last modified. .El diff --git a/lib/libulog/ulog_getutxent.c b/lib/libulog/ulog_getutxent.c index f13001c0aad4..082f60e50350 100644 --- a/lib/libulog/ulog_getutxent.c +++ b/lib/libulog/ulog_getutxent.c @@ -70,6 +70,21 @@ ulog_getutxent(void) COPY_STRING(host); utx.ut_tv.tv_sec = _time32_to_time(ut.ut_time); utx.ut_tv.tv_usec = 0; +#define MATCH(field, value) (strcmp(utx.ut_ ## field, (value)) == 0) + if (MATCH(user, "date") && MATCH(line, "|")) + utx.ut_type = OLD_TIME; + else if (MATCH(user, "date") && MATCH(line, "{")) + utx.ut_type = NEW_TIME; + else if (MATCH(user, "shutdown") && MATCH(line, "~")) + utx.ut_type = SHUTDOWN_TIME; + else if (MATCH(user, "reboot") && MATCH(line, "~")) + utx.ut_type = REBOOT_TIME; + else if (MATCH(user, "") && MATCH(host, "")) + utx.ut_type = DEAD_PROCESS; + else if (!MATCH(user, "")) + utx.ut_type = LOGIN_PROCESS; + else + utx.ut_type = EMPTY; return (&utx); }