diff options
Diffstat (limited to 'tests/c-api/test-user-cancel.c')
-rw-r--r-- | tests/c-api/test-user-cancel.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/c-api/test-user-cancel.c b/tests/c-api/test-user-cancel.c index 4908f953..39763bf0 100644 --- a/tests/c-api/test-user-cancel.c +++ b/tests/c-api/test-user-cancel.c @@ -46,6 +46,10 @@ #include "guestfs.h" +#ifndef O_CLOEXEC +#define O_CLOEXEC +#endif + static const char *filename = "test.img"; static const off_t filesize = 1024*1024*1024; @@ -83,7 +87,7 @@ main (int argc, char *argv[]) } /* Create a test image and test data. */ - fd = open (filename, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY, 0666); + fd = open (filename, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0666); if (fd == -1) { perror (filename); exit (EXIT_FAILURE); @@ -135,6 +139,13 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } + /* 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) { + perror ("fcntl"); + exit (EXIT_FAILURE); + } + data.fd = fds[1]; snprintf (dev_fd, sizeof dev_fd, "/dev/fd/%d", fds[0]); @@ -196,6 +207,13 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } + /* 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) { + perror ("fcntl"); + exit (EXIT_FAILURE); + } + data.fd = fds[0]; snprintf (dev_fd, sizeof dev_fd, "/dev/fd/%d", fds[1]); |