1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #ifndef __READUTMP_H__
21 # define __READUTMP_H__
22
23 # include <stdlib.h>
24 # include <sys/types.h>
25
26
27
28 # if (HAVE_UTMPX_H && HAVE_UTMP_H && HAVE_STRUCT_UTMP_UT_EXIT \
29 && ! HAVE_STRUCT_UTMPX_UT_EXIT)
30 # undef HAVE_UTMPX_H
31 # endif
32
33 # if HAVE_UTMPX_H
34 # if HAVE_UTMP_H
35
36 # include <utmp.h>
37 # endif
38 # if defined _THREAD_SAFE && defined UTMP_DATA_INIT
39
40
41 # define utmp_data gl_aix_4_3_workaround_utmp_data
42 # endif
43 # include <utmpx.h>
44 # define UTMP_STRUCT_NAME utmpx
45 # define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_tv.tv_sec)
46 # define SET_UTMP_ENT setutxent
47 # define GET_UTMP_ENT getutxent
48 # define END_UTMP_ENT endutxent
49 # ifdef HAVE_UTMPXNAME
50 # define UTMP_NAME_FUNCTION utmpxname
51 # elif defined UTXDB_ACTIVE
52 # define UTMP_NAME_FUNCTION(x) setutxdb (UTXDB_ACTIVE, x)
53 # endif
54
55 # if HAVE_STRUCT_UTMPX_UT_EXIT_E_TERMINATION
56 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.e_termination)
57 # else
58 # if HAVE_STRUCT_UTMPX_UT_EXIT_UT_TERMINATION
59 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.ut_termination)
60 # else
61 # define UT_EXIT_E_TERMINATION(U) 0
62 # endif
63 # endif
64
65 # if HAVE_STRUCT_UTMPX_UT_EXIT_E_EXIT
66 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.e_exit)
67 # else
68 # if HAVE_STRUCT_UTMPX_UT_EXIT_UT_EXIT
69 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.ut_exit)
70 # else
71 # define UT_EXIT_E_EXIT(U) 0
72 # endif
73 # endif
74
75 # elif HAVE_UTMP_H
76
77 # include <utmp.h>
78 # if !HAVE_DECL_GETUTENT
79 struct utmp *getutent (void);
80 # endif
81 # define UTMP_STRUCT_NAME utmp
82 # define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_time)
83 # define SET_UTMP_ENT setutent
84 # define GET_UTMP_ENT getutent
85 # define END_UTMP_ENT endutent
86 # ifdef HAVE_UTMPNAME
87 # define UTMP_NAME_FUNCTION utmpname
88 # endif
89
90 # if HAVE_STRUCT_UTMP_UT_EXIT_E_TERMINATION
91 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.e_termination)
92 # else
93 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_TERMINATION
94 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.ut_termination)
95 # else
96 # define UT_EXIT_E_TERMINATION(U) 0
97 # endif
98 # endif
99
100 # if HAVE_STRUCT_UTMP_UT_EXIT_E_EXIT
101 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.e_exit)
102 # else
103 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_EXIT
104 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.ut_exit)
105 # else
106 # define UT_EXIT_E_EXIT(U) 0
107 # endif
108 # endif
109
110 # endif
111
112
113 # if HAVE_UTMPX_H
114
115 # if HAVE_STRUCT_UTMPX_UT_USER
116 # define UT_USER(Utmp) ((Utmp)->ut_user)
117 # endif
118 # if HAVE_STRUCT_UTMPX_UT_NAME
119 # undef UT_USER
120 # define UT_USER(Utmp) ((Utmp)->ut_name)
121 # endif
122
123 # elif HAVE_UTMP_H
124
125 # if HAVE_STRUCT_UTMP_UT_USER
126 # define UT_USER(Utmp) ((Utmp)->ut_user)
127 # endif
128 # if HAVE_STRUCT_UTMP_UT_NAME
129 # undef UT_USER
130 # define UT_USER(Utmp) ((Utmp)->ut_name)
131 # endif
132
133 # endif
134
135 # define HAVE_STRUCT_XTMP_UT_EXIT \
136 (HAVE_STRUCT_UTMP_UT_EXIT \
137 || HAVE_STRUCT_UTMPX_UT_EXIT)
138
139 # define HAVE_STRUCT_XTMP_UT_ID \
140 (HAVE_STRUCT_UTMP_UT_ID \
141 || HAVE_STRUCT_UTMPX_UT_ID)
142
143 # define HAVE_STRUCT_XTMP_UT_PID \
144 (HAVE_STRUCT_UTMP_UT_PID \
145 || HAVE_STRUCT_UTMPX_UT_PID)
146
147 typedef struct UTMP_STRUCT_NAME STRUCT_UTMP;
148
149 enum { UT_USER_SIZE = sizeof UT_USER ((STRUCT_UTMP *) 0) };
150
151 # if !defined UTMP_FILE && defined _PATH_UTMP
152 # define UTMP_FILE _PATH_UTMP
153 # endif
154
155 # if !defined WTMP_FILE && defined _PATH_WTMP
156 # define WTMP_FILE _PATH_WTMP
157 # endif
158
159 # ifdef UTMPX_FILE
160 # undef UTMP_FILE
161 # define UTMP_FILE UTMPX_FILE
162 # endif
163
164 # ifdef WTMPX_FILE
165 # undef WTMP_FILE
166 # define WTMP_FILE WTMPX_FILE
167 # endif
168
169 # ifndef UTMP_FILE
170 # define UTMP_FILE "/etc/utmp"
171 # endif
172
173 # ifndef WTMP_FILE
174 # define WTMP_FILE "/etc/wtmp"
175 # endif
176
177 # if HAVE_STRUCT_XTMP_UT_PID
178 # define UT_PID(U) ((U)->ut_pid)
179 # else
180 # define UT_PID(U) 0
181 # endif
182
183 # if HAVE_STRUCT_UTMP_UT_TYPE || HAVE_STRUCT_UTMPX_UT_TYPE
184 # define UT_TYPE_EQ(U, V) ((U)->ut_type == (V))
185 # define UT_TYPE_NOT_DEFINED 0
186 # else
187 # define UT_TYPE_EQ(U, V) 0
188 # define UT_TYPE_NOT_DEFINED 1
189 # endif
190
191 # ifdef BOOT_TIME
192 # define UT_TYPE_BOOT_TIME(U) UT_TYPE_EQ (U, BOOT_TIME)
193 # else
194 # define UT_TYPE_BOOT_TIME(U) 0
195 # endif
196
197 # ifdef USER_PROCESS
198 # define UT_TYPE_USER_PROCESS(U) UT_TYPE_EQ (U, USER_PROCESS)
199 # else
200 # define UT_TYPE_USER_PROCESS(U) 0
201 # endif
202
203 # define IS_USER_PROCESS(U) \
204 (UT_USER (U)[0] \
205 && (UT_TYPE_USER_PROCESS (U) \
206 || (UT_TYPE_NOT_DEFINED && UT_TIME_MEMBER (U) != 0)))
207
208
209 enum
210 {
211 READ_UTMP_CHECK_PIDS = 1,
212 READ_UTMP_USER_PROCESS = 2
213 };
214
215 char *extract_trimmed_name (const STRUCT_UTMP *ut)
216 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
217 _GL_ATTRIBUTE_RETURNS_NONNULL;
218
219
220 int read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf,
221 int options);
222
223 #endif