diff options
Diffstat (limited to 'libc/misc/utmp')
| -rw-r--r-- | libc/misc/utmp/Makefile.in | 3 | ||||
| -rw-r--r-- | libc/misc/utmp/utent.c | 36 | ||||
| -rw-r--r-- | libc/misc/utmp/wtent.c | 15 |
3 files changed, 53 insertions, 1 deletions
diff --git a/libc/misc/utmp/Makefile.in b/libc/misc/utmp/Makefile.in index 5e584372c..4a01bb20b 100644 --- a/libc/misc/utmp/Makefile.in +++ b/libc/misc/utmp/Makefile.in @@ -1,6 +1,5 @@ # Makefile for uClibc # -# Copyright (C) 2000 by Lineo, inc. # Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> # # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. @@ -15,6 +14,8 @@ MISC_UTMP_SRC := $(patsubst %.c,$(MISC_UTMP_DIR)/%.c,$(CSRC)) MISC_UTMP_OBJ := $(patsubst %.c,$(MISC_UTMP_OUT)/%.o,$(CSRC)) libc-y += $(MISC_UTMP_OBJ) +libc-a-y += $(MISC_UTMP_OBJ) +libc-so-y += $(MISC_UTMP_OBJ) objclean-y += misc_utmp_objclean diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 597307738..2734f9e95 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -19,6 +19,9 @@ #include <errno.h> #include <string.h> #include <utmp.h> +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ +#include <not-cancel.h> +#endif libc_hidden_proto(strcmp) libc_hidden_proto(strdup) @@ -52,20 +55,37 @@ void setutent(void) LOCK; if (static_fd == -1) { +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ + if ((static_fd = open_not_cancel_2(static_ut_name, O_RDWR)) < 0) { + if ((static_fd = open_not_cancel_2(static_ut_name, O_RDONLY)) < 0) { +#else if ((static_fd = open(static_ut_name, O_RDWR)) < 0) { if ((static_fd = open(static_ut_name, O_RDONLY)) < 0) { +#endif goto bummer; } } /* Make sure the file will be closed on exec() */ +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ + ret = fcntl_not_cancel(static_fd, F_GETFD, 0); +#else ret = fcntl(static_fd, F_GETFD, 0); +#endif if (ret >= 0) { +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ + ret = fcntl_not_cancel(static_fd, F_SETFD, ret | FD_CLOEXEC); +#else ret = fcntl(static_fd, F_SETFD, ret | FD_CLOEXEC); +#endif } if (ret < 0) { bummer: static_fd = -1; +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ + close_not_cancel_no_status(static_fd); +#else close(static_fd); +#endif unlock_and_ret: UNLOCK; return; @@ -88,7 +108,11 @@ static struct utmp *__getutent(int utmp_fd) } LOCK; +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ + if (read_not_cancel(utmp_fd, (char *) &static_utmp, sizeof(struct utmp)) == sizeof(struct utmp)) +#else if (read(utmp_fd, (char *) &static_utmp, sizeof(struct utmp)) == sizeof(struct utmp)) +#endif { ret = &static_utmp; } @@ -101,7 +125,11 @@ void endutent(void) { LOCK; if (static_fd != -1) +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ + close_not_cancel_no_status(static_fd); +#else close(static_fd); +#endif static_fd = -1; UNLOCK; } @@ -168,7 +196,11 @@ struct utmp *pututline (const struct utmp *utmp_entry) lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); else lseek(static_fd, (off_t) 0, SEEK_END); +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ if (write(static_fd, utmp_entry, sizeof(struct utmp)) != sizeof(struct utmp)) +#else + if (write_not_cancel(static_fd, utmp_entry, sizeof(struct utmp)) != sizeof(struct utmp)) +#endif utmp_entry = NULL; UNLOCK; @@ -190,7 +222,11 @@ int utmpname (const char *new_ut_name) } if (static_fd != -1) +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ + close_not_cancel_no_status(static_fd); +#else close(static_fd); +#endif static_fd = -1; UNLOCK; return 0; diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c index 0378070e7..082e8c184 100644 --- a/libc/misc/utmp/wtent.c +++ b/libc/misc/utmp/wtent.c @@ -13,6 +13,10 @@ #include <utmp.h> #include <fcntl.h> #include <sys/file.h> +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ +#include <errno.h> +#include <not-cancel.h> +#endif #if 0 libc_hidden_proto(memset) @@ -47,6 +51,16 @@ void updwtmp(const char *wtmp_file, const struct utmp *lutmp) { int fd; +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ + fd = open_not_cancel(wtmp_file, O_APPEND | O_WRONLY, 0); + if (fd >= 0) { + if (lockf(fd, F_LOCK, 0)==0) { + write_not_cancel(fd, (const char *) lutmp, sizeof(struct utmp)); + lockf(fd, F_ULOCK, 0); + close_not_cancel_no_status(fd); + } + } +#else fd = open(wtmp_file, O_APPEND | O_WRONLY, 0); if (fd >= 0) { if (lockf(fd, F_LOCK, 0)==0) { @@ -55,4 +69,5 @@ void updwtmp(const char *wtmp_file, const struct utmp *lutmp) close(fd); } } +#endif } |
