]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/utmp-wtmp.h
license: LGPL-2.1+ -> LGPL-2.1-or-later
[thirdparty/systemd.git] / src / shared / utmp-wtmp.h
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
29 static inline bool utxent_start(void) {
30 setutxent();
31 return true;
32 }
33 static inline void utxent_cleanup(bool *initialized) {
34 if (initialized)
35 endutxent();
36 }
37
38 #else /* ENABLE_UTMP */
39
40 static inline int utmp_get_runlevel(int *runlevel, int *previous) {
41 return -ESRCH;
42 }
43 static inline int utmp_put_shutdown(void) {
44 return 0;
45 }
46 static inline int utmp_put_reboot(usec_t timestamp) {
47 return 0;
48 }
49 static inline int utmp_put_runlevel(int runlevel, int previous) {
50 return 0;
51 }
52 static inline int utmp_put_dead_process(const char *id, pid_t pid, int code, int status) {
53 return 0;
54 }
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 }
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 */