aboutsummaryrefslogtreecommitdiff
path: root/login/getutid_r.c
diff options
context:
space:
mode:
Diffstat (limited to 'login/getutid_r.c')
-rw-r--r--login/getutid_r.c118
1 files changed, 36 insertions, 82 deletions
diff --git a/login/getutid_r.c b/login/getutid_r.c
index 81070157a4..52b83cd862 100644
--- a/login/getutid_r.c
+++ b/login/getutid_r.c
@@ -1,35 +1,45 @@
/* Copyright (C) 1996 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
-Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>
+ and Paul Janzen <pcj@primenet.com>, 1996.
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
-The GNU C Library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Library General Public License for more details.
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
#include <errno.h>
+#include <libc-lock.h>
#include <string.h>
#include <unistd.h>
#include <utmp.h>
+#include "utmp-private.h"
+
+
+/* We have to use the lock in getutent_r.c. */
+__libc_lock_define (extern, __libc_utmp_lock)
+
+/* The jump table is also in getutent_r.c. */
+extern struct utfuncs *__libc_utmp_jump_table;
+
-/* For implementing this function we don't use the getutent_r function
- because we can avoid the reposition on every new entry this way. */
int
-__getutid_r (const struct utmp *id, struct utmp **utmp,
- struct utmp_data *utmp_data)
+__getutid_r (const struct utmp *id, struct utmp *buffer, struct utmp **result)
{
#if (_HAVE_UT_ID - 0) && (_HAVE_UT_TYPE - 0)
+ int retval = -1;
+
/* Test whether ID has any of the legal types. */
if (id->ut_type != RUN_LVL && id->ut_type != BOOT_TIME
&& id->ut_type != OLD_TIME && id->ut_type != NEW_TIME
@@ -38,77 +48,21 @@ __getutid_r (const struct utmp *id, struct utmp **utmp,
/* No, using '<' and '>' for the test is not possible. */
{
__set_errno (EINVAL);
+ *result = NULL;
return -1;
}
- /* Open utmp file if not already done. */
- if (utmp_data->ut_fd == -1)
- {
- setutent_r (utmp_data);
- if (utmp_data->ut_fd == -1)
- return -1;
- }
-
- /* Position file correctly. */
- if (lseek (utmp_data->ut_fd, utmp_data->loc_utmp, SEEK_SET) == -1)
- return -1;
-
- if (id->ut_type == RUN_LVL || id->ut_type == BOOT_TIME
- || id->ut_type == OLD_TIME || id->ut_type == NEW_TIME)
- {
- /* Search for next entry with type RUN_LVL, BOOT_TIME,
- OLD_TIME, or NEW_TIME. */
-
- while (1)
- {
- /* Read the next entry. */
- if (read (utmp_data->ut_fd, &utmp_data->ubuf, sizeof (struct utmp))
- != sizeof (struct utmp))
- {
- utmp_data->loc_utmp = 0; /* Mark loc_utmp invalid. */
- __set_errno (ESRCH);
- return -1;
- }
-
- /* Update position pointer. */
- utmp_data->loc_utmp += sizeof (struct utmp);
+ __libc_lock_lock (__libc_utmp_lock);
- if (id->ut_type == utmp_data->ubuf.ut_type)
- break;
- }
- }
+ /* Not yet initialized. */
+ if ((*__libc_utmp_jump_table->setutent) (0))
+ retval = (*__libc_utmp_jump_table->getutid_r) (id, buffer, result);
else
- {
- /* Search for the next entry with the specified ID and with type
- INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS. */
-
- while (1)
- {
- /* Read the next entry. */
- if (read (utmp_data->ut_fd, &utmp_data->ubuf, sizeof (struct utmp))
- != sizeof (struct utmp))
- {
- utmp_data->loc_utmp = 0; /* Mark loc_utmp invalid. */
- __set_errno (ESRCH);
- return -1;
- }
-
- /* Update position pointer. */
- utmp_data->loc_utmp += sizeof (struct utmp);
-
- if (( utmp_data->ubuf.ut_type == INIT_PROCESS
- || utmp_data->ubuf.ut_type == LOGIN_PROCESS
- || utmp_data->ubuf.ut_type == USER_PROCESS
- || utmp_data->ubuf.ut_type == DEAD_PROCESS)
- && (strncmp (utmp_data->ubuf.ut_id, id->ut_id, sizeof id->ut_id)
- == 0))
- break;
- }
- }
+ *result = NULL;
- *utmp = &utmp_data->ubuf;
+ __libc_lock_unlock (__libc_utmp_lock);
- return 0;
+ return retval;
#else /* !_HAVE_UT_ID && !_HAVE_UT_TYPE */
__set_errno (ENOSYS);
return -1;