From: Bubnis, R. <Rob...@te...> - 2010-01-20 21:01:06
|
Hi, Could the OpenHPI client library by default set CLOSEXEC on sockets it opens? Our client spawns other processes, inheriting the open fds. Thanks, Rob Bubnis $ cat patches/openhpi-2.14.1-cloexec.patch --- openhpi-2.14.1/marshal/strmsock.cpp.orig 2010-01-05 12:17:58.000000000 -0500 +++ openhpi-2.14.1/marshal/strmsock.cpp 2010-01-05 12:18:10.000000000 -0500 @@ -17,6 +17,7 @@ #include <stdlib.h> #include <stdio.h> #include <unistd.h> +#include <fcntl.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> @@ -258,6 +259,17 @@ return(TRUE); } + // set fd to close on exec + int flags; + flags = fcntl(s, F_GETFD); + if (flags == -1) { + errcode = errno; + close(s); + return(TRUE); + } + flags |= FD_CLOEXEC; + fcntl(s, F_SETFD, flags); + errcode = 0; fOpen = TRUE; return(FALSE); |