mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
Make our utmpx more like System V.
When booting the system, truncate the utx.active file, but do write the
BOOT_TIME record into it afterwards. This allows one to obtain the boot
time of the system as follows:
struct utmpx u1 = { .ut_type = BOOT_TIME }, *u2;
setutxent();
u2 = getutxid(&u1);
Now, the boot time is stored in u2->ut_tv, just like on Linux and other
systems.
We don't open the utx.active file with O_EXLOCK. It's rather unlikely
that other applications use this database at the same time and I want to
prevent the possibility of deadlocks in init(8).
Discussed with: pluknet
This commit is contained in:
parent
703dec68bf
commit
c5cf53fc3e
2 changed files with 20 additions and 3 deletions
|
|
@ -301,7 +301,6 @@ The value of
|
|||
determines which databases are modified.
|
||||
.Pp
|
||||
Entries of type
|
||||
.Dv BOOT_TIME ,
|
||||
.Dv SHUTDOWN_TIME ,
|
||||
.Dv OLD_TIME
|
||||
and
|
||||
|
|
@ -335,7 +334,7 @@ In addition, entries of type
|
|||
.Dv BOOT_TIME
|
||||
and
|
||||
.Dv SHUTDOWN_TIME
|
||||
will cause all entries in
|
||||
will cause all existing entries in
|
||||
.Pa /var/run/utx.active
|
||||
to be discarded.
|
||||
.Pp
|
||||
|
|
|
|||
|
|
@ -86,6 +86,9 @@ utx_active_add(const struct futx *fu)
|
|||
return (-1);
|
||||
while (fread(&fe, sizeof(fe), 1, fp) == 1) {
|
||||
switch (fe.fu_type) {
|
||||
case BOOT_TIME:
|
||||
/* Leave these intact. */
|
||||
break;
|
||||
case USER_PROCESS:
|
||||
case INIT_PROCESS:
|
||||
case LOGIN_PROCESS:
|
||||
|
|
@ -170,6 +173,19 @@ utx_active_remove(struct futx *fu)
|
|||
return (ret);
|
||||
}
|
||||
|
||||
static void
|
||||
utx_active_init(const struct futx *fu)
|
||||
{
|
||||
int fd;
|
||||
|
||||
/* Initialize utx.active with a single BOOT_TIME record. */
|
||||
fd = _open(_PATH_UTX_ACTIVE, O_CREAT|O_RDWR|O_TRUNC, 0644);
|
||||
if (fd < 0)
|
||||
return;
|
||||
_write(fd, fu, sizeof(*fu));
|
||||
_close(fd);
|
||||
}
|
||||
|
||||
static void
|
||||
utx_active_purge(void)
|
||||
{
|
||||
|
|
@ -277,9 +293,11 @@ pututxline(const struct utmpx *utmpx)
|
|||
|
||||
switch (fu.fu_type) {
|
||||
case BOOT_TIME:
|
||||
utx_active_init(&fu);
|
||||
utx_lastlogin_upgrade();
|
||||
break;
|
||||
case SHUTDOWN_TIME:
|
||||
utx_active_purge();
|
||||
utx_lastlogin_upgrade();
|
||||
break;
|
||||
case OLD_TIME:
|
||||
case NEW_TIME:
|
||||
|
|
|
|||
Loading…
Reference in a new issue