summaryrefslogtreecommitdiff
path: root/login/getutent_r.c
diff options
context:
space:
mode:
Diffstat (limited to 'login/getutent_r.c')
-rw-r--r--login/getutent_r.c135
1 files changed, 85 insertions, 50 deletions
diff --git a/login/getutent_r.c b/login/getutent_r.c
index 98c5469463..96c458f3a3 100644
--- a/login/getutent_r.c
+++ b/login/getutent_r.c
@@ -18,20 +18,20 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <assert.h>
#include <bits/libc-lock.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
#include <utmp.h>
#include "utmp-private.h"
-/* The various backends we have. */
+/* Functions defined here. */
+static int setutent_unknown (void);
static int getutent_r_unknown (struct utmp *buffer, struct utmp **result);
+static int getutid_r_unknown (const struct utmp *line, struct utmp *buffer,
+ struct utmp **result);
+static int getutline_r_unknown (const struct utmp *id, struct utmp *buffer,
+ struct utmp **result);
static struct utmp *pututline_unknown (const struct utmp *data);
-static int setutent_unknown (void);
static void endutent_unknown (void);
/* Initial Jump table. */
@@ -39,8 +39,8 @@ struct utfuncs __libc_utmp_unknown_functions =
{
setutent_unknown,
getutent_r_unknown,
- NULL,
- NULL,
+ getutid_r_unknown,
+ getutline_r_unknown,
pututline_unknown,
endutent_unknown,
NULL
@@ -53,58 +53,99 @@ struct utfuncs *__libc_utmp_jump_table = &__libc_utmp_unknown_functions;
__libc_lock_define_initialized (, __libc_utmp_lock)
-void
-__setutent (void)
+static int
+setutent_unknown (void)
{
- __libc_lock_lock (__libc_utmp_lock);
+ int result;
- (*__libc_utmp_jump_table->setutent) ();
+ /* See whether utmpd is running. */
+ result = (*__libc_utmp_daemon_functions.setutent) ();
+ if (result)
+ __libc_utmp_jump_table = &__libc_utmp_daemon_functions;
+ else
+ {
+ result = (*__libc_utmp_file_functions.setutent) ();
+ if (result)
+ __libc_utmp_jump_table = &__libc_utmp_file_functions;
+ }
- __libc_lock_unlock (__libc_utmp_lock);
+ return result;
}
-weak_alias (__setutent, setutent)
-weak_alias (__setutent, setutxent)
-void
-__endutent (void)
+static int
+getutent_r_unknown (struct utmp *buffer, struct utmp **result)
{
- __libc_lock_lock (__libc_utmp_lock);
+ /* The backend was not yet initialized. */
+ if (setutent_unknown ())
+ return (*__libc_utmp_jump_table->getutent_r) (buffer, result);
- (*__libc_utmp_jump_table->endutent) ();
+ /* Not available. */
+ *result = NULL;
+ return -1;
+}
- __libc_lock_unlock (__libc_utmp_lock);
+
+static int
+getutid_r_unknown (const struct utmp *id, struct utmp *buffer,
+ struct utmp **result)
+{
+ /* The backend was not yet initialized. */
+ if (setutent_unknown ())
+ return (*__libc_utmp_jump_table->getutid_r) (id, buffer, result);
+
+ /* Not available. */
+ *result = NULL;
+ return -1;
}
-weak_alias (__endutent, endutent)
-weak_alias (__endutent, endutxent)
static int
-setutent_unknown (void)
+getutline_r_unknown (const struct utmp *line, struct utmp *buffer,
+ struct utmp **result)
{
- int result;
+ /* The backend was not yet initialized. */
+ if (setutent_unknown ())
+ return (*__libc_utmp_jump_table->getutline_r) (line, buffer, result);
- /* See whether utmpd is running. */
- result = (*__libc_utmp_daemon_functions.setutent) ();
- if (result)
- __libc_utmp_jump_table = &__libc_utmp_daemon_functions;
- else
- {
- result = (*__libc_utmp_file_functions.setutent) ();
- __libc_utmp_jump_table = &__libc_utmp_file_functions;
- }
+ /* Not available. */
+ *result = NULL;
+ return -1;
+}
- return result;
+
+static struct utmp *
+pututline_unknown (const struct utmp *data)
+{
+ /* The backend was not yet initialized. */
+ if (setutent_unknown ())
+ return (*__libc_utmp_jump_table->pututline) (data);
+
+ /* Not available. */
+ return NULL;
}
static void
endutent_unknown (void)
{
- /* Huh, how do we came here? Nothing to do. */
+ /* Nothing to do. */
}
+void
+__setutent (void)
+{
+ __libc_lock_lock (__libc_utmp_lock);
+
+ (*__libc_utmp_jump_table->setutent) ();
+
+ __libc_lock_unlock (__libc_utmp_lock);
+}
+weak_alias (__setutent, setutent)
+weak_alias (__setutent, setutxent)
+
+
int
__getutent_r (struct utmp *buffer, struct utmp **result)
{
@@ -121,16 +162,6 @@ __getutent_r (struct utmp *buffer, struct utmp **result)
weak_alias (__getutent_r, getutent_r)
-static int
-getutent_r_unknown (struct utmp *buffer, struct utmp **result)
-{
- /* It is not yet initialized. */
- __setutent ();
-
- return (*__libc_utmp_jump_table->getutent_r) (buffer, result);
-}
-
-
struct utmp *
__pututline (const struct utmp *data)
{
@@ -148,11 +179,15 @@ weak_alias (__pututline, pututline)
weak_alias (__pututline, pututxline)
-static struct utmp *
-pututline_unknown (const struct utmp *data)
+void
+__endutent (void)
{
- /* It is not yet initialized. */
- __setutent ();
+ __libc_lock_lock (__libc_utmp_lock);
- return (*__libc_utmp_jump_table->pututline) (data);
+ (*__libc_utmp_jump_table->endutent) ();
+ __libc_utmp_jump_table = &__libc_utmp_unknown_functions;
+
+ __libc_lock_unlock (__libc_utmp_lock);
}
+weak_alias (__endutent, endutent)
+weak_alias (__endutent, endutxent)