From e5474df1acdb0a8eaeb50886c928e0c2ec4ebad7 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 3 Mar 2017 14:16:22 +0000 Subject: [PATCH] Use gnulib set_cloexec_flag in a few places. --- daemon/inotify.c | 5 +++-- fuse/test-guestunmount-fd.c | 3 ++- tests/c-api/test-user-cancel.c | 14 ++++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/daemon/inotify.c b/daemon/inotify.c index 93722d0ea..38a1c92fb 100644 --- a/daemon/inotify.c +++ b/daemon/inotify.c @@ -29,6 +29,7 @@ #include #endif +#include "cloexec.h" #include "nonblocking.h" #include "guestfs_protocol.h" @@ -120,8 +121,8 @@ do_inotify_init (int max_events) inotify_fd = -1; return -1; } - if (fcntl (inotify_fd, F_SETFD, FD_CLOEXEC) == -1) { - reply_with_perror ("fcntl: FD_CLOEXEC"); + if (set_cloexec_flag (inotify_fd, 1) == -1) { + reply_with_perror ("set_cloexec_flag"); close (inotify_fd); inotify_fd = -1; return -1; diff --git a/fuse/test-guestunmount-fd.c b/fuse/test-guestunmount-fd.c index 019f82114..6756f18cb 100644 --- a/fuse/test-guestunmount-fd.c +++ b/fuse/test-guestunmount-fd.c @@ -32,6 +32,7 @@ #include #include +#include "cloexec.h" #include "ignore-value.h" #include "guestfs.h" @@ -77,7 +78,7 @@ main (int argc, char *argv[]) /* Parent continues. */ close (pipefd[0]); - ignore_value (fcntl (pipefd[1], F_SETFD, FD_CLOEXEC)); + ignore_value (set_cloexec_flag (pipefd[1], 1)); /* Sleep a bit and test that the guestunmount process is still running. */ sleep (2); diff --git a/tests/c-api/test-user-cancel.c b/tests/c-api/test-user-cancel.c index 382368209..d429a0fe3 100644 --- a/tests/c-api/test-user-cancel.c +++ b/tests/c-api/test-user-cancel.c @@ -45,6 +45,8 @@ #include +#include "cloexec.h" + #include "guestfs.h" #include "guestfs-internal-frontend.h" @@ -102,9 +104,9 @@ main (int argc, char *argv[]) error (EXIT_FAILURE, errno, "pipe"); /* We don't want the pipe to be passed to subprocesses. */ - if (fcntl (fds[0], F_SETFD, FD_CLOEXEC) == -1 || - fcntl (fds[1], F_SETFD, FD_CLOEXEC) == -1) - error (EXIT_FAILURE, errno, "fcntl"); + if (set_cloexec_flag (fds[0], 1) == -1 || + set_cloexec_flag (fds[1], 1) == -1) + error (EXIT_FAILURE, errno, "set_cloexec_flag"); data.fd = fds[1]; snprintf (dev_fd, sizeof dev_fd, "/dev/fd/%d", fds[0]); @@ -160,9 +162,9 @@ main (int argc, char *argv[]) error (EXIT_FAILURE, errno, "pipe"); /* We don't want the pipe to be passed to subprocesses. */ - if (fcntl (fds[0], F_SETFD, FD_CLOEXEC) == -1 || - fcntl (fds[1], F_SETFD, FD_CLOEXEC) == -1) - error (EXIT_FAILURE, errno, "fcntl"); + if (set_cloexec_flag (fds[0], 1) == -1 || + set_cloexec_flag (fds[1], 1) == -1) + error (EXIT_FAILURE, errno, "set_cloexec_flag"); data.fd = fds[0]; snprintf (dev_fd, sizeof dev_fd, "/dev/fd/%d", fds[1]);