mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-01-09 00:30:18 +01:00
_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 <smcv@debian.org> Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97009
This commit is contained in:
parent
a227177918
commit
8ef699dd20
5 changed files with 35 additions and 9 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue