daemon: Minor code reorganization.

This commit is contained in:
Tom Goff 2016-01-29 17:46:55 -05:00
parent 0333c74bec
commit ec8ac2f258
3 changed files with 17 additions and 14 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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)
{