[gnome-keyring/wip/fork-fixes: 3/6] main: split out a separate function



commit b62bba45b352b2f4de7a077bd5356aefc4ff9d64
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Oct 16 11:35:53 2015 -0700

    main: split out a separate function
    
    For clarity.

 daemon/gkd-main.c |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/daemon/gkd-main.c b/daemon/gkd-main.c
index 0d637f3..134870c 100644
--- a/daemon/gkd-main.c
+++ b/daemon/gkd-main.c
@@ -654,6 +654,18 @@ discover_other_daemon (DiscoverFunc callback, gboolean acquire)
        return FALSE;
 }
 
+static void
+redirect_fds_after_fork (void)
+{
+       int fd, i;
+
+       for (i = 0; i < 3; ++i) {
+               fd = open ("/dev/null", O_RDONLY);
+               sane_dup2 (fd, i);
+               close (fd);
+       }
+}
+
 static int
 fork_and_print_environment (void)
 {
@@ -871,7 +883,6 @@ main (int argc, char *argv[])
         * Without either of these options, we follow a more boring and
         * predictable startup.
         */
-       int fd, i;
 
        /*
         * Before we do ANYTHING, we drop privileges so we don't become
@@ -972,12 +983,8 @@ main (int argc, char *argv[])
 
        signal (SIGPIPE, SIG_IGN);
 
-       for (i = 0; i < 3; ++i) {
-               fd = open ("/dev/null", O_RDONLY);
-               sane_dup2 (fd, i);
-               close (fd);
-       }
-
+       if (!run_foreground)
+               redirect_fds_after_fork ();
        send_environment_and_finish_parent (parent_wakeup_fd);
 
        g_unix_signal_add (SIGTERM, on_signal_term, loop);


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