]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #3641 from 0xAX/unset-cloexec-for-stdfs
authorLennart Poettering <lennart@poettering.net>
Sat, 2 Jul 2016 22:22:14 +0000 (15:22 -0700)
committerGitHub <noreply@github.com>
Sat, 2 Jul 2016 22:22:14 +0000 (15:22 -0700)
basic/fd-util: introduce stdio_unset_cloexec() function

src/basic/fd-util.c
src/basic/fd-util.h
src/basic/terminal-util.c
src/import/import-common.c
src/import/importd.c
src/import/pull-common.c

index 8b466cff154d94da5ad731624f0cc909e2a62372..5c820332a5dd1417663c31a4f269a3d5c440b796 100644 (file)
@@ -186,6 +186,12 @@ int fd_cloexec(int fd, bool cloexec) {
         return 0;
 }
 
+void stdio_unset_cloexec(void) {
+        fd_cloexec(STDIN_FILENO, false);
+        fd_cloexec(STDOUT_FILENO, false);
+        fd_cloexec(STDERR_FILENO, false);
+}
+
 _pure_ static bool fd_in_set(int fd, const int fdset[], unsigned n_fdset) {
         unsigned i;
 
index b86e41698acb58afaa5c9e1079626feba4130fdf..34b98d4aec546195f0495045437a638be6e51619 100644 (file)
@@ -63,6 +63,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(DIR*, closedir);
 
 int fd_nonblock(int fd, bool nonblock);
 int fd_cloexec(int fd, bool cloexec);
+void stdio_unset_cloexec(void);
 
 int close_all_fds(const int except[], unsigned n_except);
 
index d8cca55378ec89339d868a446e59da42869b8ad4..df56d853170a785fb6b7756b03004397e633fc60 100644 (file)
@@ -888,9 +888,7 @@ int make_stdio(int fd) {
 
         /* Explicitly unset O_CLOEXEC, since if fd was < 3, then
          * dup2() was a NOP and the bit hence possibly set. */
-        fd_cloexec(STDIN_FILENO, false);
-        fd_cloexec(STDOUT_FILENO, false);
-        fd_cloexec(STDERR_FILENO, false);
+        stdio_unset_cloexec();
 
         return 0;
 }
index 287a3382a1c260e6e2eecc3a4c8eb694b28cee06..81209cdaf6502d69a6f38276f18508b0055431fd 100644 (file)
@@ -125,9 +125,7 @@ int import_fork_tar_x(const char *path, pid_t *ret) {
                 if (null_fd != STDOUT_FILENO)
                         null_fd = safe_close(null_fd);
 
-                fd_cloexec(STDIN_FILENO, false);
-                fd_cloexec(STDOUT_FILENO, false);
-                fd_cloexec(STDERR_FILENO, false);
+                stdio_unset_cloexec();
 
                 if (unshare(CLONE_NEWNET) < 0)
                         log_error_errno(errno, "Failed to lock tar into network namespace, ignoring: %m");
@@ -199,9 +197,7 @@ int import_fork_tar_c(const char *path, pid_t *ret) {
                 if (null_fd != STDIN_FILENO)
                         null_fd = safe_close(null_fd);
 
-                fd_cloexec(STDIN_FILENO, false);
-                fd_cloexec(STDOUT_FILENO, false);
-                fd_cloexec(STDERR_FILENO, false);
+                stdio_unset_cloexec();
 
                 if (unshare(CLONE_NEWNET) < 0)
                         log_error_errno(errno, "Failed to lock tar into network namespace, ignoring: %m");
index 956a82945c22cc832bdef6ed8da69951ebcfa735..28b4302cb3fafa524016e19c1fc56ac60aa2baa7 100644 (file)
@@ -448,9 +448,7 @@ static int transfer_start(Transfer *t) {
                                 safe_close(null_fd);
                 }
 
-                fd_cloexec(STDIN_FILENO, false);
-                fd_cloexec(STDOUT_FILENO, false);
-                fd_cloexec(STDERR_FILENO, false);
+                stdio_unset_cloexec();
 
                 setenv("SYSTEMD_LOG_TARGET", "console-prefixed", 1);
                 setenv("NOTIFY_SOCKET", "/run/systemd/import/notify", 1);
index dc4e4667a9107aeb7efee5eeb3600a27c0450521..2ae2a4174cccb755ad2db898462f8dbaadc6f4d9 100644 (file)
@@ -506,9 +506,7 @@ int pull_verify(PullJob *main_job,
                 cmd[k++] = "-";
                 cmd[k++] = NULL;
 
-                fd_cloexec(STDIN_FILENO, false);
-                fd_cloexec(STDOUT_FILENO, false);
-                fd_cloexec(STDERR_FILENO, false);
+                stdio_unset_cloexec();
 
                 execvp("gpg2", (char * const *) cmd);
                 execvp("gpg", (char * const *) cmd);