1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <stdbool.h>
5 #include <sys/types.h>
6
7 #include "time-util.h"
8 #include "util.h"
9
10 #if ENABLE_UTMP
11 #include <utmpx.h>
12
13 int utmp_get_runlevel(int *runlevel, int *previous);
14
15 int utmp_put_shutdown(void);
16 int utmp_put_reboot(usec_t timestamp);
17 int utmp_put_runlevel(int runlevel, int previous);
18
19 int utmp_put_dead_process(const char *id, pid_t pid, int code, int status);
20 int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line, int ut_type, const char *user);
21
22 int utmp_wall(
23 const char *message,
24 const char *username,
25 const char *origin_tty,
26 bool (*match_tty)(const char *tty, void *userdata),
27 void *userdata);
28
utxent_start(void)29 static inline bool utxent_start(void) {
30 setutxent();
31 return true;
32 }
utxent_cleanup(bool * initialized)33 static inline void utxent_cleanup(bool *initialized) {
34 if (initialized)
35 endutxent();
36 }
37
38 #else /* ENABLE_UTMP */
39
utmp_get_runlevel(int * runlevel,int * previous)40 static inline int utmp_get_runlevel(int *runlevel, int *previous) {
41 return -ESRCH;
42 }
utmp_put_shutdown(void)43 static inline int utmp_put_shutdown(void) {
44 return 0;
45 }
utmp_put_reboot(usec_t timestamp)46 static inline int utmp_put_reboot(usec_t timestamp) {
47 return 0;
48 }
utmp_put_runlevel(int runlevel,int previous)49 static inline int utmp_put_runlevel(int runlevel, int previous) {
50 return 0;
51 }
utmp_put_dead_process(const char * id,pid_t pid,int code,int status)52 static inline int utmp_put_dead_process(const char *id, pid_t pid, int code, int status) {
53 return 0;
54 }
utmp_put_init_process(const char * id,pid_t pid,pid_t sid,const char * line,int ut_type,const char * user)55 static inline int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line, int ut_type, const char *user) {
56 return 0;
57 }
utmp_wall(const char * message,const char * username,const char * origin_tty,bool (* match_tty)(const char * tty,void * userdata),void * userdata)58 static inline int utmp_wall(
59 const char *message,
60 const char *username,
61 const char *origin_tty,
62 bool (*match_tty)(const char *tty, void *userdata),
63 void *userdata) {
64 return 0;
65 }
66
67 #endif /* ENABLE_UTMP */
68