| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <fcntl.h> | 
 | 2 | #include <stdio.h> | 
 | 3 |  | 
 | 4 | static int | 
 | 5 | do_test (void) | 
 | 6 | { | 
 | 7 |   int res = 0; | 
 | 8 |  | 
 | 9 |   FILE *fp = popen ("echo hello", "r"); | 
 | 10 |   if (fp == NULL) | 
 | 11 |     { | 
 | 12 |       puts ("first popen failed"); | 
 | 13 |       res = 1; | 
 | 14 |     } | 
 | 15 |   else | 
 | 16 |     { | 
 | 17 |       int fd = fileno (fp); | 
 | 18 |       if (fcntl (fd, F_GETFD) == FD_CLOEXEC) | 
 | 19 | 	{ | 
 | 20 | 	  puts ("first popen(\"r\") set FD_CLOEXEC"); | 
 | 21 | 	  res = 1; | 
 | 22 | 	} | 
 | 23 |  | 
 | 24 |       fclose (fp); | 
 | 25 |     } | 
 | 26 |  | 
 | 27 |   fp = popen ("echo hello", "re"); | 
 | 28 |   if (fp == NULL) | 
 | 29 |     { | 
 | 30 |       puts ("second popen failed"); | 
 | 31 |       res = 1; | 
 | 32 |     } | 
 | 33 |   else | 
 | 34 |     { | 
 | 35 |       int fd = fileno (fp); | 
 | 36 |       if (fcntl (fd, F_GETFD) != FD_CLOEXEC) | 
 | 37 | 	{ | 
 | 38 | 	  puts ("second popen(\"r\") did not set FD_CLOEXEC"); | 
 | 39 | 	  res = 1; | 
 | 40 | 	} | 
 | 41 |  | 
 | 42 |       fclose (fp); | 
 | 43 |     } | 
 | 44 |  | 
 | 45 |   return res; | 
 | 46 | } | 
 | 47 |  | 
 | 48 | #define TEST_FUNCTION do_test () | 
 | 49 | #include "../test-skeleton.c" |