diff --git a/daemon/src/vnode_io.c b/daemon/src/vnode_io.c index d14ca5eb..6ac607de 100644 --- a/daemon/src/vnode_io.c +++ b/daemon/src/vnode_io.c @@ -57,6 +57,18 @@ int clear_nonblock(int fd) return r; } +int set_cloexec(int fd) +{ + int fdflags; + + if ((fdflags = fcntl(fd, F_GETFD)) == -1) + fdflags = 0; + if (fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC) == -1) + return -1; + + return 0; +} + int open_stdio_pty(stdio_pty_t *stdiopty) { int masterfd, slavefd; diff --git a/daemon/src/vnode_io.h b/daemon/src/vnode_io.h index cc205697..fb5fe267 100644 --- a/daemon/src/vnode_io.h +++ b/daemon/src/vnode_io.h @@ -52,6 +52,8 @@ typedef struct { int set_nonblock(int fd); int clear_nonblock(int fd); +int set_cloexec(int fd); + int open_stdio_pty(stdio_pty_t *stdiopty); void close_stdio_pty(stdio_pty_t *stdiopty); diff --git a/daemon/src/vnode_server.c b/daemon/src/vnode_server.c index 280f38a9..f7a94fe5 100644 --- a/daemon/src/vnode_server.c +++ b/daemon/src/vnode_server.c @@ -25,6 +25,7 @@ #include "vnode_msg.h" #include "vnode_chnl.h" #include "vnode_cmd.h" +#include "vnode_io.h" #include "vnode_server.h" @@ -34,18 +35,6 @@ static vnode_cliententry_t *vnode_server_newclient(vnode_server_t *server, int fd); static void vnode_server_delclient(vnode_cliententry_t *client); -static int cloexec(int fd) -{ - int fdflags; - - if ((fdflags = fcntl(fd, F_GETFD)) == -1) - fdflags = 0; - if (fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC) == -1) - return -1; - - return 0; -} - static void client_ioerror(vnode_msgio_t *msgio) { vnode_cliententry_t *client = msgio->data; @@ -71,7 +60,7 @@ static vnode_cliententry_t *vnode_server_newclient(vnode_server_t *server, WARNX("new client on fd %d", fd); #endif - cloexec(fd); + set_cloexec(fd); if ((client = malloc(sizeof(*client))) == NULL) { @@ -292,7 +281,7 @@ vnode_server_t *vnoded(int newnetns, const char *ctrlchnlname, WARNX("vnode_listen() failed for '%s'", ctrlchnlname); return NULL; } - cloexec(ctrlfd); + set_cloexec(ctrlfd); if (newnetns) {