_dbus_init_system_log: record a syslog tag (executable name)
authorSimon McVittie <smcv@debian.org>
Thu, 21 Jul 2016 09:29:10 +0000 (10:29 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Thu, 11 Aug 2016 15:41:16 +0000 (16:41 +0100)
Instead of hard-coding "dbus", report what the executable really is.

Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97009

bus/bus.c
dbus/dbus-sysdeps-unix.c
dbus/dbus-sysdeps-win.c
dbus/dbus-sysdeps.h
test/internals/syslog.c

index 9f1daa2..b8db6d8 100644 (file)
--- 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;
index c156dcf..381e2fc 100644 (file)
@@ -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);
index 7dac66d..efd3d54 100644 (file)
@@ -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 */
 }
index fb4be88..d5594c7 100644 (file)
@@ -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,
index 805c578..c0c1f91 100644 (file)
@@ -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);