starter: Close open file descriptors after forking.
authorTobias Brunner <tobias@strongswan.org>
Thu, 13 Oct 2011 08:35:41 +0000 (10:35 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 13 Oct 2011 09:19:17 +0000 (11:19 +0200)
This avoids problems with Android's adb which leaves several file
descriptors open when executing processes.

src/starter/starter.c

index 659122a..b1a9a15 100644 (file)
@@ -429,8 +429,11 @@ int main (int argc, char **argv)
                {
                        case 0:
                        {
-                               int fnull = open("/dev/null", O_RDWR);
+                               int fnull;
 
+                               closefrom(3);
+
+                               fnull = open("/dev/null", O_RDWR);
                                if (fnull >= 0)
                                {
                                        dup2(fnull, STDIN_FILENO);
@@ -438,6 +441,7 @@ int main (int argc, char **argv)
                                        dup2(fnull, STDERR_FILENO);
                                        close(fnull);
                                }
+
                                setsid();
                        }
                        break;