1 /* Declarations for GNU's read utmp module.
3 Copyright (C) 1992-2007, 2009-2018 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* Written by jla; revised by djm */
20 #ifndef __READUTMP_H__
21 # define __READUTMP_H__
23 # include <sys/types.h>
25 /* AIX 4.3.3 has both utmp.h and utmpx.h, but only struct utmp
26 has the ut_exit member. */
27 # if (HAVE_UTMPX_H && HAVE_UTMP_H && HAVE_STRUCT_UTMP_UT_EXIT \
28 && ! HAVE_STRUCT_UTMPX_UT_EXIT)
34 /* HPUX 10.20 needs utmp.h, for the definition of e.g., UTMP_FILE. */
37 # if defined _THREAD_SAFE && defined UTMP_DATA_INIT
38 /* When including both utmp.h and utmpx.h on AIX 4.3, with _THREAD_SAFE
39 defined, work around the duplicate struct utmp_data declaration. */
40 # define utmp_data gl_aix_4_3_workaround_utmp_data
43 # define UTMP_STRUCT_NAME utmpx
44 # define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_tv.tv_sec)
45 # define SET_UTMP_ENT setutxent
46 # define GET_UTMP_ENT getutxent
47 # define END_UTMP_ENT endutxent
48 # ifdef HAVE_UTMPXNAME
49 # define UTMP_NAME_FUNCTION utmpxname
50 # elif defined UTXDB_ACTIVE
51 # define UTMP_NAME_FUNCTION(x) setutxdb (UTXDB_ACTIVE, x)
54 # if HAVE_STRUCT_UTMPX_UT_EXIT_E_TERMINATION
55 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.e_termination)
57 # if HAVE_STRUCT_UTMPX_UT_EXIT_UT_TERMINATION
58 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.ut_termination)
60 # define UT_EXIT_E_TERMINATION(U) 0
64 # if HAVE_STRUCT_UTMPX_UT_EXIT_E_EXIT
65 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.e_exit)
67 # if HAVE_STRUCT_UTMPX_UT_EXIT_UT_EXIT
68 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.ut_exit)
70 # define UT_EXIT_E_EXIT(U) 0
77 # if !HAVE_DECL_GETUTENT
78 struct utmp
*getutent (void);
80 # define UTMP_STRUCT_NAME utmp
81 # define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_time)
82 # define SET_UTMP_ENT setutent
83 # define GET_UTMP_ENT getutent
84 # define END_UTMP_ENT endutent
86 # define UTMP_NAME_FUNCTION utmpname
89 # if HAVE_STRUCT_UTMP_UT_EXIT_E_TERMINATION
90 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.e_termination)
92 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_TERMINATION
93 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.ut_termination)
95 # define UT_EXIT_E_TERMINATION(U) 0
99 # if HAVE_STRUCT_UTMP_UT_EXIT_E_EXIT
100 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.e_exit)
102 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_EXIT
103 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.ut_exit)
105 # define UT_EXIT_E_EXIT(U) 0
111 /* Accessor macro for the member named ut_user or ut_name. */
114 # if HAVE_STRUCT_UTMPX_UT_USER
115 # define UT_USER(Utmp) ((Utmp)->ut_user)
117 # if HAVE_STRUCT_UTMPX_UT_NAME
119 # define UT_USER(Utmp) ((Utmp)->ut_name)
124 # if HAVE_STRUCT_UTMP_UT_USER
125 # define UT_USER(Utmp) ((Utmp)->ut_user)
127 # if HAVE_STRUCT_UTMP_UT_NAME
129 # define UT_USER(Utmp) ((Utmp)->ut_name)
134 # define HAVE_STRUCT_XTMP_UT_EXIT \
135 (HAVE_STRUCT_UTMP_UT_EXIT \
136 || HAVE_STRUCT_UTMPX_UT_EXIT)
138 # define HAVE_STRUCT_XTMP_UT_ID \
139 (HAVE_STRUCT_UTMP_UT_ID \
140 || HAVE_STRUCT_UTMPX_UT_ID)
142 # define HAVE_STRUCT_XTMP_UT_PID \
143 (HAVE_STRUCT_UTMP_UT_PID \
144 || HAVE_STRUCT_UTMPX_UT_PID)
146 typedef struct UTMP_STRUCT_NAME STRUCT_UTMP
;
148 enum { UT_USER_SIZE
= sizeof UT_USER ((STRUCT_UTMP
*) 0) };
150 # if !defined UTMP_FILE && defined _PATH_UTMP
151 # define UTMP_FILE _PATH_UTMP
154 # if !defined WTMP_FILE && defined _PATH_WTMP
155 # define WTMP_FILE _PATH_WTMP
158 # ifdef UTMPX_FILE /* Solaris, SysVr4 */
160 # define UTMP_FILE UTMPX_FILE
163 # ifdef WTMPX_FILE /* Solaris, SysVr4 */
165 # define WTMP_FILE WTMPX_FILE
169 # define UTMP_FILE "/etc/utmp"
173 # define WTMP_FILE "/etc/wtmp"
176 # if HAVE_STRUCT_XTMP_UT_PID
177 # define UT_PID(U) ((U)->ut_pid)
182 # if HAVE_STRUCT_UTMP_UT_TYPE || HAVE_STRUCT_UTMPX_UT_TYPE
183 # define UT_TYPE_EQ(U, V) ((U)->ut_type == (V))
184 # define UT_TYPE_NOT_DEFINED 0
186 # define UT_TYPE_EQ(U, V) 0
187 # define UT_TYPE_NOT_DEFINED 1
191 # define UT_TYPE_BOOT_TIME(U) UT_TYPE_EQ (U, BOOT_TIME)
193 # define UT_TYPE_BOOT_TIME(U) 0
197 # define UT_TYPE_USER_PROCESS(U) UT_TYPE_EQ (U, USER_PROCESS)
199 # define UT_TYPE_USER_PROCESS(U) 0
202 # define IS_USER_PROCESS(U) \
204 && (UT_TYPE_USER_PROCESS (U) \
205 || (UT_TYPE_NOT_DEFINED && UT_TIME_MEMBER (U) != 0)))
207 /* Options for read_utmp. */
210 READ_UTMP_CHECK_PIDS
= 1,
211 READ_UTMP_USER_PROCESS
= 2
214 char *extract_trimmed_name (const STRUCT_UTMP
*ut
);
215 int read_utmp (char const *file
, size_t *n_entries
, STRUCT_UTMP
**utmp_buf
,
218 #endif /* __READUTMP_H__ */