From 9277fe13156a6ff2b055fe8a58d2863115c36b6a Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:09:45 +0100 Subject: Revert "utent.c, wtent.c: move functions from utxent.c" This reverts commit 84135275cfeebc0b233c1c96eeada4d4178a0b18. This change is said to make systemd deadlock (cannot reproduce this) Signed-off-by: Bernhard Reutner-Fischer Conflicts: include/utmp.h --- libc/misc/utmp/utent.c | 80 ++++++++++++------------------------------------- libc/misc/utmp/utxent.c | 4 +-- libc/misc/utmp/wtent.c | 14 ++------- 3 files changed, 22 insertions(+), 76 deletions(-) (limited to 'libc/misc') diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index a35bb2b84..07ca44eb2 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -19,9 +19,6 @@ #include #include #include -#ifdef __UCLIBC_HAS_UTMPX__ -# include -#endif #include #include @@ -34,7 +31,7 @@ static const char default_file_name[] = _PATH_UTMP; static const char *static_ut_name = default_file_name; /* This function must be called with the LOCK held */ -static void __setutent_unlocked(void) +static void __setutent(void) { if (static_fd < 0) { static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC); @@ -53,24 +50,19 @@ static void __setutent_unlocked(void) lseek(static_fd, 0, SEEK_SET); } #if defined __UCLIBC_HAS_THREADS__ -static void __setutent(void) +void setutent(void) { __UCLIBC_MUTEX_LOCK(utmplock); - __setutent_unlocked(); + __setutent(); __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) #endif +libc_hidden_def(setutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutent_unlocked(void) +static struct utmp *__getutent(void) { if (static_fd < 0) { __setutent(); @@ -86,27 +78,19 @@ static struct utmp *__getutent_unlocked(void) return NULL; } #if defined __UCLIBC_HAS_THREADS__ -static struct utmp *__getutent(void) +struct utmp *getutent(void) { struct utmp *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutent_unlocked(); + ret = __getutent(); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -static struct utmp *__getutent(void); -strong_alias(__getutent_unlocked,__getutent) -#endif strong_alias(__getutent,getutent) - -#ifdef __UCLIBC_HAS_UTMPX__ -struct utmpx *getutxent(void) -{ - return (struct utmpx *) __getutent (); -} #endif +libc_hidden_def(getutent) static void __endutent(void) { @@ -117,13 +101,10 @@ static void __endutent(void) __UCLIBC_MUTEX_UNLOCK(utmplock); } strong_alias(__endutent,endutent) - -#ifdef __UCLIBC_HAS_UTMPX__ -strong_alias(__endutent,endutxent) -#endif +libc_hidden_def(endutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) +static struct utmp *__getutid(const struct utmp *utmp_entry) { struct utmp *lutmp; unsigned type; @@ -133,7 +114,7 @@ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) type = utmp_entry->ut_type - 1; type /= 4; - while ((lutmp = __getutent_unlocked()) != NULL) { + while ((lutmp = __getutent()) != NULL) { if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) { /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */ return lutmp; @@ -147,34 +128,26 @@ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) return NULL; } #if defined __UCLIBC_HAS_THREADS__ -static struct utmp *__getutid(const struct utmp *utmp_entry) +struct utmp *getutid(const struct utmp *utmp_entry) { struct utmp *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutid_unlocked(utmp_entry); + ret = __getutid(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); -} #endif +libc_hidden_def(getutid) static struct utmp *__getutline(const struct utmp *utmp_entry) { struct utmp *lutmp; __UCLIBC_MUTEX_LOCK(utmplock); - while ((lutmp = __getutent_unlocked()) != NULL) { + while ((lutmp = __getutent()) != 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; @@ -185,13 +158,7 @@ static struct utmp *__getutline(const struct utmp *utmp_entry) return lutmp; } strong_alias(__getutline,getutline) - -#ifdef __UCLIBC_HAS_UTMPX__ -struct utmpx *getutxline(const struct utmpx *utmp_entry) -{ - return (struct utmpx *) __getutline ((const struct utmp *) utmp_entry); -} -#endif +libc_hidden_def(getutline) static struct utmp *__pututline(const struct utmp *utmp_entry) { @@ -200,7 +167,7 @@ static struct utmp *__pututline(const struct utmp *utmp_entry) 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) + if (__getutid(utmp_entry) != NULL) lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); else lseek(static_fd, (off_t) 0, SEEK_END); @@ -211,13 +178,7 @@ static struct utmp *__pututline(const struct utmp *utmp_entry) return (struct utmp *)utmp_entry; } strong_alias(__pututline,pututline) - -#ifdef __UCLIBC_HAS_UTMPX__ -struct utmpx *pututxline (const struct utmpx *utmp_entry) -{ - return (struct utmpx *) __pututline ((const struct utmp *) utmp_entry); -} -#endif +libc_hidden_def(pututline) static int __utmpname(const char *new_ut_name) { @@ -241,7 +202,4 @@ static int __utmpname(const char *new_ut_name) return 0; /* or maybe return -(static_ut_name != new_ut_name)? */ } strong_alias(__utmpname,utmpname) - -#ifdef __UCLIBC_HAS_UTMPX__ -strong_alias(__utmpname,utmpxname) -#endif +libc_hidden_def(utmpname) diff --git a/libc/misc/utmp/utxent.c b/libc/misc/utmp/utxent.c index 71157ccd8..a0e80a662 100644 --- a/libc/misc/utmp/utxent.c +++ b/libc/misc/utmp/utxent.c @@ -13,7 +13,6 @@ #include #include -#if 0 /* moved to utent.c */ void setutxent(void) { setutent (); @@ -49,12 +48,10 @@ 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) @@ -107,3 +104,4 @@ void getutmpx (const struct utmp *utmp, struct utmpx *utmpx) utmpx->ut_time = utmp->ut_time; #endif } + diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c index 9b3ad5084..b5e4ee576 100644 --- a/libc/misc/utmp/wtent.c +++ b/libc/misc/utmp/wtent.c @@ -11,9 +11,6 @@ #include #include #include -#ifdef __UCLIBC_HAS_UTMPX__ -# include -#endif #include #include #include @@ -36,7 +33,7 @@ void logwtmp (const char *line, const char *name, const char *host) } #endif -static void __updwtmp(const char *wtmp_file, const struct utmp *lutmp) +void updwtmp(const char *wtmp_file, const struct utmp *lutmp) { int fd; @@ -49,11 +46,4 @@ static void __updwtmp(const char *wtmp_file, const struct utmp *lutmp) } } } -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 +libc_hidden_def(updwtmp) -- cgit v1.2.3 From 4da43e9f2e4f2f7593427003e37b87287c7b16cf Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:21 +0100 Subject: buildsys: HAS_UTMP (XPG2, SVr4 compat) knob Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/Makefile.in | 4 +++- libc/misc/utmp/utent.c | 1 + libc/misc/utmp/utxent.c | 1 + libc/misc/utmp/wtent.c | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) (limited to 'libc/misc') diff --git a/libc/misc/utmp/Makefile.in b/libc/misc/utmp/Makefile.in index 535efb150..715341c85 100644 --- a/libc/misc/utmp/Makefile.in +++ b/libc/misc/utmp/Makefile.in @@ -7,7 +7,9 @@ subdirs += libc/misc/utmp -CSRC-y := utent.c wtent.c +CSRC-y := +CSRC-$(if $(findstring y,$(UCLIBC_HAS_UTMP)$(UCLIBC_HAS_UTMPX)),y) += wtent.c +CSRC-$(UCLIBC_HAS_UTMP) += utent.c CSRC-$(UCLIBC_HAS_UTMPX) += utxent.c MISC_UTMP_DIR := $(top_srcdir)libc/misc/utmp diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 07ca44eb2..6e1567865 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 */ /* 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 diff --git a/libc/misc/utmp/utxent.c b/libc/misc/utmp/utxent.c index a0e80a662..c32e4da49 100644 --- a/libc/misc/utmp/utxent.c +++ b/libc/misc/utmp/utxent.c @@ -1,3 +1,4 @@ +/* vi: set sw=4 ts=4: */ /* * utexent.c : Support for accessing user accounting database. * Copyright (C) 2010 STMicroelectronics Ltd. diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c index b5e4ee576..30939ea43 100644 --- a/libc/misc/utmp/wtent.c +++ b/libc/misc/utmp/wtent.c @@ -1,3 +1,4 @@ +/* vi: set sw=4 ts=4: */ /* * Copyright (C) 2000-2006 Erik Andersen * -- cgit v1.2.3 From d0f60a600bafc3f6dfc844418d310cf6a4e38c92 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:24 +0100 Subject: utmp: add _unlocked suffix to internal helpers Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/utent.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'libc/misc') diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 6e1567865..87fe42b16 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -21,8 +21,8 @@ #include #include #include - #include + __UCLIBC_MUTEX_STATIC(utmplock, PTHREAD_MUTEX_INITIALIZER); /* Some global crap */ @@ -32,7 +32,7 @@ static const char default_file_name[] = _PATH_UTMP; static const char *static_ut_name = default_file_name; /* This function must be called with the LOCK held */ -static void __setutent(void) +static void __setutent_unlocked(void) { if (static_fd < 0) { static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC); @@ -54,19 +54,19 @@ static void __setutent(void) void setutent(void) { __UCLIBC_MUTEX_LOCK(utmplock); - __setutent(); + __setutent_unlocked(); __UCLIBC_MUTEX_UNLOCK(utmplock); } #else -strong_alias(__setutent,setutent) +strong_alias(__setutent_unlocked,setutent) #endif libc_hidden_def(setutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutent(void) +static struct utmp *__getutent_unlocked(void) { if (static_fd < 0) { - __setutent(); + __setutent_unlocked(); if (static_fd < 0) { return NULL; } @@ -84,12 +84,12 @@ struct utmp *getutent(void) struct utmp *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutent(); + ret = __getutent_unlocked(); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -strong_alias(__getutent,getutent) +strong_alias(__getutent_unlocked,getutent) #endif libc_hidden_def(getutent) @@ -105,7 +105,7 @@ strong_alias(__endutent,endutent) libc_hidden_def(endutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutid(const struct utmp *utmp_entry) +static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) { struct utmp *lutmp; unsigned type; @@ -115,7 +115,7 @@ static struct utmp *__getutid(const struct utmp *utmp_entry) type = utmp_entry->ut_type - 1; type /= 4; - while ((lutmp = __getutent()) != NULL) { + 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; @@ -134,12 +134,12 @@ struct utmp *getutid(const struct utmp *utmp_entry) struct utmp *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutid(utmp_entry); + ret = __getutid_unlocked(utmp_entry); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -strong_alias(__getutid,getutid) +strong_alias(__getutid_unlocked,getutid) #endif libc_hidden_def(getutid) @@ -148,7 +148,7 @@ static struct utmp *__getutline(const struct utmp *utmp_entry) struct utmp *lutmp; __UCLIBC_MUTEX_LOCK(utmplock); - while ((lutmp = __getutent()) != NULL) { + 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; @@ -168,7 +168,7 @@ static struct utmp *__pututline(const struct utmp *utmp_entry) the file pointer where they want it, everything will work out. */ lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); - if (__getutid(utmp_entry) != NULL) + 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); -- cgit v1.2.3 From 97c9f52239301c81c021b8be187ac07ddf33496d Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:28 +0100 Subject: utmp: Remove unneeded aliases Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/utent.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'libc/misc') diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 87fe42b16..c45820e3a 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -143,7 +143,7 @@ strong_alias(__getutid_unlocked,getutid) #endif libc_hidden_def(getutid) -static struct utmp *__getutline(const struct utmp *utmp_entry) +struct utmp *getutline(const struct utmp *utmp_entry) { struct utmp *lutmp; @@ -158,10 +158,9 @@ static struct utmp *__getutline(const struct utmp *utmp_entry) __UCLIBC_MUTEX_UNLOCK(utmplock); return lutmp; } -strong_alias(__getutline,getutline) libc_hidden_def(getutline) -static struct utmp *__pututline(const struct utmp *utmp_entry) +struct utmp *pututline(const struct utmp *utmp_entry) { __UCLIBC_MUTEX_LOCK(utmplock); /* Ignore the return value. That way, if they've already positioned @@ -178,10 +177,9 @@ static struct utmp *__pututline(const struct utmp *utmp_entry) __UCLIBC_MUTEX_UNLOCK(utmplock); return (struct utmp *)utmp_entry; } -strong_alias(__pututline,pututline) libc_hidden_def(pututline) -static int __utmpname(const char *new_ut_name) +int utmpname(const char *new_ut_name) { __UCLIBC_MUTEX_LOCK(utmplock); if (new_ut_name != NULL) { @@ -202,5 +200,4 @@ static int __utmpname(const char *new_ut_name) __UCLIBC_MUTEX_UNLOCK(utmplock); return 0; /* or maybe return -(static_ut_name != new_ut_name)? */ } -strong_alias(__utmpname,utmpname) libc_hidden_def(utmpname) -- cgit v1.2.3 From 6cba32e6e9a1910ea0a5277fd39484047094e478 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:38 +0100 Subject: utmp: indent indent only, no code changes Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/utent.c | 194 +++++++++++++++++++++++++------------------------ 1 file changed, 99 insertions(+), 95 deletions(-) (limited to 'libc/misc') diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index c45820e3a..4d71f5e29 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -34,28 +34,28 @@ static const char *static_ut_name = default_file_name; /* This function must be called with the LOCK held */ 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 remains < 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 */ + } + } #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__ 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) /* This function must be called with the LOCK held */ 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) /* This function must be called with the LOCK held */ static struct utmp *__getutid_unlocked(const struct utmp *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 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; + } + 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__ 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); - /* 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) + __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); - 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) { - /* We should probably whine about out-of-memory - * 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) { + /* We should probably whine about out-of-memory + * 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; /* or maybe return -(static_ut_name != new_ut_name)? */ + 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)? */ } libc_hidden_def(utmpname) -- cgit v1.2.3 From 2b33716c08cc506e57115e34b5fe11d8d5477398 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 25 Mar 2015 23:59:37 +0100 Subject: utmp: Remove unneeded alias Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/utent.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'libc/misc') diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 4d71f5e29..a258cb46d 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -93,7 +93,7 @@ strong_alias(__getutent_unlocked,getutent) #endif libc_hidden_def(getutent) -static void __endutent(void) +void endutent(void) { __UCLIBC_MUTEX_LOCK(utmplock); if (static_fd >= 0) @@ -101,7 +101,6 @@ static void __endutent(void) static_fd = -1; __UCLIBC_MUTEX_UNLOCK(utmplock); } -strong_alias(__endutent,endutent) libc_hidden_def(endutent) /* This function must be called with the LOCK held */ -- cgit v1.2.3 From 6ff9c31abc14f207265ab214370982ecb3bfe428 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 25 Mar 2015 23:59:45 +0100 Subject: utmp: favour POSIX utmpx over SVID utmp Note: _PATH_UTMPX == _PATH_UTMP and the utmp struct is identical to the utmpx struct so this only changes the external API entrypoints and NOT the underlying data source. This saves about 500b (~1300b from previously ~1950) while at it. Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/Makefile.in | 4 +- libc/misc/utmp/utent.c | 121 +++++++++++++++++++++++++++------------------ libc/misc/utmp/utxent.c | 108 ---------------------------------------- libc/misc/utmp/wtent.c | 50 ------------------- 4 files changed, 73 insertions(+), 210 deletions(-) delete mode 100644 libc/misc/utmp/utxent.c delete mode 100644 libc/misc/utmp/wtent.c (limited to 'libc/misc') diff --git a/libc/misc/utmp/Makefile.in b/libc/misc/utmp/Makefile.in index 715341c85..6c54ade96 100644 --- a/libc/misc/utmp/Makefile.in +++ b/libc/misc/utmp/Makefile.in @@ -8,9 +8,7 @@ subdirs += libc/misc/utmp CSRC-y := -CSRC-$(if $(findstring y,$(UCLIBC_HAS_UTMP)$(UCLIBC_HAS_UTMPX)),y) += wtent.c -CSRC-$(UCLIBC_HAS_UTMP) += utent.c -CSRC-$(UCLIBC_HAS_UTMPX) += utxent.c +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 a258cb46d..3671bb05c 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include "internal/utmp.h" #include #include @@ -27,17 +27,17 @@ __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); + static_fd = open_not_cancel_2(current_file, O_RDWR | O_CLOEXEC); if (static_fd < 0) { - static_fd = open_not_cancel_2(static_ut_name, O_RDONLY | O_CLOEXEC); + static_fd = open_not_cancel_2(current_file, O_RDONLY | O_CLOEXEC); if (static_fd < 0) { return; /* static_fd remains < 0 */ } @@ -51,22 +51,23 @@ static void __setutent_unlocked(void) lseek(static_fd, 0, SEEK_SET); } #if defined __UCLIBC_HAS_THREADS__ -void setutent(void) +void set(void) { __UCLIBC_MUTEX_LOCK(utmplock); - __setutent_unlocked(); + __set_unlocked(); __UCLIBC_MUTEX_UNLOCK(utmplock); } #else -strong_alias(__setutent_unlocked,setutent) +strong_alias(__set_unlocked,set) #endif -libc_hidden_def(setutent) +/* 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_unlocked(); + __set_unlocked(); if (static_fd < 0) return NULL; } @@ -79,21 +80,22 @@ static struct utmp *__getutent_unlocked(void) return NULL; } #if defined __UCLIBC_HAS_THREADS__ -struct utmp *getutent(void) +struct UT *get(void) { - struct utmp *ret; + struct UT *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutent_unlocked(); + ret = __get_unlocked(); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -strong_alias(__getutent_unlocked,getutent) +strong_alias(__get_unlocked,get) #endif -libc_hidden_def(getutent) +/* not used in libc_hidden_def(get) */ +other(getutxent,getutent) -void endutent(void) +void end(void) { __UCLIBC_MUTEX_LOCK(utmplock); if (static_fd >= 0) @@ -101,12 +103,13 @@ void endutent(void) static_fd = -1; __UCLIBC_MUTEX_UNLOCK(utmplock); } -libc_hidden_def(endutent) +/* 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; + struct UT *lutmp; unsigned type; /* We use the fact that constants we are interested in are: */ @@ -114,7 +117,7 @@ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) type = utmp_entry->ut_type - 1; type /= 4; - while ((lutmp = __getutent_unlocked()) != NULL) { + 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; @@ -130,26 +133,27 @@ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) return NULL; } #if defined __UCLIBC_HAS_THREADS__ -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); + ret = __getid_unlocked(utmp_entry); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -strong_alias(__getutid_unlocked,getutid) +strong_alias(__getid_unlocked,getid) #endif -libc_hidden_def(getutid) +/* not used in libc_hidden_def(getid) */ +other(getutxid,getutid) -struct utmp *getutline(const struct utmp *utmp_entry) +struct UT *getline(const struct UT *utmp_entry) { - struct utmp *lutmp; + struct UT *lutmp; __UCLIBC_MUTEX_LOCK(utmplock); - while ((lutmp = __getutent_unlocked()) != NULL) { + 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) { @@ -160,39 +164,41 @@ struct utmp *getutline(const struct utmp *utmp_entry) __UCLIBC_MUTEX_UNLOCK(utmplock); return lutmp; } -libc_hidden_def(getutline) +/* libc_hidden_def(getline) */ +other(getutxline,getutline) -struct utmp *pututline(const struct utmp *utmp_entry) +struct UT *putline(const struct UT *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 utmp), SEEK_CUR); + lseek(static_fd, (off_t) - sizeof(struct UT), SEEK_CUR); - if (__getutid_unlocked(utmp_entry) != NULL) - lseek(static_fd, (off_t) - sizeof(struct utmp), 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 utmp)) - != sizeof(struct utmp)) + if (write(static_fd, utmp_entry, sizeof(struct UT)) + != sizeof(struct UT)) utmp_entry = NULL; __UCLIBC_MUTEX_UNLOCK(utmplock); - return (struct utmp *)utmp_entry; + return (struct UT *)utmp_entry; } -libc_hidden_def(pututline) +/* not used in libc_hidden_def(putline) */ +other(pututxline,pututline) -int utmpname(const char *new_ut_name) +int name(const char *new_file) { __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) { + 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 */ - static_ut_name = default_file_name; + current_file = default_file; } } @@ -201,6 +207,23 @@ int utmpname(const char *new_ut_name) static_fd = -1; } __UCLIBC_MUTEX_UNLOCK(utmplock); - return 0; /* or maybe return -(static_ut_name != new_ut_name)? */ + return 0; /* or maybe return -(current_file != new_file)? */ } -libc_hidden_def(utmpname) +/* not used in libc_hidden_def(name) */ +other(utmpxname,utmpname) + +void updw(const char *wtmp_file, const struct UT *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 UT)); + lockf(fd, F_ULOCK, 0); + close_not_cancel_no_status(fd); + } + } +} +/* 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 c32e4da49..000000000 --- a/libc/misc/utmp/utxent.c +++ /dev/null @@ -1,108 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * utexent.c : Support for accessing user accounting database. - * Copyright (C) 2010 STMicroelectronics Ltd. - * - * Author: Salvatore Cro - * - * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. - * - */ - -#include -#include -#include -#include - -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); -} - -void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx) -{ - updwtmp (wtmpx_file, (const struct utmp *) utmpx); -} - -/* 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 30939ea43..000000000 --- a/libc/misc/utmp/wtent.c +++ /dev/null @@ -1,50 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Copyright (C) 2000-2006 Erik Andersen - * - * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. - */ - -/* wtmp support rubbish (i.e. complete crap) */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#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 - -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); - } - } -} -libc_hidden_def(updwtmp) -- cgit v1.2.3