1 /* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>
4 and Paul Janzen <pcj@primenet.com>, 1996.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include <libc-lock.h>
28 #include "utmp-private.h"
31 /* The various backends we have. */
32 static int setutent_unknown (int reset
);
33 static int getutent_r_unknown (struct utmp
*buffer
, struct utmp
**result
);
34 static struct utmp
*pututline_unknown (const struct utmp
*data
);
35 static void endutent_unknown (void);
37 /* Initial Jump table. */
38 struct utfuncs __libc_utmp_unknown_functions
=
49 /* Currently selected backend. */
50 struct utfuncs
*__libc_utmp_jump_table
= &__libc_utmp_unknown_functions
;
52 /* We need to protect the opening of the file. */
53 __libc_lock_define_initialized (, __libc_utmp_lock
)
59 __libc_lock_lock (__libc_utmp_lock
);
61 (void) (*__libc_utmp_jump_table
->setutent
) (1);
63 __libc_lock_unlock (__libc_utmp_lock
);
65 weak_alias (__setutent
, setutent
)
69 setutent_unknown (int reset
)
71 /* We have to test whether it is still not decided which backend to use. */
72 assert (__libc_utmp_jump_table
== &__libc_utmp_unknown_functions
);
74 /* See whether utmpd is running. */
75 if ((*__libc_utmp_daemon_functions
.setutent
) (reset
))
76 __libc_utmp_jump_table
= &__libc_utmp_daemon_functions
;
79 /* Use the normal file, but if the current file is _PATH_UTMP or
80 _PATH_WTMP and the corresponding extended file (with an extra
81 'x' added to the pathname) exists, we use the extended file,
82 because the original file is in a different format. */
83 if (strcmp (__libc_utmp_file_name
, _PATH_UTMP
) == 0
84 && __access (_PATH_UTMP
"x", F_OK
) == 0)
85 __utmpname (_PATH_UTMP
"x");
86 else if (strcmp (__libc_utmp_file_name
, _PATH_WTMP
) == 0
87 && __access (_PATH_WTMP
"x", F_OK
) == 0)
88 __utmpname (_PATH_WTMP
"x");
90 (*__libc_utmp_file_functions
.setutent
) (reset
);
91 __libc_utmp_jump_table
= &__libc_utmp_file_functions
;
101 __libc_lock_lock (__libc_utmp_lock
);
103 (*__libc_utmp_jump_table
->endutent
) ();
105 __libc_lock_unlock (__libc_utmp_lock
);
107 weak_alias (__endutent
, endutent
)
111 endutent_unknown (void)
113 /* Huh, how do we came here? Nothing to do. */
118 __getutent_r (struct utmp
*buffer
, struct utmp
**result
)
122 __libc_lock_lock (__libc_utmp_lock
);
124 retval
= (*__libc_utmp_jump_table
->getutent_r
) (buffer
, result
);
126 __libc_lock_unlock (__libc_utmp_lock
);
130 weak_alias (__getutent_r
, getutent_r
)
134 getutent_r_unknown (struct utmp
*buffer
, struct utmp
**result
)
136 /* It is not yet initialized. */
137 setutent_unknown (0);
139 return (*__libc_utmp_jump_table
->getutent_r
) (buffer
, result
);
144 __pututline (const struct utmp
*data
)
148 __libc_lock_lock (__libc_utmp_lock
);
150 buffer
= (*__libc_utmp_jump_table
->pututline
) (data
);
152 __libc_lock_unlock (__libc_utmp_lock
);
156 weak_alias (__pututline
, pututline
)
160 pututline_unknown (const struct utmp
*data
)
162 /* It is not yet initialized. */
163 setutent_unknown (0);
165 return (*__libc_utmp_jump_table
->pututline
) (data
);