[gnome-session/wip/desktop-generator: 1/2] Revert "Revert "autostart-app: give ever app its own journal id""



commit fc7405d07d5f4510d4fdd3e383583855015532fc
Author: Ray Strode <rstrode redhat com>
Date:   Fri Nov 6 10:22:01 2015 -0500

    Revert "Revert "autostart-app: give ever app its own journal id""
    
    Nice.  I didn't mean to revert the patch I was pushing.
    
    This reverts commit a8f8c4fd1382c97215a216abfee6c250535416b4.

 gnome-session/gsm-autostart-app.c |   44 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 43 insertions(+), 1 deletions(-)
---
diff --git a/gnome-session/gsm-autostart-app.c b/gnome-session/gsm-autostart-app.c
index 75008fe..08a434b 100644
--- a/gnome-session/gsm-autostart-app.c
+++ b/gnome-session/gsm-autostart-app.c
@@ -32,6 +32,11 @@
 #include <gconf/gconf-client.h>
 #endif
 
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-journal.h>
+#include <systemd/sd-daemon.h>
+#endif
+
 #include "gsm-autostart-app.h"
 #include "gsm-util.h"
 
@@ -1014,6 +1019,34 @@ app_launched (GAppLaunchContext *ctx,
         app->priv->startup_id = sn_id;
 }
 
+#ifdef HAVE_SYSTEMD
+static void
+on_child_setup (GsmAutostartApp *app)
+{
+        int standard_output, standard_error;
+
+        /* The FALSE means programs aren't expected to prefix each
+         * line with <n> prefix to specify priority.
+         */
+        standard_output = sd_journal_stream_fd (app->priv->desktop_id,
+                                                LOG_INFO,
+                                                FALSE);
+        standard_error = sd_journal_stream_fd (app->priv->desktop_id,
+                                               LOG_WARNING,
+                                               FALSE);
+
+        if (standard_output >= 0) {
+                dup2 (standard_output, STDOUT_FILENO);
+                close (standard_output);
+        }
+
+        if (standard_error >= 0) {
+                dup2 (standard_error, STDERR_FILENO);
+                close (standard_error);
+        }
+}
+#endif
+
 static gboolean
 autostart_app_start_spawn (GsmAutostartApp *app,
                            GError         **error)
@@ -1022,6 +1055,8 @@ autostart_app_start_spawn (GsmAutostartApp *app,
         GError          *local_error;
         const char      *startup_id;
         GAppLaunchContext *ctx;
+        GSpawnChildSetupFunc child_setup_func = NULL;
+        gpointer             child_setup_data = NULL;
         guint handler;
 
         startup_id = gsm_app_peek_startup_id (GSM_APP (app));
@@ -1041,12 +1076,19 @@ autostart_app_start_spawn (GsmAutostartApp *app,
                 g_app_launch_context_setenv (ctx, "DESKTOP_AUTOSTART_ID", startup_id);
         }
 
+#ifdef HAVE_SYSTEMD
+        if (sd_booted () > 0) {
+                child_setup_func = (GSpawnChildSetupFunc) on_child_setup;
+                child_setup_data = app;
+        }
+#endif
+
         handler = g_signal_connect (ctx, "launched", G_CALLBACK (app_launched), app);
         success = g_desktop_app_info_launch_uris_as_manager (app->priv->app_info,
                                                              NULL,
                                                              ctx,
                                                              G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
-                                                             NULL, NULL,
+                                                             child_setup_func, child_setup_data,
                                                              NULL, NULL,
                                                              &local_error);
         g_signal_handler_disconnect (ctx, handler);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]