|
@@ -24,14 +24,26 @@
|
|
|
__UCLIBC_MUTEX_STATIC(utmplock, PTHREAD_MUTEX_INITIALIZER);
|
|
|
|
|
|
|
|
|
+
|
|
|
+#if defined __UCLIBC_HAS_THREADS__
|
|
|
+# define static_if_threaded static
|
|
|
+#else
|
|
|
+# define static_if_threaded
|
|
|
+# define __setutent setutent
|
|
|
+# define __getutent getutent
|
|
|
+# define __getutid getutid
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
|
|
|
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 void __setutent(void)
|
|
|
+static_if_threaded void __setutent(void)
|
|
|
{
|
|
|
if (static_fd < 0) {
|
|
|
static_fd = open(static_ut_name, O_RDWR | O_CLOEXEC);
|
|
@@ -49,20 +61,19 @@ static void __setutent(void)
|
|
|
}
|
|
|
lseek(static_fd, 0, SEEK_SET);
|
|
|
}
|
|
|
-
|
|
|
+#if defined __UCLIBC_HAS_THREADS__
|
|
|
void setutent(void)
|
|
|
{
|
|
|
__UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
__setutent();
|
|
|
__UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
}
|
|
|
+#endif
|
|
|
libc_hidden_def(setutent)
|
|
|
|
|
|
|
|
|
-static struct utmp *__getutent(void)
|
|
|
+static_if_threaded struct utmp *__getutent(void)
|
|
|
{
|
|
|
- struct utmp *ret = NULL;
|
|
|
-
|
|
|
if (static_fd < 0) {
|
|
|
__setutent();
|
|
|
if (static_fd < 0) {
|
|
@@ -71,11 +82,22 @@ static struct utmp *__getutent(void)
|
|
|
}
|
|
|
|
|
|
if (read(static_fd, &static_utmp, sizeof(static_utmp)) == sizeof(static_utmp)) {
|
|
|
- ret = &static_utmp;
|
|
|
+ return &static_utmp;
|
|
|
}
|
|
|
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+#if defined __UCLIBC_HAS_THREADS__
|
|
|
+struct utmp *getutent(void)
|
|
|
+{
|
|
|
+ struct utmp *ret;
|
|
|
+
|
|
|
+ __UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
+ ret = __getutent();
|
|
|
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
return ret;
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
void endutent(void)
|
|
|
{
|
|
@@ -86,43 +108,31 @@ void endutent(void)
|
|
|
__UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
}
|
|
|
|
|
|
-struct utmp *getutent(void)
|
|
|
-{
|
|
|
- struct utmp *ret;
|
|
|
-
|
|
|
- __UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
- ret = __getutent();
|
|
|
- __UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
-static struct utmp *__getutid(const struct utmp *utmp_entry)
|
|
|
+static_if_threaded struct utmp *__getutid(const struct utmp *utmp_entry)
|
|
|
{
|
|
|
struct utmp *lutmp;
|
|
|
+ unsigned type;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ type = utmp_entry->ut_type - 1;
|
|
|
+ type /= 4;
|
|
|
|
|
|
while ((lutmp = __getutent()) != NULL) {
|
|
|
- if ( (utmp_entry->ut_type == RUN_LVL ||
|
|
|
- utmp_entry->ut_type == BOOT_TIME ||
|
|
|
- utmp_entry->ut_type == NEW_TIME ||
|
|
|
- utmp_entry->ut_type == OLD_TIME) &&
|
|
|
- lutmp->ut_type == utmp_entry->ut_type)
|
|
|
- {
|
|
|
- return lutmp;
|
|
|
- }
|
|
|
- if ( (utmp_entry->ut_type == INIT_PROCESS ||
|
|
|
- utmp_entry->ut_type == DEAD_PROCESS ||
|
|
|
- utmp_entry->ut_type == LOGIN_PROCESS ||
|
|
|
- utmp_entry->ut_type == USER_PROCESS) &&
|
|
|
- !strncmp(lutmp->ut_id, utmp_entry->ut_id, sizeof(lutmp->ut_id)))
|
|
|
- {
|
|
|
- return lutmp;
|
|
|
- }
|
|
|
+ if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) {
|
|
|
+
|
|
|
+ return lutmp;
|
|
|
+ }
|
|
|
+ if (type == 1 && strncmp(lutmp->ut_id, utmp_entry->ut_id, sizeof(lutmp->ut_id)) == 0) {
|
|
|
+
|
|
|
+ return lutmp;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return NULL;
|
|
|
}
|
|
|
-
|
|
|
+#if defined __UCLIBC_HAS_THREADS__
|
|
|
struct utmp *getutid(const struct utmp *utmp_entry)
|
|
|
{
|
|
|
struct utmp *ret;
|
|
@@ -132,6 +142,7 @@ struct utmp *getutid(const struct utmp *utmp_entry)
|
|
|
__UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
return ret;
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
struct utmp *getutline(const struct utmp *utmp_entry)
|
|
|
{
|
|
@@ -139,9 +150,10 @@ struct utmp *getutline(const struct utmp *utmp_entry)
|
|
|
|
|
|
__UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
while ((lutmp = __getutent()) != NULL) {
|
|
|
- if ((lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) &&
|
|
|
- !strcmp(lutmp->ut_line, utmp_entry->ut_line)) {
|
|
|
- break;
|
|
|
+ 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);
|