1 /* Declarations for GNU's read utmp module.
3 Copyright (C) 1992-2007 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 <http://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
52 # if HAVE_STRUCT_UTMPX_UT_EXIT_E_TERMINATION
53 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.e_termination)
55 # if HAVE_STRUCT_UTMPX_UT_EXIT_UT_TERMINATION
56 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.ut_termination)
58 # define UT_EXIT_E_TERMINATION(U) 0
62 # if HAVE_STRUCT_UTMPX_UT_EXIT_E_EXIT
63 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.e_exit)
65 # if HAVE_STRUCT_UTMPX_UT_EXIT_UT_EXIT
66 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.ut_exit)
68 # define UT_EXIT_E_EXIT(U) 0
75 # if !HAVE_DECL_GETUTENT
76 struct utmp *getutent();
78 # define UTMP_STRUCT_NAME utmp
79 # define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_time)
80 # define SET_UTMP_ENT setutent
81 # define GET_UTMP_ENT getutent
82 # define END_UTMP_ENT endutent
84 # define UTMP_NAME_FUNCTION utmpname
87 # if HAVE_STRUCT_UTMP_UT_EXIT_E_TERMINATION
88 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.e_termination)
90 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_TERMINATION
91 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.ut_termination)
93 # define UT_EXIT_E_TERMINATION(U) 0
97 # if HAVE_STRUCT_UTMP_UT_EXIT_E_EXIT
98 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.e_exit)
100 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_EXIT
101 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.ut_exit)
103 # define UT_EXIT_E_EXIT(U) 0
109 /* Accessor macro for the member named ut_user or ut_name. */
112 # if HAVE_STRUCT_UTMPX_UT_USER
113 # define UT_USER(Utmp) ((Utmp)->ut_user)
115 # if HAVE_STRUCT_UTMPX_UT_NAME
117 # define UT_USER(Utmp) ((Utmp)->ut_name)
122 # if HAVE_STRUCT_UTMP_UT_USER
123 # define UT_USER(Utmp) ((Utmp)->ut_user)
125 # if HAVE_STRUCT_UTMP_UT_NAME
127 # define UT_USER(Utmp) ((Utmp)->ut_name)
132 # define HAVE_STRUCT_XTMP_UT_EXIT \
133 (HAVE_STRUCT_UTMP_UT_EXIT \
134 || HAVE_STRUCT_UTMPX_UT_EXIT)
136 # define HAVE_STRUCT_XTMP_UT_ID \
137 (HAVE_STRUCT_UTMP_UT_ID \
138 || HAVE_STRUCT_UTMPX_UT_ID)
140 # define HAVE_STRUCT_XTMP_UT_PID \
141 (HAVE_STRUCT_UTMP_UT_PID \
142 || HAVE_STRUCT_UTMPX_UT_PID)
144 typedef struct UTMP_STRUCT_NAME STRUCT_UTMP;
146 enum { UT_USER_SIZE = sizeof UT_USER ((STRUCT_UTMP *) 0) };
148 # if !defined UTMP_FILE && defined _PATH_UTMP
149 # define UTMP_FILE _PATH_UTMP
152 # if !defined WTMP_FILE && defined _PATH_WTMP
153 # define WTMP_FILE _PATH_WTMP
156 # ifdef UTMPX_FILE /* Solaris, SysVr4 */
158 # define UTMP_FILE UTMPX_FILE
161 # ifdef WTMPX_FILE /* Solaris, SysVr4 */
163 # define WTMP_FILE WTMPX_FILE
167 # define UTMP_FILE "/etc/utmp"
171 # define WTMP_FILE "/etc/wtmp"
174 # if HAVE_STRUCT_XTMP_UT_PID
175 # define UT_PID(U) ((U)->ut_pid)
180 # if HAVE_STRUCT_UTMP_UT_TYPE || HAVE_STRUCT_UTMPX_UT_TYPE
181 # define UT_TYPE_EQ(U, V) ((U)->ut_type == (V))
182 # define UT_TYPE_NOT_DEFINED 0
184 # define UT_TYPE_EQ(U, V) 0
185 # define UT_TYPE_NOT_DEFINED 1
189 # define UT_TYPE_BOOT_TIME(U) UT_TYPE_EQ (U, BOOT_TIME)
191 # define UT_TYPE_BOOT_TIME(U) 0
195 # define UT_TYPE_USER_PROCESS(U) UT_TYPE_EQ (U, USER_PROCESS)
197 # define UT_TYPE_USER_PROCESS(U) 0
200 # define IS_USER_PROCESS(U) \
202 && (UT_TYPE_USER_PROCESS (U) \
203 || (UT_TYPE_NOT_DEFINED && UT_TIME_MEMBER (U) != 0)))
205 /* Options for read_utmp. */
208 READ_UTMP_CHECK_PIDS = 1,
209 READ_UTMP_USER_PROCESS = 2
212 char *extract_trimmed_name (const STRUCT_UTMP *ut);
213 int read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf,
216 #endif /* __READUTMP_H__ */