|
@@ -34,28 +34,28 @@ static const char *static_ut_name = default_file_name;
|
|
|
|
|
|
static void __setutent_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 = 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
#ifndef __ASSUME_O_CLOEXEC
|
|
|
-
|
|
|
- fcntl_not_cancel(static_fd, F_SETFD, FD_CLOEXEC);
|
|
|
+
|
|
|
+ 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__
|
|
|
void setutent(void)
|
|
|
{
|
|
|
- __UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
- __setutent_unlocked();
|
|
|
- __UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
+ __UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
+ __setutent_unlocked();
|
|
|
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
}
|
|
|
#else
|
|
|
strong_alias(__setutent_unlocked,setutent)
|
|
@@ -65,28 +65,28 @@ libc_hidden_def(setutent)
|
|
|
|
|
|
static struct utmp *__getutent_unlocked(void)
|
|
|
{
|
|
|
- if (static_fd < 0) {
|
|
|
- __setutent_unlocked();
|
|
|
if (static_fd < 0) {
|
|
|
- return NULL;
|
|
|
+ __setutent_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__
|
|
|
struct utmp *getutent(void)
|
|
|
{
|
|
|
- struct utmp *ret;
|
|
|
+ struct utmp *ret;
|
|
|
|
|
|
- __UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
- ret = __getutent_unlocked();
|
|
|
- __UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
- return ret;
|
|
|
+ __UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
+ ret = __getutent_unlocked();
|
|
|
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
+ return ret;
|
|
|
}
|
|
|
#else
|
|
|
strong_alias(__getutent_unlocked,getutent)
|
|
@@ -95,11 +95,11 @@ libc_hidden_def(getutent)
|
|
|
|
|
|
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)
|
|
|
libc_hidden_def(endutent)
|
|
@@ -107,36 +107,38 @@ libc_hidden_def(endutent)
|
|
|
|
|
|
static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry)
|
|
|
{
|
|
|
- struct utmp *lutmp;
|
|
|
- unsigned type;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- type = utmp_entry->ut_type - 1;
|
|
|
- type /= 4;
|
|
|
-
|
|
|
- while ((lutmp = __getutent_unlocked()) != NULL) {
|
|
|
- if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) {
|
|
|
-
|
|
|
- return lutmp;
|
|
|
+ struct utmp *lutmp;
|
|
|
+ unsigned type;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ type = utmp_entry->ut_type - 1;
|
|
|
+ type /= 4;
|
|
|
+
|
|
|
+ while ((lutmp = __getutent_unlocked()) != NULL) {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|
|
|
- if (type == 1 && strncmp(lutmp->ut_id, utmp_entry->ut_id, sizeof(lutmp->ut_id)) == 0) {
|
|
|
-
|
|
|
- return lutmp;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- return NULL;
|
|
|
+ return NULL;
|
|
|
}
|
|
|
#if defined __UCLIBC_HAS_THREADS__
|
|
|
struct utmp *getutid(const struct utmp *utmp_entry)
|
|
|
{
|
|
|
- struct utmp *ret;
|
|
|
+ struct utmp *ret;
|
|
|
|
|
|
- __UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
- ret = __getutid_unlocked(utmp_entry);
|
|
|
- __UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
- return ret;
|
|
|
+ __UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
+ ret = __getutid_unlocked(utmp_entry);
|
|
|
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
+ return ret;
|
|
|
}
|
|
|
#else
|
|
|
strong_alias(__getutid_unlocked,getutid)
|
|
@@ -145,59 +147,61 @@ libc_hidden_def(getutid)
|
|
|
|
|
|
struct utmp *getutline(const struct utmp *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 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- __UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
- return lutmp;
|
|
|
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
+ return lutmp;
|
|
|
}
|
|
|
libc_hidden_def(getutline)
|
|
|
|
|
|
struct utmp *pututline(const struct utmp *utmp_entry)
|
|
|
{
|
|
|
- __UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
-
|
|
|
- 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)
|
|
|
+ __UCLIBC_MUTEX_LOCK(utmplock);
|
|
|
+
|
|
|
+ the file pointer where they want it, everything will work out. */
|
|
|
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;
|
|
|
+ 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;
|
|
|
}
|
|
|
libc_hidden_def(pututline)
|
|
|
|
|
|
int utmpname(const char *new_ut_name)
|
|
|
{
|
|
|
- __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) {
|
|
|
-
|
|
|
- * errors here... Instead just reset to the default */
|
|
|
- static_ut_name = default_file_name;
|
|
|
+ __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) {
|
|
|
+
|
|
|
+ * errors here... Instead just reset to the default */
|
|
|
+ static_ut_name = default_file_name;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (static_fd >= 0) {
|
|
|
- close_not_cancel_no_status(static_fd);
|
|
|
- static_fd = -1;
|
|
|
- }
|
|
|
- __UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
- return 0;
|
|
|
+ if (static_fd >= 0) {
|
|
|
+ close_not_cancel_no_status(static_fd);
|
|
|
+ static_fd = -1;
|
|
|
+ }
|
|
|
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
|
|
|
+ return 0;
|
|
|
}
|
|
|
libc_hidden_def(utmpname)
|