summaryrefslogtreecommitdiff
path: root/libc/misc/utmp
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@openadk.org>2015-03-29 04:50:56 -0500
committerWaldemar Brodkorb <wbx@openadk.org>2015-03-29 04:50:56 -0500
commitcd5f92704e1e17bbc0c15d197f3bc236c7dc9bf2 (patch)
tree1400302b543e4528aedea5d72731983559cfcf36 /libc/misc/utmp
parentad2bffbf1926051ef333f9899344f6bddf2c03cf (diff)
parent24946289317ea23bb0d1814cca0a499a905f7d6f (diff)
merge uClibc git master
Diffstat (limited to 'libc/misc/utmp')
-rw-r--r--libc/misc/utmp/Makefile.in4
-rw-r--r--libc/misc/utmp/utent.c312
-rw-r--r--libc/misc/utmp/utxent.c109
-rw-r--r--libc/misc/utmp/wtent.c59
4 files changed, 149 insertions, 335 deletions
diff --git a/libc/misc/utmp/Makefile.in b/libc/misc/utmp/Makefile.in
index 535efb150..6c54ade96 100644
--- a/libc/misc/utmp/Makefile.in
+++ b/libc/misc/utmp/Makefile.in
@@ -7,8 +7,8 @@
subdirs += libc/misc/utmp
-CSRC-y := utent.c wtent.c
-CSRC-$(UCLIBC_HAS_UTMPX) += utxent.c
+CSRC-y :=
+CSRC-$(if $(findstring y,$(UCLIBC_HAS_UTMP)$(UCLIBC_HAS_UTMPX)),y) += utent.c
MISC_UTMP_DIR := $(top_srcdir)libc/misc/utmp
MISC_UTMP_OUT := $(top_builddir)libc/misc/utmp
diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c
index a35bb2b84..3671bb05c 100644
--- a/libc/misc/utmp/utent.c
+++ b/libc/misc/utmp/utent.c
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
/* utent.c <ndf@linux.mit.edu> */
/* Let it be known that this is very possibly the worst standard ever. HP-UX
does one thing, someone else does another, linux another... If anyone
@@ -18,230 +19,211 @@
#include <paths.h>
#include <errno.h>
#include <string.h>
-#include <utmp.h>
-#ifdef __UCLIBC_HAS_UTMPX__
-# include <utmpx.h>
-#endif
+#include "internal/utmp.h"
#include <not-cancel.h>
-
#include <bits/uClibc_mutex.h>
+
__UCLIBC_MUTEX_STATIC(utmplock, PTHREAD_MUTEX_INITIALIZER);
/* Some global crap */
static int static_fd = -1;
-static struct utmp static_utmp;
-static const char default_file_name[] = _PATH_UTMP;
-static const char *static_ut_name = default_file_name;
+static struct UT static_utmp;
+static const char default_file[] = __DEFAULT_PATH_UTMP;
+static const char *current_file = default_file;
/* This function must be called with the LOCK held */
-static void __setutent_unlocked(void)
+static void __set_unlocked(void)
{
- if (static_fd < 0) {
- static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC);
if (static_fd < 0) {
- static_fd = open_not_cancel_2(static_ut_name, O_RDONLY | O_CLOEXEC);
- if (static_fd < 0) {
- return; /* static_fd remains < 0 */
- }
- }
+ static_fd = open_not_cancel_2(current_file, O_RDWR | O_CLOEXEC);
+ if (static_fd < 0) {
+ static_fd = open_not_cancel_2(current_file, O_RDONLY | O_CLOEXEC);
+ if (static_fd < 0) {
+ return; /* static_fd remains < 0 */
+ }
+ }
#ifndef __ASSUME_O_CLOEXEC
- /* Make sure the file will be closed on exec() */
- fcntl_not_cancel(static_fd, F_SETFD, FD_CLOEXEC);
+ /* Make sure the file will be closed on exec() */
+ fcntl_not_cancel(static_fd, F_SETFD, FD_CLOEXEC);
#endif
- return;
- }
- lseek(static_fd, 0, SEEK_SET);
+ return;
+ }
+ lseek(static_fd, 0, SEEK_SET);
}
#if defined __UCLIBC_HAS_THREADS__
-static void __setutent(void)
+void set(void)
{
- __UCLIBC_MUTEX_LOCK(utmplock);
- __setutent_unlocked();
- __UCLIBC_MUTEX_UNLOCK(utmplock);
+ __UCLIBC_MUTEX_LOCK(utmplock);
+ __set_unlocked();
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
}
#else
-static void __setutent(void);
-strong_alias(__setutent_unlocked,__setutent)
-#endif
-strong_alias(__setutent,setutent)
-
-#ifdef __UCLIBC_HAS_UTMPX__
-strong_alias(__setutent,setutxent)
+strong_alias(__set_unlocked,set)
#endif
+/* not used in libc_hidden_def(set) */
+other(setutxent,setutent)
/* This function must be called with the LOCK held */
-static struct utmp *__getutent_unlocked(void)
+static struct UT *__get_unlocked(void)
{
- if (static_fd < 0) {
- __setutent();
if (static_fd < 0) {
- return NULL;
+ __set_unlocked();
+ if (static_fd < 0)
+ return NULL;
}
- }
- if (read_not_cancel(static_fd, &static_utmp, sizeof(static_utmp)) == sizeof(static_utmp)) {
- return &static_utmp;
- }
+ if (read_not_cancel(static_fd, &static_utmp,
+ sizeof(static_utmp)) == sizeof(static_utmp)) {
+ return &static_utmp;
+ }
- return NULL;
+ return NULL;
}
#if defined __UCLIBC_HAS_THREADS__
-static struct utmp *__getutent(void)
+struct UT *get(void)
{
- struct utmp *ret;
+ struct UT *ret;
- __UCLIBC_MUTEX_LOCK(utmplock);
- ret = __getutent_unlocked();
- __UCLIBC_MUTEX_UNLOCK(utmplock);
- return ret;
+ __UCLIBC_MUTEX_LOCK(utmplock);
+ ret = __get_unlocked();
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
+ return ret;
}
#else
-static struct utmp *__getutent(void);
-strong_alias(__getutent_unlocked,__getutent)
+strong_alias(__get_unlocked,get)
#endif
-strong_alias(__getutent,getutent)
+/* not used in libc_hidden_def(get) */
+other(getutxent,getutent)
-#ifdef __UCLIBC_HAS_UTMPX__
-struct utmpx *getutxent(void)
+void end(void)
{
- return (struct utmpx *) __getutent ();
-}
-#endif
-
-static void __endutent(void)
-{
- __UCLIBC_MUTEX_LOCK(utmplock);
- if (static_fd >= 0)
- close_not_cancel_no_status(static_fd);
- static_fd = -1;
- __UCLIBC_MUTEX_UNLOCK(utmplock);
+ __UCLIBC_MUTEX_LOCK(utmplock);
+ if (static_fd >= 0)
+ close_not_cancel_no_status(static_fd);
+ static_fd = -1;
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
}
-strong_alias(__endutent,endutent)
-
-#ifdef __UCLIBC_HAS_UTMPX__
-strong_alias(__endutent,endutxent)
-#endif
+/* not used in libc_hidden_def(end) */
+other(endutxent,endutent)
/* This function must be called with the LOCK held */
-static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry)
+static struct UT *__getid_unlocked(const struct UT *utmp_entry)
{
- struct utmp *lutmp;
- unsigned type;
-
- /* We use the fact that constants we are interested in are: */
- /* RUN_LVL=1, ... OLD_TIME=4; INIT_PROCESS=5, ... USER_PROCESS=8 */
- type = utmp_entry->ut_type - 1;
- type /= 4;
-
- while ((lutmp = __getutent_unlocked()) != NULL) {
- if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) {
- /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */
- return lutmp;
+ struct UT *lutmp;
+ unsigned type;
+
+ /* We use the fact that constants we are interested in are: */
+ /* RUN_LVL=1, ... OLD_TIME=4; INIT_PROCESS=5, ... USER_PROCESS=8 */
+ type = utmp_entry->ut_type - 1;
+ type /= 4;
+
+ while ((lutmp = __get_unlocked()) != NULL) {
+ if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) {
+ /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */
+ return lutmp;
+ }
+ if (type == 1
+ && strncmp(lutmp->ut_id, utmp_entry->ut_id,
+ sizeof(lutmp->ut_id)) == 0) {
+ /* INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, DEAD_PROCESS */
+ return lutmp;
+ }
}
- if (type == 1 && strncmp(lutmp->ut_id, utmp_entry->ut_id, sizeof(lutmp->ut_id)) == 0) {
- /* INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, DEAD_PROCESS */
- return lutmp;
- }
- }
- return NULL;
+ return NULL;
}
#if defined __UCLIBC_HAS_THREADS__
-static struct utmp *__getutid(const struct utmp *utmp_entry)
+struct UT *getid(const struct UT *utmp_entry)
{
- struct utmp *ret;
+ struct UT *ret;
- __UCLIBC_MUTEX_LOCK(utmplock);
- ret = __getutid_unlocked(utmp_entry);
- __UCLIBC_MUTEX_UNLOCK(utmplock);
- return ret;
+ __UCLIBC_MUTEX_LOCK(utmplock);
+ ret = __getid_unlocked(utmp_entry);
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
+ return ret;
}
#else
-static struct utmp *__getutid(const struct utmp *utmp_entry);
-strong_alias(__getutid_unlocked,__getutid)
-#endif
-strong_alias(__getutid,getutid)
-
-#ifdef __UCLIBC_HAS_UTMPX__
-struct utmpx *getutxid(const struct utmpx *utmp_entry)
-{
- return (struct utmpx *) __getutid ((const struct utmp *) utmp_entry);
-}
+strong_alias(__getid_unlocked,getid)
#endif
+/* not used in libc_hidden_def(getid) */
+other(getutxid,getutid)
-static struct utmp *__getutline(const struct utmp *utmp_entry)
+struct UT *getline(const struct UT *utmp_entry)
{
- struct utmp *lutmp;
-
- __UCLIBC_MUTEX_LOCK(utmplock);
- while ((lutmp = __getutent_unlocked()) != NULL) {
- if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) {
- if (strncmp(lutmp->ut_line, utmp_entry->ut_line, sizeof(lutmp->ut_line)) == 0) {
- break;
- }
+ struct UT *lutmp;
+
+ __UCLIBC_MUTEX_LOCK(utmplock);
+ while ((lutmp = __get_unlocked()) != NULL) {
+ if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) {
+ if (strncmp(lutmp->ut_line, utmp_entry->ut_line,
+ sizeof(lutmp->ut_line)) == 0) {
+ break;
+ }
+ }
}
- }
- __UCLIBC_MUTEX_UNLOCK(utmplock);
- return lutmp;
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
+ return lutmp;
}
-strong_alias(__getutline,getutline)
+/* libc_hidden_def(getline) */
+other(getutxline,getutline)
-#ifdef __UCLIBC_HAS_UTMPX__
-struct utmpx *getutxline(const struct utmpx *utmp_entry)
+struct UT *putline(const struct UT *utmp_entry)
{
- return (struct utmpx *) __getutline ((const struct utmp *) utmp_entry);
+ __UCLIBC_MUTEX_LOCK(utmplock);
+ /* Ignore the return value. That way, if they've already positioned
+ the file pointer where they want it, everything will work out. */
+ lseek(static_fd, (off_t) - sizeof(struct UT), SEEK_CUR);
+
+ if (__getid_unlocked(utmp_entry) != NULL)
+ lseek(static_fd, (off_t) - sizeof(struct UT), SEEK_CUR);
+ else
+ lseek(static_fd, (off_t) 0, SEEK_END);
+ if (write(static_fd, utmp_entry, sizeof(struct UT))
+ != sizeof(struct UT))
+ utmp_entry = NULL;
+
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
+ return (struct UT *)utmp_entry;
}
-#endif
+/* not used in libc_hidden_def(putline) */
+other(pututxline,pututline)
-static struct utmp *__pututline(const struct utmp *utmp_entry)
+int name(const char *new_file)
{
- __UCLIBC_MUTEX_LOCK(utmplock);
- /* Ignore the return value. That way, if they've already positioned
- the file pointer where they want it, everything will work out. */
- lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR);
-
- if (__getutid_unlocked(utmp_entry) != NULL)
- lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR);
- else
- lseek(static_fd, (off_t) 0, SEEK_END);
- if (write(static_fd, utmp_entry, sizeof(struct utmp)) != sizeof(struct utmp))
- utmp_entry = NULL;
-
- __UCLIBC_MUTEX_UNLOCK(utmplock);
- return (struct utmp *)utmp_entry;
-}
-strong_alias(__pututline,pututline)
+ __UCLIBC_MUTEX_LOCK(utmplock);
+ if (new_file != NULL) {
+ if (current_file != default_file)
+ free((char *)current_file);
+ current_file = strdup(new_file);
+ if (current_file == NULL) {
+ /* We should probably whine about out-of-memory
+ * errors here... Instead just reset to the default */
+ current_file = default_file;
+ }
+ }
-#ifdef __UCLIBC_HAS_UTMPX__
-struct utmpx *pututxline (const struct utmpx *utmp_entry)
-{
- return (struct utmpx *) __pututline ((const struct utmp *) utmp_entry);
+ if (static_fd >= 0) {
+ close_not_cancel_no_status(static_fd);
+ static_fd = -1;
+ }
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
+ return 0; /* or maybe return -(current_file != new_file)? */
}
-#endif
+/* not used in libc_hidden_def(name) */
+other(utmpxname,utmpname)
-static int __utmpname(const char *new_ut_name)
+void updw(const char *wtmp_file, const struct UT *lutmp)
{
- __UCLIBC_MUTEX_LOCK(utmplock);
- if (new_ut_name != NULL) {
- if (static_ut_name != default_file_name)
- free((char *)static_ut_name);
- static_ut_name = strdup(new_ut_name);
- if (static_ut_name == NULL) {
- /* We should probably whine about out-of-memory
- * errors here... Instead just reset to the default */
- static_ut_name = default_file_name;
+ int fd;
+
+ fd = open_not_cancel_2(wtmp_file, O_APPEND | O_WRONLY);
+ if (fd >= 0) {
+ if (lockf(fd, F_LOCK, 0) == 0) {
+ write_not_cancel(fd, lutmp, sizeof(struct UT));
+ lockf(fd, F_ULOCK, 0);
+ close_not_cancel_no_status(fd);
+ }
}
- }
-
- if (static_fd >= 0) {
- close_not_cancel_no_status(static_fd);
- static_fd = -1;
- }
- __UCLIBC_MUTEX_UNLOCK(utmplock);
- return 0; /* or maybe return -(static_ut_name != new_ut_name)? */
}
-strong_alias(__utmpname,utmpname)
-
-#ifdef __UCLIBC_HAS_UTMPX__
-strong_alias(__utmpname,utmpxname)
-#endif
+/* not used in libc_hidden_def(updw) */
+other(updwtmpx,updwtmp)
diff --git a/libc/misc/utmp/utxent.c b/libc/misc/utmp/utxent.c
deleted file mode 100644
index 71157ccd8..000000000
--- a/libc/misc/utmp/utxent.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * utexent.c : Support for accessing user accounting database.
- * Copyright (C) 2010 STMicroelectronics Ltd.
- *
- * Author: Salvatore Cro <salvatore.cro@st.com>
- *
- * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
- *
- */
-
-#include <features.h>
-#include <string.h>
-#include <utmpx.h>
-#include <utmp.h>
-
-#if 0 /* moved to utent.c */
-void setutxent(void)
-{
- setutent ();
-}
-
-void endutxent(void)
-{
- endutent ();
-}
-
-struct utmpx *getutxent(void)
-{
- return (struct utmpx *) getutent ();
-}
-
-struct utmpx *getutxid(const struct utmpx *utmp_entry)
-{
- return (struct utmpx *) getutid ((const struct utmp *) utmp_entry);
-}
-
-struct utmpx *getutxline(const struct utmpx *utmp_entry)
-{
- return (struct utmpx *) getutline ((const struct utmp *) utmp_entry);
-}
-
-struct utmpx *pututxline (const struct utmpx *utmp_entry)
-{
- return (struct utmpx *) pututline ((const struct utmp *) utmp_entry);
-}
-
-int utmpxname (const char *new_ut_name)
-{
- return utmpname (new_ut_name);
-}
-
-/* moved to wtent.c */
-void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx)
-{
- updwtmp (wtmpx_file, (const struct utmp *) utmpx);
-}
-#endif
-
-/* Copy the information in UTMPX to UTMP. */
-void getutmp (const struct utmpx *utmpx, struct utmp *utmp)
-{
-#if _HAVE_UT_TYPE - 0
- utmp->ut_type = utmpx->ut_type;
-#endif
-#if _HAVE_UT_PID - 0
- utmp->ut_pid = utmpx->ut_pid;
-#endif
- memcpy (utmp->ut_line, utmpx->ut_line, sizeof (utmp->ut_line));
- memcpy (utmp->ut_user, utmpx->ut_user, sizeof (utmp->ut_user));
-#if _HAVE_UT_ID - 0
- memcpy (utmp->ut_id, utmpx->ut_id, sizeof (utmp->ut_id));
-#endif
-#if _HAVE_UT_HOST - 0
- memcpy (utmp->ut_host, utmpx->ut_host, sizeof (utmp->ut_host));
-#endif
-#if _HAVE_UT_TV - 0
- utmp->ut_tv.tv_sec = utmpx->ut_tv.tv_sec;
- utmp->ut_tv.tv_usec = utmpx->ut_tv.tv_usec;
-#else
- utmp->ut_time = utmpx->ut_time;
-#endif
-}
-
-/* Copy the information in UTMP to UTMPX. */
-void getutmpx (const struct utmp *utmp, struct utmpx *utmpx)
-{
- memset (utmpx, 0, sizeof (struct utmpx));
-
-#if _HAVE_UT_TYPE - 0
- utmpx->ut_type = utmp->ut_type;
-#endif
-#if _HAVE_UT_PID - 0
- utmpx->ut_pid = utmp->ut_pid;
-#endif
- memcpy (utmpx->ut_line, utmp->ut_line, sizeof (utmp->ut_line));
- memcpy (utmpx->ut_user, utmp->ut_user, sizeof (utmp->ut_user));
-#if _HAVE_UT_ID - 0
- memcpy (utmpx->ut_id, utmp->ut_id, sizeof (utmp->ut_id));
-#endif
-#if _HAVE_UT_HOST - 0
- memcpy (utmpx->ut_host, utmp->ut_host, sizeof (utmp->ut_host));
-#endif
-#if _HAVE_UT_TV - 0
- utmpx->ut_tv.tv_sec = utmp->ut_tv.tv_sec;
- utmpx->ut_tv.tv_usec = utmp->ut_tv.tv_usec;
-#else
- utmpx->ut_time = utmp->ut_time;
-#endif
-}
diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c
deleted file mode 100644
index 9b3ad5084..000000000
--- a/libc/misc/utmp/wtent.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
- *
- * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
- */
-
-/* wtmp support rubbish (i.e. complete crap) */
-
-#include <string.h>
-#include <sys/time.h>
-#include <time.h>
-#include <unistd.h>
-#include <utmp.h>
-#ifdef __UCLIBC_HAS_UTMPX__
-# include <utmpx.h>
-#endif
-#include <fcntl.h>
-#include <sys/file.h>
-#include <not-cancel.h>
-
-#if 0
-/* This is enabled in uClibc/libutil/logwtmp.c */
-void logwtmp (const char *line, const char *name, const char *host)
-{
- struct utmp lutmp;
- memset(&lutmp, 0, sizeof(lutmp));
-
- lutmp.ut_type = (name && *name) ? USER_PROCESS : DEAD_PROCESS;
- lutmp.ut_pid = getpid();
- strncpy(lutmp.ut_line, line, sizeof(lutmp.ut_line)-1);
- strncpy(lutmp.ut_name, name, sizeof(lutmp.ut_name)-1);
- strncpy(lutmp.ut_host, host, sizeof(lutmp.ut_host)-1);
- gettimeofday(&(lutmp.ut_tv), NULL);
-
- updwtmp(_PATH_WTMP, &lutmp);
-}
-#endif
-
-static void __updwtmp(const char *wtmp_file, const struct utmp *lutmp)
-{
- int fd;
-
- fd = open_not_cancel_2(wtmp_file, O_APPEND | O_WRONLY);
- if (fd >= 0) {
- if (lockf(fd, F_LOCK, 0) == 0) {
- write_not_cancel(fd, lutmp, sizeof(struct utmp));
- lockf(fd, F_ULOCK, 0);
- close_not_cancel_no_status(fd);
- }
- }
-}
-strong_alias(__updwtmp,updwtmp)
-
-#ifdef __UCLIBC_HAS_UTMPX__
-void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx)
-{
- __updwtmp (wtmpx_file, (const struct utmp *) utmpx);
-}
-#endif