summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO.org3
-rw-r--r--lib/cee-syslog.c28
-rw-r--r--lib/cee-syslog.h5
3 files changed, 32 insertions, 4 deletions
diff --git a/TODO.org b/TODO.org
index 628b5c1..2a81e10 100644
--- a/TODO.org
+++ b/TODO.org
@@ -5,7 +5,8 @@
* TODO Features
** TODO More autodiscovery
-*** TODO UID/GID discovery
+*** DONE UID/GID discovery
+CLOSED: [2012-03-20 Tue 11:47]
Cached by default, should be able to turn of caching with the global
LOG_CEE_NOCACHE flag, and also with LOG_CEE_NOCACHE_UID flag.
*** TODO Thread-id discovery
diff --git a/lib/cee-syslog.c b/lib/cee-syslog.c
index 60d8517..0256164 100644
--- a/lib/cee-syslog.c
+++ b/lib/cee-syslog.c
@@ -53,6 +53,8 @@ static __thread struct
int facility;
pid_t pid;
+ uid_t uid;
+ gid_t gid;
const char *ident;
} cee_sys_settings;
@@ -72,6 +74,8 @@ cee_openlog (const char *ident, int option, int facility)
cee_sys_settings.flags = option;
cee_sys_settings.facility = facility;
cee_sys_settings.pid = getpid ();
+ cee_sys_settings.gid = getgid ();
+ cee_sys_settings.uid = getuid ();
cee_sys_settings.ident = ident;
}
@@ -104,7 +108,7 @@ _find_prio (int prio)
return "<unknown>";
}
-static inline const pid_t
+static inline pid_t
_find_pid (void)
{
if (cee_sys_settings.flags & LOG_CEE_NOCACHE)
@@ -113,6 +117,26 @@ _find_pid (void)
return cee_sys_settings.pid;
}
+static inline uid_t
+_get_uid (void)
+{
+ if (cee_sys_settings.flags & LOG_CEE_NOCACHE ||
+ cee_sys_settings.flags & LOG_CEE_NOCACHE_UID)
+ return getuid ();
+ else
+ return cee_sys_settings.uid;
+}
+
+static inline uid_t
+_get_gid (void)
+{
+ if (cee_sys_settings.flags & LOG_CEE_NOCACHE ||
+ cee_sys_settings.flags & LOG_CEE_NOCACHE_UID)
+ return getgid ();
+ else
+ return cee_sys_settings.gid;
+}
+
static struct json_object *
_cee_json_vappend (struct json_object *json, va_list ap)
{
@@ -153,6 +177,8 @@ _cee_discover (struct json_object *jo, int priority)
"facility", "%s", _find_facility (),
"priority", "%s", _find_prio (priority),
"program", "%s", cee_sys_settings.ident,
+ "uid", "%d", _get_uid (),
+ "gid", "%d", _get_gid (),
NULL);
}
diff --git a/lib/cee-syslog.h b/lib/cee-syslog.h
index 171f3ae..bba25c4 100644
--- a/lib/cee-syslog.h
+++ b/lib/cee-syslog.h
@@ -31,8 +31,9 @@
#include <syslog.h>
#include <stdarg.h>
-#define LOG_CEE_NODISCOVER 0x40
-#define LOG_CEE_NOCACHE 0x80
+#define LOG_CEE_NODISCOVER 0x0040
+#define LOG_CEE_NOCACHE 0x0080
+#define LOG_CEE_NOCACHE_UID 0x0100
char *cee_format (int priority, const char *msg_format, ...);
char *cee_vformat (int priority, const char *msg_format, va_list ap);