From dcea6d50ba8cfd7985c5628a20ce19f0b9ce9993 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 21 Mar 2012 12:57:19 +0100 Subject: Include the hostname in the JSON payload. Include the hostname (as returned by gethostname()) in the JSON payload. Test case updated to verify this. Signed-off-by: Gergely Nagy --- lib/cee-syslog.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib') diff --git a/lib/cee-syslog.c b/lib/cee-syslog.c index bac8435..6ad7abb 100644 --- a/lib/cee-syslog.c +++ b/lib/cee-syslog.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "cee-syslog.h" @@ -56,6 +57,7 @@ static __thread struct uid_t uid; gid_t gid; const char *ident; + char hostname[HOST_NAME_MAX + 1]; } cee_sys_settings; static void @@ -77,6 +79,8 @@ cee_openlog (const char *ident, int option, int facility) cee_sys_settings.gid = getgid (); cee_sys_settings.uid = getuid (); cee_sys_settings.ident = ident; + + gethostname (cee_sys_settings.hostname, HOST_NAME_MAX); } /** HELPERS **/ @@ -137,6 +141,14 @@ _get_gid (void) return cee_sys_settings.gid; } +static inline const char * +_get_hostname (void) +{ + if (cee_sys_settings.flags & LOG_CEE_NOCACHE) + gethostname (cee_sys_settings.hostname, HOST_NAME_MAX); + return cee_sys_settings.hostname; +} + static struct json_object * _cee_json_vappend (struct json_object *json, va_list ap) { @@ -179,6 +191,7 @@ _cee_discover (struct json_object *jo, int priority) "program", "%s", cee_sys_settings.ident, "uid", "%d", _get_uid (), "gid", "%d", _get_gid (), + "host", "%s", _get_hostname (), NULL); } -- cgit