mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2025-12-25 04:40:07 +01:00
Only redirect child processes to systemd Journal if using syslog
In particular this means the test suite won't spam the Journal any more. 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
1c807207bb
commit
814560d56a
8 changed files with 36 additions and 11 deletions
|
|
@ -1661,6 +1661,7 @@ bus_activation_activate_service (BusActivation *activation,
|
|||
dbus_bool_t was_pending_activation;
|
||||
DBusString command;
|
||||
int limit;
|
||||
DBusSpawnFlags flags = DBUS_SPAWN_NONE;
|
||||
|
||||
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
||||
|
||||
|
|
@ -2097,10 +2098,14 @@ bus_activation_activate_service (BusActivation *activation,
|
|||
|
||||
dbus_error_init (&tmp_error);
|
||||
|
||||
if (bus_context_get_using_syslog (activation->context))
|
||||
flags |= DBUS_SPAWN_REDIRECT_OUTPUT;
|
||||
|
||||
if (!_dbus_spawn_async_with_babysitter (&pending_activation->babysitter,
|
||||
service_name,
|
||||
argv,
|
||||
envp,
|
||||
flags,
|
||||
child_setup,
|
||||
activation,
|
||||
&tmp_error))
|
||||
|
|
|
|||
|
|
@ -1366,6 +1366,12 @@ bus_context_get_initial_fd_limit (BusContext *context)
|
|||
return context->initial_fd_limit;
|
||||
}
|
||||
|
||||
dbus_bool_t
|
||||
bus_context_get_using_syslog (BusContext *context)
|
||||
{
|
||||
return context->syslog;
|
||||
}
|
||||
|
||||
void
|
||||
bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ int bus_context_get_max_match_rules_per_connection (BusContext
|
|||
int bus_context_get_max_replies_per_connection (BusContext *context);
|
||||
int bus_context_get_reply_timeout (BusContext *context);
|
||||
DBusRLimit * bus_context_get_initial_fd_limit (BusContext *context);
|
||||
dbus_bool_t bus_context_get_using_syslog (BusContext *context);
|
||||
void bus_context_log (BusContext *context,
|
||||
DBusSystemLogSeverity severity,
|
||||
const char *msg,
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ check_spawn_nonexistent (void *data)
|
|||
|
||||
argv[0] = "/this/does/not/exist/32542sdgafgafdg";
|
||||
if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_nonexistent", argv,
|
||||
NULL, NULL, NULL,
|
||||
NULL, DBUS_SPAWN_NONE, NULL, NULL,
|
||||
&error))
|
||||
{
|
||||
_dbus_babysitter_block_for_child_exit (sitter);
|
||||
|
|
@ -113,7 +113,7 @@ check_spawn_segfault (void *data)
|
|||
}
|
||||
|
||||
if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_segfault", argv,
|
||||
NULL, NULL, NULL,
|
||||
NULL, DBUS_SPAWN_NONE, NULL, NULL,
|
||||
&error))
|
||||
{
|
||||
_dbus_babysitter_block_for_child_exit (sitter);
|
||||
|
|
@ -168,7 +168,7 @@ check_spawn_exit (void *data)
|
|||
}
|
||||
|
||||
if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_exit", argv,
|
||||
NULL, NULL, NULL,
|
||||
NULL, DBUS_SPAWN_NONE, NULL, NULL,
|
||||
&error))
|
||||
{
|
||||
_dbus_babysitter_block_for_child_exit (sitter);
|
||||
|
|
@ -219,7 +219,7 @@ check_spawn_and_kill (void *data)
|
|||
}
|
||||
|
||||
if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_and_kill", argv,
|
||||
NULL, NULL, NULL,
|
||||
NULL, DBUS_SPAWN_NONE, NULL, NULL,
|
||||
&error))
|
||||
{
|
||||
_dbus_babysitter_kill_child (sitter);
|
||||
|
|
|
|||
|
|
@ -645,6 +645,7 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
|
|||
const char *log_name,
|
||||
char **argv,
|
||||
char **envp,
|
||||
DBusSpawnFlags flags _DBUS_GNUC_UNUSED,
|
||||
DBusSpawnChildSetupFunc child_setup _DBUS_GNUC_UNUSED,
|
||||
void *user_data _DBUS_GNUC_UNUSED,
|
||||
DBusError *error)
|
||||
|
|
|
|||
|
|
@ -1216,6 +1216,7 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
|
|||
const char *log_name,
|
||||
char **argv,
|
||||
char **env,
|
||||
DBusSpawnFlags flags,
|
||||
DBusSpawnChildSetupFunc child_setup,
|
||||
void *user_data,
|
||||
DBusError *error)
|
||||
|
|
@ -1316,12 +1317,15 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
|
|||
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
||||
|
||||
#ifdef HAVE_SYSTEMD
|
||||
/* This may fail, but it's not critical.
|
||||
* In particular, if we were compiled with journald support but are now
|
||||
* running on a non-systemd system, this is going to fail, so we
|
||||
* have to cope gracefully. */
|
||||
fd_out = sd_journal_stream_fd (sitter->log_name, LOG_INFO, FALSE);
|
||||
fd_err = sd_journal_stream_fd (sitter->log_name, LOG_WARNING, FALSE);
|
||||
if (flags & DBUS_SPAWN_REDIRECT_OUTPUT)
|
||||
{
|
||||
/* This may fail, but it's not critical.
|
||||
* In particular, if we were compiled with journald support but are now
|
||||
* running on a non-systemd system, this is going to fail, so we
|
||||
* have to cope gracefully. */
|
||||
fd_out = sd_journal_stream_fd (sitter->log_name, LOG_INFO, FALSE);
|
||||
fd_err = sd_journal_stream_fd (sitter->log_name, LOG_WARNING, FALSE);
|
||||
}
|
||||
#endif
|
||||
|
||||
pid = fork ();
|
||||
|
|
|
|||
|
|
@ -38,10 +38,16 @@ typedef struct DBusBabysitter DBusBabysitter;
|
|||
typedef void (* DBusBabysitterFinishedFunc) (DBusBabysitter *sitter,
|
||||
void *user_data);
|
||||
|
||||
typedef enum {
|
||||
DBUS_SPAWN_REDIRECT_OUTPUT = (1 << 0),
|
||||
DBUS_SPAWN_NONE = 0
|
||||
} DBusSpawnFlags;
|
||||
|
||||
dbus_bool_t _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
|
||||
const char *log_name,
|
||||
char **argv,
|
||||
char **env,
|
||||
DBusSpawnFlags flags,
|
||||
DBusSpawnChildSetupFunc child_setup,
|
||||
void *user_data,
|
||||
DBusError *error);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@ main (int argc, char **argv)
|
|||
argv_copy [i] = argv[i + 1];
|
||||
argv_copy[argc - 1] = NULL;
|
||||
|
||||
if (!_dbus_spawn_async_with_babysitter (NULL, argv_copy[0], argv_copy, NULL, setup_func, NULL, &error))
|
||||
if (!_dbus_spawn_async_with_babysitter (NULL, argv_copy[0], argv_copy, NULL,
|
||||
DBUS_SPAWN_NONE, setup_func, NULL,
|
||||
&error))
|
||||
{
|
||||
fprintf (stderr, "Could not launch application: \"%s\"\n",
|
||||
error.message);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue