blob: b3ce7c5ac1a45846ba9c20282dd9f1f111bc6d7e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/* ISC license. */
#include <skalibs/nonposix.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <utmpx.h>
#include <skalibs/strerr2.h>
#include <skalibs/tai.h>
#include "os.h"
#ifndef WTMPX_FILE
# include <utmp.h>
# ifdef WTMP_FILE
# define WTMPX_FILE WTMP_FILE
# else
# ifdef _PATH_WTMP
# define WTMPX_FILE _PATH_WTMP
# else
# define WTMPX_FILE "/var/log/wtmp"
# endif
# endif
#endif
#ifndef UT_NAMESIZE
# define UT_NAMESIZE 32
#endif
#ifndef UT_HOSTSIZE
# define UT_HOSTSIZE 256
#endif
void os_final_wtmp (int what)
{
struct utmpx utx =
{
.ut_type = RUN_LVL,
.ut_pid = getpid(),
.ut_line = "~",
.ut_id = "",
.ut_session = getsid(0)
} ;
strncpy(utx.ut_user, what == 3 ? "reboot" : "shutdown", UT_NAMESIZE) ;
if (gethostname(utx.ut_host, UT_HOSTSIZE) < 0)
{
utx.ut_host[0] = 0 ;
strerr_warnwu1sys("gethostname") ;
}
else utx.ut_host[UT_HOSTSIZE - 1] = 0 ;
/* glibc multilib can go fuck itself */
#ifdef __WORDSIZE_TIME64_COMPAT32
{
struct timeval tv ;
if (!timeval_from_tain(&tv, &STAMP))
strerr_warnwu1sys("timeval_from_tain") ;
utx.ut_tv.tv_sec = tv.tv_sec ;
utx.ut_tv.tv_usec = tv.tv_usec ;
}
#else
if (!timeval_from_tain(&utx.ut_tv, &STAMP))
strerr_warnwu1sys("timeval_from_tain") ;
#endif
updwtmpx(WTMPX_FILE, &utx) ;
}
|