delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1998/05/26/14:15:37

From: newsham AT lava DOT net (Tim Newsham)
Subject: close-on-exec doesnt work for spawn*()
26 May 1998 14:15:37 -0700 :
Message-ID: <m0yeQtI-0010xiC.cygnus.cygwin32.developers@malasada.lava.net>
Mime-Version: 1.0
To: cygwin32-developers AT cygnus DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019