From e7675cc3c3c078aedf57e6d386f10c47eb22f0d1 Mon Sep 17 00:00:00 2001 From: Felix Zhang Date: Sun, 17 Jul 2016 17:27:06 +0800 Subject: [PATCH] logging to systemd journal configurable --- configure.ac | 19 +++++++++++++++++++ gnome-session/gsm-autostart-app.c | 6 ++++-- gnome-session/gsm-manager.c | 8 ++++---- gnome-session/main.c | 4 ++-- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 223ee89..f248e9d 100644 --- a/configure.ac +++ b/configure.ac @@ -147,6 +147,25 @@ AC_SUBST(SYSTEMD_LIBS) AM_CONDITIONAL(HAVE_SYSTEMD, [test "$enable_systemd" = "yes"], [Using systemd]) dnl ==================================================================== +dnl systemd journal support +dnl ==================================================================== +AC_ARG_ENABLE([systemd-journal], + AS_HELP_STRING([--enable-systemd-journal], [Send output to systemd journal]), + [enable_systemd_journal=$enableval], + [enable_systemd_journal=$enable_systemd]) + +AC_MSG_CHECKING([whether to send the outputs of gnome-session and its child processes to systemd journal]) + +AC_MSG_RESULT($enable_systemd_journal) + +if test x$enable_systemd_journal = xyes ; then + if test x$enable_systemd = xno ; then + AC_MSG_ERROR([Systemd not found, or it is not enabled]) + fi + AC_DEFINE(ENABLE_SYSTEMD_JOURNAL, 1, [Define if output should be send to systemd journal]) +fi + +dnl ==================================================================== dnl Check for ConsoleKit dnl ==================================================================== diff --git a/gnome-session/gsm-autostart-app.c b/gnome-session/gsm-autostart-app.c index 1dc3ba3..0837258 100644 --- a/gnome-session/gsm-autostart-app.c +++ b/gnome-session/gsm-autostart-app.c @@ -33,7 +33,9 @@ #endif #ifdef HAVE_SYSTEMD +#ifdef ENABLE_SYSTEMD_JOURNAL #include +#endif #include #endif @@ -1021,7 +1023,7 @@ app_launched (GAppLaunchContext *ctx, app->priv->startup_id = sn_id; } -#ifdef HAVE_SYSTEMD +#ifdef ENABLE_SYSTEMD_JOURNAL static void on_child_setup (GsmAutostartApp *app) { @@ -1092,7 +1094,7 @@ autostart_app_start_spawn (GsmAutostartApp *app, g_app_launch_context_setenv (ctx, "DESKTOP_AUTOSTART_ID", startup_id); } -#ifdef HAVE_SYSTEMD +#ifdef ENABLE_SYSTEMD_JOURNAL if (sd_booted () > 0) { child_setup_func = (GSpawnChildSetupFunc) on_child_setup; child_setup_data = app; diff --git a/gnome-session/gsm-manager.c b/gnome-session/gsm-manager.c index a378cd9..175f4f5 100644 --- a/gnome-session/gsm-manager.c +++ b/gnome-session/gsm-manager.c @@ -40,7 +40,7 @@ #include "gsm-manager.h" #include "org.gnome.SessionManager.h" -#ifdef HAVE_SYSTEMD +#ifdef ENABLE_SYSTEMD_JOURNAL #include #endif @@ -271,7 +271,7 @@ on_required_app_failure (GsmManager *manager, allow_logout = !_log_out_is_locked_down (manager); } -#ifdef HAVE_SYSTEMD +#ifdef ENABLE_SYSTEMD_JOURNAL sd_journal_send ("MESSAGE_ID=%s", GSM_MANAGER_UNRECOVERABLE_FAILURE_MSGID, "PRIORITY=%d", 3, "MESSAGE=Unrecoverable failure in required component %s", app_id, @@ -301,7 +301,7 @@ on_display_server_failure (GsmManager *manager, extensions = NULL; } -#ifdef HAVE_SYSTEMD +#ifdef ENABLE_SYSTEMD_JOURNAL sd_journal_send ("MESSAGE_ID=%s", GSM_MANAGER_UNRECOVERABLE_FAILURE_MSGID, "PRIORITY=%d", 3, "MESSAGE=Unrecoverable failure in required component %s", app_id, @@ -1317,7 +1317,7 @@ start_phase (GsmManager *manager) do_phase_startup (manager); break; case GSM_MANAGER_PHASE_RUNNING: -#ifdef HAVE_SYSTEMD +#ifdef ENABLE_SYSTEMD_JOURNAL sd_journal_send ("MESSAGE_ID=%s", GSM_MANAGER_STARTUP_SUCCEEDED_MSGID, "PRIORITY=%d", 5, "MESSAGE=Entering running state", diff --git a/gnome-session/main.c b/gnome-session/main.c index bd23824..39757b9 100644 --- a/gnome-session/main.c +++ b/gnome-session/main.c @@ -41,7 +41,7 @@ #include "gsm-system.h" #include "gsm-fail-whale.h" -#ifdef HAVE_SYSTEMD +#ifdef ENABLE_SYSTEMD_JOURNAL #include #endif @@ -329,7 +329,7 @@ main (int argc, char **argv) * journald picks ups the nicer "gnome-session" as the program * name instead of whatever shell script GDM happened to use. */ -#ifdef HAVE_SYSTEMD +#ifdef ENABLE_SYSTEMD_JOURNAL if (!debug) { int journalfd; -- 2.6.6