|
@@ -20,55 +20,43 @@
|
|
|
#include <string.h>
|
|
|
#include <utmp.h>
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
#include <bits/uClibc_mutex.h>
|
|
|
__UCLIBC_MUTEX_STATIC(utmplock, PTHREAD_MUTEX_INITIALIZER);
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
static int static_fd = -1;
|
|
|
static struct utmp static_utmp;
|
|
|
static const char default_file_name[] = _PATH_UTMP;
|
|
|
-static const char *static_ut_name = (const char *) default_file_name;
|
|
|
+static const char *static_ut_name = default_file_name;
|
|
|
|
|
|
|
|
|
static void __setutent(void)
|
|
|
{
|
|
|
- int ret;
|
|
|
-
|
|
|
- if (static_fd == -1) {
|
|
|
- if ((static_fd = open(static_ut_name, O_RDWR)) < 0) {
|
|
|
- if ((static_fd = open(static_ut_name, O_RDONLY)) < 0) {
|
|
|
- goto bummer;
|
|
|
+ if (static_fd < 0) {
|
|
|
+ static_fd = open(static_ut_name, O_RDWR);
|
|
|
+ if (static_fd < 0) {
|
|
|
+ static_fd = open(static_ut_name, O_RDONLY);
|
|
|
+ if (static_fd < 0) {
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- ret = fcntl(static_fd, F_GETFD, 0);
|
|
|
- if (ret >= 0) {
|
|
|
- ret = fcntl(static_fd, F_SETFD, ret | FD_CLOEXEC);
|
|
|
- }
|
|
|
- if (ret < 0) {
|
|
|
-bummer:
|
|
|
- static_fd = -1;
|
|
|
- close(static_fd);
|
|
|
- return;
|
|
|
- }
|
|
|
+ fcntl(static_fd, F_SETFD, FD_CLOEXEC);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return;
|
|
|
}
|
|
|
lseek(static_fd, 0, SEEK_SET);
|
|
|
- return;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
void setutent(void)
|
|
|
{
|
|
|
__UCLIBC_MUTEX_LOCK(utmplock);
|
|
@@ -78,19 +66,18 @@ void setutent(void)
|
|
|
libc_hidden_def(setutent)
|
|
|
|
|
|
|
|
|
-static struct utmp *__getutent(int utmp_fd)
|
|
|
+static struct utmp *__getutent(void)
|
|
|
{
|
|
|
struct utmp *ret = NULL;
|
|
|
|
|
|
- if (utmp_fd == -1) {
|
|
|
+ if (static_fd < 0) {
|
|
|
__setutent();
|
|
|
- }
|
|
|
- if (utmp_fd == -1) {
|
|
|
- return NULL;
|
|
|
+ if (static_fd < 0) {
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (read(utmp_fd, (char *) &static_utmp, sizeof(struct utmp)) == sizeof(struct utmp))
|
|
|
- {
|
|
|
+ if (read(static_fd, &static_utmp, sizeof(static_utmp)) == sizeof(static_utmp)) {
|
|
|
ret = &static_utmp;
|
|
|
}
|
|
|
|
|
@@ -100,7 +87,7 @@ static struct utmp *__getutent(int utmp_fd)
|
|
|
void endutent(void)
|
|
|
{
|
|
|
__UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
- if (static_fd != -1)
|
|
|
+ if (static_fd >= 0)
|
|
|
close(static_fd);
|
|
|
static_fd = -1;
|
|
|
__UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
@@ -111,7 +98,7 @@ struct utmp *getutent(void)
|
|
|
struct utmp *ret = NULL;
|
|
|
|
|
|
__UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
- ret = __getutent(static_fd);
|
|
|
+ ret = __getutent();
|
|
|
__UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
return ret;
|
|
|
}
|
|
@@ -121,7 +108,7 @@ static struct utmp *__getutid(const struct utmp *utmp_entry)
|
|
|
{
|
|
|
struct utmp *lutmp;
|
|
|
|
|
|
- while ((lutmp = __getutent(static_fd)) != NULL) {
|
|
|
+ while ((lutmp = __getutent()) != NULL) {
|
|
|
if ( (utmp_entry->ut_type == RUN_LVL ||
|
|
|
utmp_entry->ut_type == BOOT_TIME ||
|
|
|
utmp_entry->ut_type == NEW_TIME ||
|
|
@@ -143,7 +130,6 @@ static struct utmp *__getutid(const struct utmp *utmp_entry)
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
struct utmp *getutid(const struct utmp *utmp_entry)
|
|
|
{
|
|
|
struct utmp *ret = NULL;
|
|
@@ -160,7 +146,7 @@ struct utmp *getutline(const struct utmp *utmp_entry)
|
|
|
struct utmp *lutmp = NULL;
|
|
|
|
|
|
__UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
- while ((lutmp = __getutent(static_fd)) != NULL) {
|
|
|
+ while ((lutmp = __getutent()) != NULL) {
|
|
|
if ((lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) &&
|
|
|
!strcmp(lutmp->ut_line, utmp_entry->ut_line)) {
|
|
|
break;
|
|
@@ -170,7 +156,7 @@ struct utmp *getutline(const struct utmp *utmp_entry)
|
|
|
return lutmp;
|
|
|
}
|
|
|
|
|
|
-struct utmp *pututline (const struct utmp *utmp_entry)
|
|
|
+struct utmp *pututline(const struct utmp *utmp_entry)
|
|
|
{
|
|
|
__UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
|
|
@@ -188,7 +174,7 @@ struct utmp *pututline (const struct utmp *utmp_entry)
|
|
|
return (struct utmp *)utmp_entry;
|
|
|
}
|
|
|
|
|
|
-int utmpname (const char *new_ut_name)
|
|
|
+int utmpname(const char *new_ut_name)
|
|
|
{
|
|
|
__UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
if (new_ut_name != NULL) {
|
|
@@ -202,9 +188,10 @@ int utmpname (const char *new_ut_name)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (static_fd != -1)
|
|
|
+ if (static_fd >= 0) {
|
|
|
close(static_fd);
|
|
|
- static_fd = -1;
|
|
|
+ static_fd = -1;
|
|
|
+ }
|
|
|
__UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
- return 0;
|
|
|
+ return 0;
|
|
|
}
|