On Wed, Jun 20, 2012 at 11:18:39PM -0700, Philip Guenther wrote: > On Wed, Jun 20, 2012 at 4:26 AM, Paul Irofti <[email protected]> wrote: > > + SCARG(&bfa, cmd) = F_SETFL; > > + SCARG(&bfa, arg) = (void *)O_NONBLOCK; > > + error = sys_fcntl(p, &bfa, retval); > > <mumble> That assumes that a new socket can't have any of the > FCNTLFLAGS set on it, which _is_ true, currently... > > The casts have me second guessing whether the argument passing really > is correct, though I think it is. I would still suggest a small linux > test program that passes those flags then checks the results with > fcntl(F_GETFL) and fcntl(GETFD). If it passes that, then it's better > than what's there.
Tested with the following program and everything seems to work. I've also sprinkled some extra printfs in the original diff and both cases are found and dealt with in the kernel. You can also fetch the blob from: http://irofti.net/tmp/sock-cloexec -------------------------------------------------------------------------------- #include <fcntl.h> #include <stdio.h> #include <unistd.h> #include <netinet/in.h> #include <sys/socket.h> int main() { int fd, flag; fd = socket(PF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0); if (fd == -1) { return 1; } flag = fcntl(fd, F_GETFD); if (flag == -1) { printf("fnctl failed!\n"); } if ((flag & FD_CLOEXEC) == 0) { printf("FD_CLOEXEC not set!\n"); } close(fd); fd = socket(PF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); if (fd == -1) { return 1; } flag = fcntl(fd, F_GETFL); if (flag == -1) { printf("fnctl failed!\n"); } if ((flag & O_NONBLOCK) == 0) { printf("O_NONBLOCK not set!\n"); } close(fd); return 0; } --------------------------------------------------------------------------------
