Mail Archives: cygwin-developers/1998/05/26/14:15:37
Hi,
Close-on-exec flag is not honored when spawn*() is used
to exec a process. Test case follows.
Tim N.
---- setfd.c ----
#include <process.h>
#include <fcntl.h>
#include <sys/socket.h>
main()
{
int pid, i, x[5];
for(i = 0; i < 5; i++) {
x[i] = socket(AF_INET, SOCK_STREAM, 0);
if(x[i] == -1) {
perror("socket");
return -1;
}
if(fcntl(x[i], F_SETFD, FD_CLOEXEC) == -1) {
perror("f_setfd");
return -1;
}
printf("%d\n", x[i]);
}
pid = spawnl(_P_NOWAIT, "./envargs", "envargs", 0);
printf("pid %d\n", pid);
return 0;
}
---- end setfd.c ----
---- envargs.c : compile as envargs.exe ----
void
print_list(char **l)
{
int i;
for(i = 0; l[i]; i++) {
printf(" [%d] %s\n", i, l[i]);
}
return;
}
int
main(int argc, char **argv)
{
extern char **environ;
int i;
printf("Env: \n");
print_list(environ);
printf("\nArgs: \n");
print_list(argv);
printf("open files: ");
for(i = 0; i < 100; i++) {
if(i == 1 || close(i) == 0)
printf("%d ", i);
}
printf("\n");
return 0;
}
---- end envargs.c ----
- Raw text -