I have the following code:

        pid_t pid;
        int sv[2];
        int val;
        char arg0[] = "someotherprog";
        char arg1[] = VSTRING;
        char* arg[] = {arg0, arg1, 0};

        socketpair(AF_UNIX, SOCK_STREAM, 0, sv);
        printf("socketpair returned %i,%i\n", sv[0], sv[1]);
        cox(sv[0]);
        cox(sv[1]);
        val = fcntl(sv[0], F_GETFL, 0);
        fcntl(sv[0], F_SETFL, val | O_NONBLOCK);
        pid = vfork();
        if (pid == 0) {
                dup2(3, sv[1]);
                ncox(3);
                execve("/someotherprog", arg, 0);
        }
        close(sv[1]);

cox() sets FD_CLOEXEC while ncox() deletes.

1. Problem:
   I need to clear FD_CLOEXEC on the descriptor that dup2 returned.
   Otherwise the the programm has fd 3 invalid.
   I wonder why dup2 did not clear it.
2. Problem:
   If I write(2) to sv[0] in the parent process I get an SIGPIPE.
   And read(2) on fd 3 in the child returns socket not connected.
   
-- 
B.Walter              COSMO-Project         http://www.cosmo-project.de
[EMAIL PROTECTED]         Usergroup           [EMAIL PROTECTED]


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-net" in the body of the message

Reply via email to