From 61233d3703071993a1505570de765d8ef1bf7ee2 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 13 Feb 2015 04:27:27 -0500 Subject: [PATCH 1/2] Drop use of libgsystem, move single API call into shell-global.c See https://mail.gnome.org/archives/desktop-devel-list/2015-February/msg00121.html We presently only indirectly link to it via this one call; until GLib gains structured logging, simply import the code to wrap the journal logging in an introspectable API into Shell. https://bugzilla.gnome.org/show_bug.cgi?id=744457 --- js/ui/main.js | 12 +++--------- src/shell-global.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/shell-global.h | 3 +++ 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/js/ui/main.js b/js/ui/main.js index 2459069..45df8b4 100644 --- a/js/ui/main.js +++ b/js/ui/main.js @@ -208,16 +208,10 @@ function _initializeUI() { if (screenShield) { screenShield.lockIfWasLocked(); } - if (LoginManager.haveSystemd() && - sessionMode.currentMode != 'gdm' && + if (sessionMode.currentMode != 'gdm' && sessionMode.currentMode != 'initial-setup') { - // Do not import globally to not depend - // on systemd on non-systemd systems. - let GSystem = imports.gi.GSystem; - GSystem.log_structured_print('GNOME Shell started at ' + _startDate, - ['MESSAGE_ID=' + GNOMESHELL_STARTED_MESSAGE_ID]); - } else { - log('GNOME Shell started at ' + _startDate); + Shell.log_structured_print('GNOME Shell started at ' + _startDate, + ['MESSAGE_ID=' + GNOMESHELL_STARTED_MESSAGE_ID]); } }); } diff --git a/src/shell-global.c b/src/shell-global.c index d90ceaf..3a27f31 100644 --- a/src/shell-global.c +++ b/src/shell-global.c @@ -28,6 +28,12 @@ #include #include +#ifdef HAVE_SYSTEMD +#include +#include +#include +#endif + /* Memory report bits */ #ifdef HAVE_MALLINFO #include @@ -1307,6 +1313,52 @@ shell_global_reexec_self (ShellGlobal *global) } /** + * shell_global_log_structured: + * @message: A message to print + * @keys: (allow-none) (array zero-terminated=1) (element-type utf8): Optional structured data + * + * Log structured data in an operating-system specific fashion. The + * parameter @opts should be an array of UTF-8 KEY=VALUE strings. + * This function does not support binary data. See + * http://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html + * or more information about fields that can be used on a systemd + * system. + * + */ +void +shell_global_log_structured (const char *message, + const char *const *keys) +{ +#ifdef HAVE_SYSTEMD + const char *const*iter; + char *msgkey; + guint i, n_opts; + struct iovec *iovs; + + for (n_opts = 0, iter = keys; *iter; iter++, n_opts++) + ; + + n_opts++; /* Add one for MESSAGE= */ + iovs = g_alloca (sizeof (struct iovec) * n_opts); + + for (i = 0, iter = keys; *iter; iter++, i++) { + iovs[i].iov_base = (char*)keys[i]; + iovs[i].iov_len = strlen (keys[i]); + } + g_assert(i == n_opts-1); + msgkey = g_strconcat ("MESSAGE=", message, NULL); + iovs[i].iov_base = msgkey; + iovs[i].iov_len = strlen (msgkey); + + // The code location isn't useful since we're wrapping + sd_journal_sendv (iovs, n_opts); + g_free (msgkey); +#else + g_print ("%s\n", message); +#endif +} + +/** * shell_global_notify_error: * @global: a #ShellGlobal * @msg: Error message diff --git a/src/shell-global.h b/src/shell-global.h index a5630ec..25afe17 100644 --- a/src/shell-global.h +++ b/src/shell-global.h @@ -126,6 +126,9 @@ void shell_global_init_xdnd (ShellGlobal *global); void shell_global_reexec_self (ShellGlobal *global); +void shell_global_log_structured (const char *message, + const char *const *keys); + const char * shell_global_get_session_mode (ShellGlobal *global); void shell_global_set_runtime_state (ShellGlobal *global, -- 2.3.6 From 1fe15cf0dbd98afb7b1084c5556f6b6b9a0e62f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 13 Feb 2015 23:02:06 +0100 Subject: [PATCH 2/2] main: Fix structured_log() call Meh, I should have caught that one in review ... --- js/ui/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/ui/main.js b/js/ui/main.js index 45df8b4..6865c41 100644 --- a/js/ui/main.js +++ b/js/ui/main.js @@ -210,8 +210,8 @@ function _initializeUI() { } if (sessionMode.currentMode != 'gdm' && sessionMode.currentMode != 'initial-setup') { - Shell.log_structured_print('GNOME Shell started at ' + _startDate, - ['MESSAGE_ID=' + GNOMESHELL_STARTED_MESSAGE_ID]); + Shell.Global.log_structured('GNOME Shell started at ' + _startDate, + ['MESSAGE_ID=' + GNOMESHELL_STARTED_MESSAGE_ID]); } }); } -- 2.3.6