]> sourceware.org Git - systemtap.git/commitdiff
Make sure monitor pipe file descriptors are marked close-on-exec.
authorDavid Smith <dsmith@redhat.com>
Thu, 24 Mar 2016 14:35:25 +0000 (09:35 -0500)
committerDavid Smith <dsmith@redhat.com>
Thu, 24 Mar 2016 14:35:25 +0000 (09:35 -0500)
* staprun/relay.c (init_relayfs): Make sure pipe fds are marked
  close-on-exec.
* staprun/common.c (pipe_cloexec): New function.
* staprun/staprun.h: Add pipe_cloexec() prototype.

staprun/common.c
staprun/relay.c
staprun/staprun.h

index 51d5aee1ddc5152a26b91d3848629cbba00f1451..010bcbbe88ff5876f22c4f6291a0d3b81aff7bae 100644 (file)
@@ -581,6 +581,8 @@ err:
  * when calling open() and openat() to avoid this race condition. When
  * O_CLOEXEC isn't available, the best we can do is call fcntl()
  * immediately after open() is called.
+ *
+ * The same logic applies to openat() and pipe().
  */
 
 int open_cloexec(const char *pathname, int flags, mode_t mode)
@@ -617,6 +619,28 @@ int openat_cloexec(int dirfd, const char *pathname, int flags, mode_t mode)
 }
 #endif
 
+int pipe_cloexec(int pipefd[2])
+{
+#ifdef O_CLOEXEC
+       return pipe2(pipefd, O_CLOEXEC);
+#else
+       int rc = pipe(pipefd);
+       if (rc == 0) {
+               if (set_clexec(pipefd[0]) < 0 || set_clexec(pipefd[1] < 0)) {
+                       goto err;
+               }
+       }
+       return rc;
+
+err:
+       close(pipefd[0]);
+       close(pipefd[1]);
+       pipefd[0] = -1;
+       pipefd[1] = -1;
+       return -1;
+#endif
+}
+
 /**
  *      send_request - send request to kernel over control channel
  *      @type: the relay-app command id
index 06576f7931ff81b755ae1e2db7b12ef13ae53506..b06c9d0dd945870a2901c8827792f9192a90f9d0 100644 (file)
@@ -393,7 +393,7 @@ int init_relayfs(void)
                        }
                } else
                        if (monitor) {
-                               if (pipe(monitor_pfd)) {
+                               if (pipe_cloexec(monitor_pfd)) {
                                        perr("Couldn't create pipe");
                                        return -1;
                                }
index 0a03030ab539c3dfa7be5c43e7357a4862160396..8e0c664c1ad2beed779347623e593e653ce37967 100644 (file)
@@ -224,6 +224,7 @@ int open_cloexec(const char *pathname, int flags, mode_t mode);
 #ifdef HAVE_OPENAT
 int openat_cloexec(int dirfd, const char *pathname, int flags, mode_t mode);
 #endif
+int pipe_cloexec(int pipefd[2]);
 void closefrom(int lowfd);
 
 /* monitor.c function */
This page took 0.029632 seconds and 5 git commands to generate.