[Pkg-gnupg-commit] [gnupg2] 264/292: scd, dirmngr: Keep the standard fds when daemonizing.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Mon Nov 21 06:31:50 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg2.

commit 4839e6d002a8ad1f7d3260792c3c9641e258f342
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Nov 16 21:17:47 2016 +0100

    scd,dirmngr: Keep the standard fds when daemonizing.
    
    * dirmngr/dirmngr.c (main): Before calling setsid do not close the
    standard fds but connect them to /dev/null.
    * scd/scdaemon.c (main): Ditto.  Noet that the old test for a log
    stream was even reverted.
    
    --
    
    Note that this was fixed for gpg-agent 10 years ago on 2006-11-09.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 dirmngr/dirmngr.c | 12 +++++++++++-
 scd/scdaemon.c    | 14 ++++++++++++--
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c
index 254c543..db5079c 100644
--- a/dirmngr/dirmngr.c
+++ b/dirmngr/dirmngr.c
@@ -1209,8 +1209,18 @@ main (int argc, char **argv)
           for (i=0; i <= 2; i++)
             {
               if (!log_test_fd (i) && i != fd )
-                close (i);
+                {
+                  if ( !close (i)
+                       && open ("/dev/null", i? O_WRONLY : O_RDONLY) == -1)
+                    {
+                      log_error ("failed to open '%s': %s\n",
+                                 "/dev/null", strerror (errno));
+                      cleanup ();
+                      dirmngr_exit (1);
+                    }
+                }
             }
+
           if (setsid() == -1)
             {
               log_error ("setsid() failed: %s\n", strerror(errno) );
diff --git a/scd/scdaemon.c b/scd/scdaemon.c
index acc5b47..064cae9 100644
--- a/scd/scdaemon.c
+++ b/scd/scdaemon.c
@@ -871,9 +871,19 @@ main (int argc, char **argv )
           /* Close stdin, stdout and stderr unless it is the log stream. */
           for (i=0; i <= 2; i++)
             {
-              if ( log_test_fd (i) && i != fd)
-                close (i);
+              if (!log_test_fd (i) && i != fd )
+                {
+                  if ( !close (i)
+                       && open ("/dev/null", i? O_WRONLY : O_RDONLY) == -1)
+                    {
+                      log_error ("failed to open '%s': %s\n",
+                                 "/dev/null", strerror (errno));
+                      cleanup ();
+                      exit (1);
+                    }
+                }
             }
+
           if (setsid() == -1)
             {
               log_error ("setsid() failed: %s\n", strerror(errno) );

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list