diff --git a/pressure-vessel/adverb.c b/pressure-vessel/adverb.c index 29188fc474137ef7fde6709a296532ecc57e3a65..ae826df342b2a8cfe6492366c18406ea203537c1 100644 --- a/pressure-vessel/adverb.c +++ b/pressure-vessel/adverb.c @@ -620,17 +620,6 @@ static GOptionEntry options[] = { NULL } }; -static int my_pid = -1; - -static void -cli_log_func (const gchar *log_domain, - GLogLevelFlags log_level, - const gchar *message, - gpointer user_data) -{ - g_printerr ("%s[%d]: %s\n", (const char *) user_data, my_pid, message); -} - int main (int argc, char *argv[]) @@ -649,8 +638,6 @@ main (int argc, struct sigaction terminate_child_action = {}; g_autoptr(FlatpakBwrap) wrapped_command = NULL; - my_pid = getpid (); - sigemptyset (&mask); sigaddset (&mask, SIGCHLD); @@ -674,7 +661,7 @@ main (int argc, g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE, - cli_log_func, (void *) g_get_prgname ()); + pv_log_to_stderr, NULL); context = g_option_context_new ( "COMMAND [ARG...]\n" @@ -710,7 +697,7 @@ main (int argc, if (opt_verbose) g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO, - cli_log_func, (void *) g_get_prgname ()); + pv_log_to_stderr, NULL); original_stdout = _srt_divert_stdout_to_stderr (error); diff --git a/pressure-vessel/launch.c b/pressure-vessel/launch.c index cc9023917f82596d312a1ca997c148e7cad31ec7..3740dcc3f84065b4b3a47739f4c89a0a5e7c9f27 100644 --- a/pressure-vessel/launch.c +++ b/pressure-vessel/launch.c @@ -516,17 +516,6 @@ static const GOptionEntry options[] = { NULL } }; -static int my_pid = -1; - -static void -cli_log_func (const gchar *log_domain, - GLogLevelFlags log_level, - const gchar *message, - gpointer user_data) -{ - g_printerr ("%s[%d]: %s\n", (const char *) user_data, my_pid, message); -} - int main (int argc, char *argv[]) @@ -555,8 +544,6 @@ main (int argc, GHashTableIter iter; gpointer key, value; - my_pid = getpid (); - setlocale (LC_ALL, ""); original_environ = g_get_environ (); @@ -566,7 +553,7 @@ main (int argc, g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE, - cli_log_func, (void *) g_get_prgname ()); + pv_log_to_stderr, NULL); context = g_option_context_new ("COMMAND [ARG...]"); g_option_context_set_summary (context, @@ -594,7 +581,7 @@ main (int argc, if (opt_verbose) g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO, - cli_log_func, (void *) g_get_prgname ()); + pv_log_to_stderr, NULL); original_stdout = _srt_divert_stdout_to_stderr (error); diff --git a/pressure-vessel/launcher.c b/pressure-vessel/launcher.c index 37e3b31faaeee2a1d03e7097fc1591fb6065f37c..6315cfe7b317ae3de45f2076473af6ded488d62f 100644 --- a/pressure-vessel/launcher.c +++ b/pressure-vessel/launcher.c @@ -873,17 +873,6 @@ static GOptionEntry options[] = { NULL } }; -static int my_pid = -1; - -static void -cli_log_func (const gchar *log_domain, - GLogLevelFlags log_level, - const gchar *message, - gpointer user_data) -{ - g_printerr ("%s[%d]: %s\n", (const char *) user_data, my_pid, message); -} - int main (int argc, char *argv[]) @@ -896,8 +885,6 @@ main (int argc, int ret = EX_USAGE; GBusNameOwnerFlags flags; - my_pid = getpid (); - global_listener = pv_portal_listener_new (); setlocale (LC_ALL, ""); @@ -906,7 +893,7 @@ main (int argc, g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE, - cli_log_func, (void *) g_get_prgname ()); + pv_log_to_stderr, NULL); context = g_option_context_new (""); g_option_context_set_summary (context, @@ -935,7 +922,7 @@ main (int argc, if (opt_verbose) g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO, - cli_log_func, (void *) g_get_prgname ()); + pv_log_to_stderr, NULL); if (!pv_portal_listener_set_up_info_fd (global_listener, opt_info_fd, diff --git a/pressure-vessel/utils.c b/pressure-vessel/utils.c index 8de743af348ee94764775e985aa0e166bebeddc9..35b526d2a93275c738b67ee4dec0a585dc4fc0f6 100644 --- a/pressure-vessel/utils.c +++ b/pressure-vessel/utils.c @@ -907,3 +907,19 @@ pv_current_namespace_path_to_host_path (const gchar *current_env_path) return path_on_host; } + +/** + * pv_log_to_stderr: + * @log_domain: the log domain of the message + * @log_level: the log level of the message + * @message: the message to process + * @user_data: not used + */ +void +pv_log_to_stderr (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer user_data) +{ + g_printerr ("%s[%d]: %s\n", g_get_prgname (), getpid (), message); +} diff --git a/pressure-vessel/utils.h b/pressure-vessel/utils.h index 266deebf35b9269b8800b3ecc68717c1f49dbce1..91cce4bb4cdc0e03befe7635a84a6187ec1e1f78 100644 --- a/pressure-vessel/utils.h +++ b/pressure-vessel/utils.h @@ -73,3 +73,8 @@ gchar *pv_current_namespace_path_to_host_path (const gchar *current_env_path); const char *pv_get_path_after (const char *str, const char *prefix); + +void pv_log_to_stderr (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer user_data); diff --git a/pressure-vessel/wrap.c b/pressure-vessel/wrap.c index e91328060d444a13a3e64dd6de7c081f336ce029..47426409246ec2b05742a57f66b75e2293774334 100644 --- a/pressure-vessel/wrap.c +++ b/pressure-vessel/wrap.c @@ -1187,17 +1187,6 @@ tristate_environment (const gchar *name) return TRISTATE_MAYBE; } -static int my_pid = -1; - -static void -cli_log_func (const gchar *log_domain, - GLogLevelFlags log_level, - const gchar *message, - gpointer user_data) -{ - g_printerr ("%s[%d]: %s\n", (const char *) user_data, my_pid, message); -} - int main (int argc, char *argv[]) @@ -1243,15 +1232,13 @@ main (int argc, g_autofree char *lock_env_fd = NULL; g_autoptr(GArray) pass_fds_through_adverb = g_array_new (FALSE, FALSE, sizeof (int)); - my_pid = getpid (); - setlocale (LC_ALL, ""); g_set_prgname ("pressure-vessel-wrap"); g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE, - cli_log_func, (void *) g_get_prgname ()); + pv_log_to_stderr, NULL); original_argv = g_new0 (char *, argc + 1); @@ -1311,6 +1298,11 @@ main (int argc, if (!g_option_context_parse (context, &argc, &argv, error)) goto out; + if (opt_verbose) + g_log_set_handler (G_LOG_DOMAIN, + G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO, + pv_log_to_stderr, NULL); + if (opt_runtime == NULL) opt_runtime = g_strdup (g_getenv ("PRESSURE_VESSEL_RUNTIME")); @@ -1546,10 +1538,6 @@ main (int argc, { g_auto(GStrv) env = g_strdupv (original_environ); - g_log_set_handler (G_LOG_DOMAIN, - G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO, - cli_log_func, (void *) g_get_prgname ()); - g_message ("Original argv:"); for (i = 0; i < original_argc; i++)