From: Simon McVittie Date: Thu, 21 Jul 2016 09:29:10 +0000 (+0100) Subject: _dbus_init_system_log: record a syslog tag (executable name) X-Git-Tag: dbus-1.11.4~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8ef699dd20c8ca7ec0afe6147655f2cb6d4117fc;p=thirdparty%2Fdbus.git _dbus_init_system_log: record a syslog tag (executable name) Instead of hard-coding "dbus", report what the executable really is. Signed-off-by: Simon McVittie Reviewed-by: Ralf Habacker Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97009 --- diff --git a/bus/bus.c b/bus/bus.c index 9f1daa2eb..b8db6d806 100644 --- a/bus/bus.c +++ b/bus/bus.c @@ -288,7 +288,7 @@ process_config_first_time_only (BusContext *context, auth_mechanisms = NULL; pidfile = NULL; - _dbus_init_system_log (TRUE); + _dbus_init_system_log ("dbus-daemon", TRUE); if (flags & BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION) context->systemd_activation = TRUE; diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index c156dcfbd..381e2fcf0 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -4523,8 +4523,21 @@ _dbus_restore_socket_errno (int saved_errno) errno = saved_errno; } +static const char *syslog_tag = "dbus"; + +/** + * Initialize the system log. + * + * The "tag" is not copied, and must remain valid for the entire lifetime of + * the process or until _dbus_init_system_log() is called again. In practice + * it will normally be a constant. + * + * @param tag the name of the executable (syslog tag) + * @param is_daemon #TRUE if this is the dbus-daemon + */ void -_dbus_init_system_log (dbus_bool_t is_daemon) +_dbus_init_system_log (const char *tag, + dbus_bool_t is_daemon) { #ifdef HAVE_SYSLOG_H int logopts = LOG_PID; @@ -4536,7 +4549,8 @@ _dbus_init_system_log (dbus_bool_t is_daemon) logopts |= LOG_PERROR; #endif - openlog ("dbus", logopts, LOG_DAEMON); + syslog_tag = tag; + openlog (tag, logopts, LOG_DAEMON); #endif } @@ -4583,7 +4597,7 @@ _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args { /* vsyslog() won't write to stderr, so we'd better do it */ DBUS_VA_COPY (tmp, args); - fprintf (stderr, "dbus[" DBUS_PID_FORMAT "]: ", _dbus_getpid ()); + fprintf (stderr, "%s[" DBUS_PID_FORMAT "]: ", syslog_tag, _dbus_getpid ()); vfprintf (stderr, msg, tmp); fputc ('\n', stderr); va_end (tmp); diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 7dac66d6c..efd3d54fb 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -3634,8 +3634,19 @@ _dbus_restore_socket_errno (int saved_errno) _dbus_win_set_errno (saved_errno); } +/** + * Initialize the system log. + * + * The "tag" is not copied, and must remain valid for the entire lifetime of + * the process or until _dbus_init_system_log() is called again. In practice + * it will normally be a constant. + * + * @param tag the name of the executable (syslog tag) + * @param is_daemon #TRUE if this is the dbus-daemon + */ void -_dbus_init_system_log (dbus_bool_t is_daemon) +_dbus_init_system_log (const char *tag, + dbus_bool_t is_daemon) { /* OutputDebugStringA doesn't need any special initialization, do nothing */ } diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index fb4be88ad..d5594c728 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -556,7 +556,8 @@ dbus_bool_t _dbus_user_at_console (const char *username, DBusError *error); DBUS_PRIVATE_EXPORT -void _dbus_init_system_log (dbus_bool_t is_daemon); +void _dbus_init_system_log (const char *tag, + dbus_bool_t is_daemon); typedef enum { DBUS_SYSTEM_LOG_INFO, diff --git a/test/internals/syslog.c b/test/internals/syslog.c index 805c57840..c0c1f910c 100644 --- a/test/internals/syslog.c +++ b/test/internals/syslog.c @@ -56,7 +56,7 @@ test_syslog (Fixture *f, #ifndef G_OS_WIN32 if (g_test_trap_fork (0, 0)) { - _dbus_init_system_log (FALSE); + _dbus_init_system_log ("test-syslog", FALSE); _dbus_system_log (DBUS_SYSTEM_LOG_FATAL, MESSAGE "%d", 23); /* should not be reached: exit 0 so the assertion in the main process * will fail */ @@ -68,7 +68,7 @@ test_syslog (Fixture *f, if (g_test_trap_fork (0, 0)) { - _dbus_init_system_log (FALSE); + _dbus_init_system_log ("test-syslog", FALSE); _dbus_system_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42); _dbus_system_log (DBUS_SYSTEM_LOG_WARNING, MESSAGE "%d", 45); _dbus_system_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666); @@ -79,7 +79,7 @@ test_syslog (Fixture *f, g_test_trap_assert_stderr ("*" MESSAGE "42\n*" MESSAGE "45\n*" MESSAGE "666\n*"); #endif /* manual test (this is the best we can do on Windows) */ - _dbus_init_system_log (FALSE); + _dbus_init_system_log ("test-syslog", FALSE); _dbus_system_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42); _dbus_system_log (DBUS_SYSTEM_LOG_WARNING, MESSAGE "%d", 45); _dbus_system_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666);