root/maint/gnulib/lib/readutmp.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /* Declarations for GNU's read utmp module.
   2 
   3    Copyright (C) 1992-2007, 2009-2021 Free Software Foundation, Inc.
   4 
   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.
   9 
  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.
  14 
  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/>.  */
  17 
  18 /* Written by jla; revised by djm */
  19 
  20 #ifndef __READUTMP_H__
  21 # define __READUTMP_H__
  22 
  23 # include <stdlib.h>
  24 # include <sys/types.h>
  25 
  26 /* AIX 4.3.3 has both utmp.h and utmpx.h, but only struct utmp
  27    has the ut_exit member.  */
  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     /* HPUX 10.20 needs utmp.h, for the definition of e.g., UTMP_FILE.  */
  36 #   include <utmp.h>
  37 #  endif
  38 #  if defined _THREAD_SAFE && defined UTMP_DATA_INIT
  39     /* When including both utmp.h and utmpx.h on AIX 4.3, with _THREAD_SAFE
  40        defined, work around the duplicate struct utmp_data declaration.  */
  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 /* Accessor macro for the member named ut_user or ut_name.  */
 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 /* Solaris, SysVr4 */
 160 #  undef UTMP_FILE
 161 #  define UTMP_FILE UTMPX_FILE
 162 # endif
 163 
 164 # ifdef WTMPX_FILE /* Solaris, SysVr4 */
 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 /* Options for read_utmp.  */
 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 /* FIXME: This header should use idx_t, not size_t.  */
 220 int read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf,
 221                int options);
 222 
 223 #endif /* __READUTMP_H__ */

/* [previous][next][first][last][top][bottom][index][help] */