From c5e0e2b6c8f1f408f9dd178053edfebc8387b19f Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sun, 14 Aug 2016 13:54:30 +0200 Subject: [PATCH] src: Switch from g_print() to g_log() Use G_LOG_USE_STRUCTURED to ensure that the structured logging mode is used. https://bugs.freedesktop.org/show_bug.cgi?id=97342 --- src/examples/Makefile.am | 1 + src/polkit/Makefile.am | 1 + src/polkitagent/Makefile.am | 1 + src/polkitagent/polkitagenthelperprivate.c | 6 +++--- src/polkitagent/polkitagentlistener.c | 12 +++++------ src/polkitagent/polkitagentsession.c | 24 +++++++++++----------- src/polkitbackend/Makefile.am | 1 + .../polkitbackendinteractiveauthority.c | 22 ++++++++++---------- src/polkitbackend/polkitbackendjsauthority.c | 4 ++-- .../polkitbackendsessionmonitor-systemd.c | 4 ++-- src/polkitbackend/polkitbackendsessionmonitor.c | 10 ++++----- src/polkitbackend/polkitd.c | 18 ++++++++-------- src/programs/Makefile.am | 1 + test/Makefile.am | 1 + test/mocklibc/bin/Makefile.am | 1 + test/mocklibc/src/Makefile.am | 1 + test/polkit/Makefile.am | 1 + test/polkitbackend/Makefile.am | 1 + 18 files changed, 60 insertions(+), 50 deletions(-) diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am index 71c4991..52b5a4e 100644 --- a/src/examples/Makefile.am +++ b/src/examples/Makefile.am @@ -13,6 +13,7 @@ AM_CPPFLAGS = \ -DPACKAGE_LIB_DIR=\""$(libdir)"\" \ -D_POSIX_PTHREAD_SEMANTICS \ -D_REENTRANT \ + -DG_LOG_USE_STRUCTURED \ $(NULL) bin_PROGRAMS = diff --git a/src/polkit/Makefile.am b/src/polkit/Makefile.am index 51befaf..3b8e9f3 100644 --- a/src/polkit/Makefile.am +++ b/src/polkit/Makefile.am @@ -12,6 +12,7 @@ AM_CPPFLAGS = \ -DPACKAGE_LIB_DIR=\""$(libdir)"\" \ -D_POSIX_PTHREAD_SEMANTICS \ -D_REENTRANT \ + -DG_LOG_USE_STRUCTURED \ $(NULL) BUILT_SOURCES = \ diff --git a/src/polkitagent/Makefile.am b/src/polkitagent/Makefile.am index 4b64165..612c403 100644 --- a/src/polkitagent/Makefile.am +++ b/src/polkitagent/Makefile.am @@ -15,6 +15,7 @@ AM_CPPFLAGS = \ -DPACKAGE_LIB_DIR=\""$(libdir)"\" \ -D_POSIX_PTHREAD_SEMANTICS \ -D_REENTRANT \ + -DG_LOG_USE_STRUCTURED \ $(NULL) BUILT_SOURCES = \ diff --git a/src/polkitagent/polkitagenthelperprivate.c b/src/polkitagent/polkitagenthelperprivate.c index e23f9f5..ae2a031 100644 --- a/src/polkitagent/polkitagenthelperprivate.c +++ b/src/polkitagent/polkitagenthelperprivate.c @@ -94,7 +94,7 @@ send_dbus_message (const char *cookie, const char *user) authority = polkit_authority_get_sync (NULL /* GCancellable* */, &error); if (authority == NULL) { - g_printerr ("Error getting authority: %s\n", error->message); + g_critical ("Error getting authority: %s", error->message); g_error_free (error); goto out; } @@ -102,7 +102,7 @@ send_dbus_message (const char *cookie, const char *user) identity = polkit_unix_user_new_for_name (user, &error); if (identity == NULL) { - g_printerr ("Error constructing identity: %s\n", error->message); + g_critical ("Error constructing identity: %s", error->message); g_error_free (error); goto out; } @@ -113,7 +113,7 @@ send_dbus_message (const char *cookie, const char *user) NULL, &error)) { - g_printerr ("polkit-agent-helper-1: error response to PolicyKit daemon: %s\n", error->message); + g_critical ("polkit-agent-helper-1: error response to PolicyKit daemon: %s", error->message); g_error_free (error); goto out; } diff --git a/src/polkitagent/polkitagentlistener.c b/src/polkitagent/polkitagentlistener.c index 4704b03..2ae8ecf 100644 --- a/src/polkitagent/polkitagentlistener.c +++ b/src/polkitagent/polkitagentlistener.c @@ -179,10 +179,10 @@ on_notify_authority_owner (GObject *object, owner = polkit_authority_get_owner (server->authority); if (owner == NULL) { - g_printerr ("PolicyKit daemon disconnected from the bus.\n"); + g_critical ("PolicyKit daemon disconnected from the bus."); if (server->is_registered) - g_printerr ("We are no longer a registered authentication agent.\n"); + g_critical ("We are no longer a registered authentication agent."); server->is_registered = FALSE; } @@ -193,17 +193,17 @@ on_notify_authority_owner (GObject *object, { GError *error; - g_printerr ("PolicyKit daemon reconnected to bus.\n"); - g_printerr ("Attempting to re-register as an authentication agent.\n"); + g_critical ("PolicyKit daemon reconnected to bus."); + g_critical ("Attempting to re-register as an authentication agent."); error = NULL; if (server_register (server, &error)) { - g_printerr ("We are now a registered authentication agent.\n"); + g_critical ("We are now a registered authentication agent."); } else { - g_printerr ("Failed to register as an authentication agent: %s\n", error->message); + g_critical ("Failed to register as an authentication agent: %s", error->message); g_error_free (error); } } diff --git a/src/polkitagent/polkitagentsession.c b/src/polkitagent/polkitagentsession.c index 895d75e..511b0c7 100644 --- a/src/polkitagent/polkitagentsession.c +++ b/src/polkitagent/polkitagentsession.c @@ -411,7 +411,7 @@ complete_session (PolkitAgentSession *session, if (!session->have_emitted_completed) { if (G_UNLIKELY (_show_debug ())) - g_print ("PolkitAgentSession: emitting ::completed(%s)\n", result ? "TRUE" : "FALSE"); + g_message ("PolkitAgentSession: emitting ::completed(%s)", result ? "TRUE" : "FALSE"); session->have_emitted_completed = TRUE; /* Note that the signal handler may drop the last reference to session. */ g_signal_emit_by_name (session, "completed", result); @@ -463,34 +463,34 @@ io_watch_have_data (GIOChannel *channel, unescaped = g_strcompress (line); if (G_UNLIKELY (_show_debug ())) - g_print ("PolkitAgentSession: read `%s' from helper\n", unescaped); + g_debug ("PolkitAgentSession: read `%s' from helper", unescaped); if (g_str_has_prefix (unescaped, "PAM_PROMPT_ECHO_OFF ")) { const gchar *s = unescaped + sizeof "PAM_PROMPT_ECHO_OFF " - 1; if (G_UNLIKELY (_show_debug ())) - g_print ("PolkitAgentSession: emitting ::request('%s', FALSE)\n", s); + g_debug ("PolkitAgentSession: emitting ::request('%s', FALSE)", s); g_signal_emit_by_name (session, "request", s, FALSE); } else if (g_str_has_prefix (unescaped, "PAM_PROMPT_ECHO_ON ")) { const gchar *s = unescaped + sizeof "PAM_PROMPT_ECHO_ON " - 1; if (G_UNLIKELY (_show_debug ())) - g_print ("PolkitAgentSession: emitting ::request('%s', TRUE)\n", s); + g_debug ("PolkitAgentSession: emitting ::request('%s', TRUE)", s); g_signal_emit_by_name (session, "request", s, TRUE); } else if (g_str_has_prefix (unescaped, "PAM_ERROR_MSG ")) { const gchar *s = unescaped + sizeof "PAM_ERROR_MSG " - 1; if (G_UNLIKELY (_show_debug ())) - g_print ("PolkitAgentSession: emitting ::show-error('%s')\n", s); + g_debug ("PolkitAgentSession: emitting ::show-error('%s')", s); g_signal_emit_by_name (session, "show-error", s); } else if (g_str_has_prefix (unescaped, "PAM_TEXT_INFO ")) { const gchar *s = unescaped + sizeof "PAM_TEXT_INFO " - 1; if (G_UNLIKELY (_show_debug ())) - g_print ("PolkitAgentSession: emitting ::show-info('%s')\n", s); + g_debug ("PolkitAgentSession: emitting ::show-info('%s')", s); g_signal_emit_by_name (session, "show-info", s); } else if (g_str_has_prefix (unescaped, "SUCCESS")) @@ -574,9 +574,9 @@ polkit_agent_session_initiate (PolkitAgentSession *session) { gchar *s; s = polkit_identity_to_string (session->identity); - g_print ("PolkitAgentSession: initiating authentication for identity `%s', cookie %s\n", - s, - session->cookie); + g_message ("PolkitAgentSession: initiating authentication for identity `%s', cookie %s", + s, + session->cookie); g_free (s); } @@ -616,13 +616,13 @@ polkit_agent_session_initiate (PolkitAgentSession *session) NULL, &error)) { - g_warning ("Cannot spawn helper: %s\n", error->message); + g_warning ("Cannot spawn helper: %s", error->message); g_error_free (error); goto error; } if (G_UNLIKELY (_show_debug ())) - g_print ("PolkitAgentSession: spawned helper with pid %d\n", (gint) session->child_pid); + g_debug ("PolkitAgentSession: spawned helper with pid %d", (gint) session->child_pid); session->child_stdin = (GOutputStream*)g_unix_output_stream_new (stdin_fd, TRUE); @@ -662,7 +662,7 @@ polkit_agent_session_cancel (PolkitAgentSession *session) g_return_if_fail (POLKIT_AGENT_IS_SESSION (session)); if (G_UNLIKELY (_show_debug ())) - g_print ("PolkitAgentSession: canceling authentication\n"); + g_debug ("PolkitAgentSession: canceling authentication"); complete_session (session, FALSE); } diff --git a/src/polkitbackend/Makefile.am b/src/polkitbackend/Makefile.am index a80ca36..afd1bcc 100644 --- a/src/polkitbackend/Makefile.am +++ b/src/polkitbackend/Makefile.am @@ -16,6 +16,7 @@ AM_CPPFLAGS = \ -DPACKAGE_LIB_DIR=\""$(libdir)"\" \ -D_POSIX_PTHREAD_SEMANTICS \ -D_REENTRANT \ + -DG_LOG_USE_STRUCTURED \ $(NULL) noinst_LTLIBRARIES=libpolkit-backend-1.la diff --git a/src/polkitbackend/polkitbackendinteractiveauthority.c b/src/polkitbackend/polkitbackendinteractiveauthority.c index 23152a4..e2fd3d7 100644 --- a/src/polkitbackend/polkitbackendinteractiveauthority.c +++ b/src/polkitbackend/polkitbackendinteractiveauthority.c @@ -499,7 +499,7 @@ _polkit_subject_get_cmdline (PolkitSubject *subject) &error); if (process == NULL) { - g_printerr ("Error getting process for system bus name `%s': %s\n", + g_critical ("Error getting process for system bus name `%s': %s", polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject)), error->message); g_error_free (error); @@ -521,7 +521,7 @@ _polkit_subject_get_cmdline (PolkitSubject *subject) &contents_len, &error)) { - g_printerr ("Error opening `%s': %s\n", + g_critical ("Error opening `%s': %s", filename, error->message); g_error_free (error); @@ -1924,7 +1924,7 @@ authentication_agent_begin_cb (GDBusProxy *proxy, res, &error)) { - g_printerr ("Error performing authentication: %s (%s %d)\n", + g_critical ("Error performing authentication: %s (%s %d)", error->message, g_quark_to_string (error->domain), error->code); @@ -2075,7 +2075,7 @@ get_localized_data_for_challenge (PolkitBackendInteractiveAuthority *authority, /* Set LANG and locale so g_dgettext() + friends work below */ if (setlocale (LC_ALL, locale) == NULL) { - g_printerr ("Invalid locale '%s'\n", locale); + g_critical ("Invalid locale '%s'", locale); } g_setenv ("LANG", locale, TRUE); @@ -2084,7 +2084,7 @@ get_localized_data_for_challenge (PolkitBackendInteractiveAuthority *authority, if (message_to_use != NULL) { message = g_strdup (g_dgettext (gettext_domain, message_to_use)); - /* g_print ("locale=%s, domain=%s, msg=`%s' -> `%s'\n", locale, gettext_domain, message_to_use, message); */ + /* g_message ("locale=%s, domain=%s, msg=`%s' -> `%s'", locale, gettext_domain, message_to_use, message); */ } icon_name = g_strdup (polkit_details_lookup (details, "polkit.icon_name")); @@ -2145,7 +2145,7 @@ add_pid (PolkitDetails *details, &error); if (process == NULL) { - g_printerr ("Error getting process for system bus name `%s': %s\n", + g_critical ("Error getting process for system bus name `%s': %s", polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject)), error->message); g_error_free (error); @@ -2162,7 +2162,7 @@ add_pid (PolkitDetails *details, { gchar *s; s = polkit_subject_to_string (subject); - g_printerr ("Don't know how to get pid from subject of type %s: %s\n", + g_critical ("Don't know how to get pid from subject of type %s: %s", g_type_name (G_TYPE_FROM_INSTANCE (subject)), s); g_free (s); @@ -2457,7 +2457,7 @@ authentication_agent_cancel_cb (GDBusProxy *proxy, error = NULL; if (!g_dbus_proxy_call_finish (proxy, res, &error)) { - g_printerr ("Error cancelling authentication: %s\n", error->message); + g_critical ("Error cancelling authentication: %s", error->message); g_error_free (error); } } @@ -3061,7 +3061,7 @@ temporary_authorization_store_has_authorization (TemporaryAuthorizationStore *st &error); if (subject_to_use == NULL) { - g_printerr ("Error getting process for system bus name `%s': %s\n", + g_critical ("Error getting process for system bus name `%s': %s", polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject)), error->message); g_error_free (error); @@ -3131,7 +3131,7 @@ on_unix_process_check_vanished_timeout (gpointer user_data) { if (error != NULL) { - g_printerr ("Error checking if process exists: %s\n", error->message); + g_critical ("Error checking if process exists: %s", error->message); g_error_free (error); } else @@ -3222,7 +3222,7 @@ temporary_authorization_store_add_authorization (TemporaryAuthorizationStore *st &error); if (subject_to_use == NULL) { - g_printerr ("Error getting process for system bus name `%s': %s\n", + g_critical ("Error getting process for system bus name `%s': %s", polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject)), error->message); g_error_free (error); diff --git a/src/polkitbackend/polkitbackendjsauthority.c b/src/polkitbackend/polkitbackendjsauthority.c index 25b8e77..ab30345 100644 --- a/src/polkitbackend/polkitbackendjsauthority.c +++ b/src/polkitbackend/polkitbackendjsauthority.c @@ -361,7 +361,7 @@ load_scripts (PolkitBackendJsAuthority *authority) continue; } - //g_print ("Successfully loaded and evaluated script `%s'\n", filename); + //g_message ("Successfully loaded and evaluated script `%s'", filename); num_scripts++; } @@ -431,7 +431,7 @@ on_dir_monitor_changed (GFileMonitor *monitor, name = g_file_get_basename (file); - /* g_print ("event_type=%d file=%p name=%s\n", event_type, file, name); */ + /* g_message ("event_type=%d file=%p name=%s", event_type, file, name); */ if (!g_str_has_prefix (name, ".") && !g_str_has_prefix (name, "#") && g_str_has_suffix (name, ".rules") && diff --git a/src/polkitbackend/polkitbackendsessionmonitor-systemd.c b/src/polkitbackend/polkitbackendsessionmonitor-systemd.c index 2a6c739..bab9802 100644 --- a/src/polkitbackend/polkitbackendsessionmonitor-systemd.c +++ b/src/polkitbackend/polkitbackendsessionmonitor-systemd.c @@ -107,7 +107,7 @@ sd_source_new (void) if ((ret = sd_login_monitor_new (NULL, &sd_source->monitor)) < 0) { - g_printerr ("Error getting login monitor: %d", ret); + g_critical ("Error getting login monitor: %d", ret); } else { @@ -168,7 +168,7 @@ polkit_backend_session_monitor_init (PolkitBackendSessionMonitor *monitor) monitor->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (monitor->system_bus == NULL) { - g_printerr ("Error getting system bus: %s", error->message); + g_critical ("Error getting system bus: %s", error->message); g_error_free (error); } diff --git a/src/polkitbackend/polkitbackendsessionmonitor.c b/src/polkitbackend/polkitbackendsessionmonitor.c index e1a9ab3..ecfca66 100644 --- a/src/polkitbackend/polkitbackendsessionmonitor.c +++ b/src/polkitbackend/polkitbackendsessionmonitor.c @@ -172,14 +172,14 @@ polkit_backend_session_monitor_init (PolkitBackendSessionMonitor *monitor) monitor->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (monitor->system_bus == NULL) { - g_printerr ("Error getting system bus: %s", error->message); + g_critical ("Error getting system bus: %s", error->message); g_error_free (error); } error = NULL; if (!ensure_database (monitor, &error)) { - g_printerr ("Error loading " CKDB_PATH ": %s", error->message); + g_critical ("Error loading " CKDB_PATH ": %s", error->message); g_error_free (error); } @@ -192,7 +192,7 @@ polkit_backend_session_monitor_init (PolkitBackendSessionMonitor *monitor) g_object_unref (file); if (monitor->database_monitor == NULL) { - g_printerr ("Error monitoring " CKDB_PATH ": %s", error->message); + g_critical ("Error monitoring " CKDB_PATH ": %s", error->message); g_error_free (error); } else @@ -443,7 +443,7 @@ get_boolean (PolkitBackendSessionMonitor *monitor, error = NULL; if (!ensure_database (monitor, &error)) { - g_printerr ("Error getting boolean `%s' in group `%s': Error ensuring CK database at " CKDB_PATH ": %s", + g_critical ("Error getting boolean `%s' in group `%s': Error ensuring CK database at " CKDB_PATH ": %s", key_name, group, error->message); @@ -455,7 +455,7 @@ get_boolean (PolkitBackendSessionMonitor *monitor, ret = g_key_file_get_boolean (monitor->database, group, key_name, &error); if (error != NULL) { - g_printerr ("Error looking %s using " CKDB_PATH " for %s: %s\n", + g_critical ("Error looking %s using " CKDB_PATH " for %s: %s", key_name, group, error->message); diff --git a/src/polkitbackend/polkitd.c b/src/polkitbackend/polkitd.c index db964bc..51fbdf7 100644 --- a/src/polkitbackend/polkitd.c +++ b/src/polkitbackend/polkitd.c @@ -52,7 +52,7 @@ on_bus_acquired (GDBusConnection *connection, { GError *error; - g_print ("Connected to the system bus\n"); + g_message ("Connected to the system bus"); g_assert (registration_id == NULL); @@ -63,7 +63,7 @@ on_bus_acquired (GDBusConnection *connection, &error); if (registration_id == NULL) { - g_printerr ("Error registering authority: %s\n", error->message); + g_critical ("Error registering authority: %s", error->message); g_error_free (error); g_main_loop_quit (loop); /* exit */ } @@ -95,7 +95,7 @@ on_name_acquired (GDBusConnection *connection, static gboolean on_sigint (gpointer user_data) { - g_print ("Handling SIGINT\n"); + g_message ("Handling SIGINT"); g_main_loop_quit (loop); return TRUE; } @@ -240,7 +240,7 @@ main (int argc, error = NULL; if (!g_option_context_parse (opt_context, &argc, &argv, &error)) { - g_printerr ("Error parsing options: %s\n", error->message); + g_critical ("Error parsing options: %s", error->message); g_error_free (error); goto out; } @@ -248,13 +248,13 @@ main (int argc, error = NULL; if (!become_user (POLKITD_USER, &error)) { - g_printerr ("Error switching to user %s: %s\n", + g_critical ("Error switching to user %s: %s", POLKITD_USER, error->message); g_clear_error (&error); goto out; } - g_print ("Successfully changed to user %s\n", POLKITD_USER); + g_message ("Successfully changed to user %s", POLKITD_USER); if (g_getenv ("PATH") == NULL) g_setenv ("PATH", "/usr/bin:/bin:/usr/sbin:/sbin", TRUE); @@ -277,12 +277,12 @@ main (int argc, NULL, NULL); - g_print ("Entering main event loop\n"); + g_message ("Entering main event loop"); g_main_loop_run (loop); ret = 0; - g_print ("Shutting down\n"); + g_message ("Shutting down"); out: if (sigint_id > 0) g_source_remove (sigint_id); @@ -297,6 +297,6 @@ main (int argc, if (opt_context != NULL) g_option_context_free (opt_context); - g_print ("Exiting with code %d\n", ret); + g_message ("Exiting with code %d", ret); return ret; } diff --git a/src/programs/Makefile.am b/src/programs/Makefile.am index 880b90b..b6cdf98 100644 --- a/src/programs/Makefile.am +++ b/src/programs/Makefile.am @@ -13,6 +13,7 @@ AM_CPPFLAGS = \ -DPACKAGE_LIB_DIR=\""$(libdir)"\" \ -D_POSIX_PTHREAD_SEMANTICS \ -D_REENTRANT \ + -DG_LOG_USE_STRUCTURED \ $(NULL) # ---------------------------------------------------------------------------------------------------- diff --git a/test/Makefile.am b/test/Makefile.am index 59d0680..ba26769 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,6 +1,7 @@ SUBDIRS = mocklibc . polkit polkitbackend AM_CFLAGS = $(GLIB_CFLAGS) +AM_CPPFLAGS = -DG_LOG_USE_STRUCTURED noinst_LTLIBRARIES = libpolkit-test-helper.la libpolkit_test_helper_la_SOURCES = polkittesthelper.c polkittesthelper.h diff --git a/test/mocklibc/bin/Makefile.am b/test/mocklibc/bin/Makefile.am index 499c5c7..b77f277 100644 --- a/test/mocklibc/bin/Makefile.am +++ b/test/mocklibc/bin/Makefile.am @@ -1,3 +1,4 @@ +AM_CPPFLAGS = -DG_LOG_USE_STRUCTURED bin_SCRIPTS = mocklibc diff --git a/test/mocklibc/src/Makefile.am b/test/mocklibc/src/Makefile.am index 1103b9d..21a5ad8 100644 --- a/test/mocklibc/src/Makefile.am +++ b/test/mocklibc/src/Makefile.am @@ -1,3 +1,4 @@ +AM_CPPFLAGS = -DG_LOG_USE_STRUCTURED lib_LTLIBRARIES = libmocklibc.la libmocklibc_la_SOURCES = pwd.c grp.c netdb.c netgroup.c netgroup.h diff --git a/test/polkit/Makefile.am b/test/polkit/Makefile.am index 1e0a23f..ab6d96f 100644 --- a/test/polkit/Makefile.am +++ b/test/polkit/Makefile.am @@ -14,6 +14,7 @@ AM_CPPFLAGS = \ -DPACKAGE_LIB_DIR=\""$(libdir)"\" \ -D_POSIX_PTHREAD_SEMANTICS \ -D_REENTRANT \ + -DG_LOG_USE_STRUCTURED \ $(NULL) AM_CFLAGS = \ diff --git a/test/polkitbackend/Makefile.am b/test/polkitbackend/Makefile.am index 8859c1f..d27f3f5 100644 --- a/test/polkitbackend/Makefile.am +++ b/test/polkitbackend/Makefile.am @@ -14,6 +14,7 @@ AM_CPPFLAGS = \ -DPACKAGE_LIB_DIR=\""$(libdir)"\" \ -D_POSIX_PTHREAD_SEMANTICS \ -D_REENTRANT \ + -DG_LOG_USE_STRUCTURED \ $(NULL) AM_CFLAGS = \ -- 2.7.4