From fa426feb6e1508c3204c44b15ec41e7b99809697 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Tue, 24 Jul 2012 13:59:24 +0200 Subject: Mark missing [UG]ID cache data separately from flags. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This simplifies the syslog() path a little, and allows us to express "[UG]ID should be cached but no value is set.". Signed-off-by: Miloslav Trmač --- lib/umberlog.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/umberlog.c b/lib/umberlog.c index c7fd874..7231065 100644 --- a/lib/umberlog.c +++ b/lib/umberlog.c @@ -71,8 +71,8 @@ static struct /* Cached data */ pid_t pid; /* -1 = no value cached */ - uid_t uid; - gid_t gid; + uid_t uid; /* (uid_t)-1 = no value cached */ + gid_t gid; /* (gid_t)-1 = no value cached */ char hostname[_POSIX_HOST_NAME_MAX + 1]; } ul_process_data = { @@ -111,8 +111,17 @@ ul_openlog (const char *ident, int option, int facility) ul_process_data.pid = -1; else ul_process_data.pid = getpid (); - ul_process_data.gid = getgid (); - ul_process_data.uid = getuid (); + if ((ul_process_data.flags & LOG_UL_NOCACHE) != 0 || + (ul_process_data.flags & LOG_UL_NOCACHE_UID) != 0) + { + ul_process_data.gid = (gid_t)-1; + ul_process_data.uid = (uid_t)-1; + } + else + { + ul_process_data.gid = getgid (); + ul_process_data.uid = getuid (); + } gethostname (ul_process_data.hostname, _POSIX_HOST_NAME_MAX); pthread_mutex_unlock (&ul_process_data.lock); } @@ -179,21 +188,23 @@ _find_pid (void) static inline uid_t _get_uid (void) { - if (ul_process_data.flags & LOG_UL_NOCACHE || - ul_process_data.flags & LOG_UL_NOCACHE_UID) - return getuid (); - else - return ul_process_data.uid; + uid_t uid; + + uid = ul_process_data.uid; + if (uid == (uid_t)-1) + uid = getuid (); + return uid; } static inline gid_t _get_gid (void) { - if (ul_process_data.flags & LOG_UL_NOCACHE || - ul_process_data.flags & LOG_UL_NOCACHE_UID) - return getgid (); - else - return ul_process_data.gid; + gid_t gid; + + gid = ul_process_data.gid; + if (gid == (gid_t)-1) + gid = getgid (); + return gid; } static inline const char * -- cgit