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.
This commit is contained in:
Ed Schouten 2009-12-03 16:33:47 +00:00
parent e72b7e5bba
commit fab0a3c997
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=200065
3 changed files with 53 additions and 1 deletions

View file

@ -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;
};

View file

@ -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

View file

@ -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);
}