daemon: Minor code reorganization.
This commit is contained in:
parent
0333c74bec
commit
ec8ac2f258
3 changed files with 17 additions and 14 deletions
|
@ -57,6 +57,18 @@ int clear_nonblock(int fd)
|
||||||
return r;
|
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 open_stdio_pty(stdio_pty_t *stdiopty)
|
||||||
{
|
{
|
||||||
int masterfd, slavefd;
|
int masterfd, slavefd;
|
||||||
|
|
|
@ -52,6 +52,8 @@ typedef struct {
|
||||||
int set_nonblock(int fd);
|
int set_nonblock(int fd);
|
||||||
int clear_nonblock(int fd);
|
int clear_nonblock(int fd);
|
||||||
|
|
||||||
|
int set_cloexec(int fd);
|
||||||
|
|
||||||
int open_stdio_pty(stdio_pty_t *stdiopty);
|
int open_stdio_pty(stdio_pty_t *stdiopty);
|
||||||
void close_stdio_pty(stdio_pty_t *stdiopty);
|
void close_stdio_pty(stdio_pty_t *stdiopty);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "vnode_msg.h"
|
#include "vnode_msg.h"
|
||||||
#include "vnode_chnl.h"
|
#include "vnode_chnl.h"
|
||||||
#include "vnode_cmd.h"
|
#include "vnode_cmd.h"
|
||||||
|
#include "vnode_io.h"
|
||||||
|
|
||||||
#include "vnode_server.h"
|
#include "vnode_server.h"
|
||||||
|
|
||||||
|
@ -34,18 +35,6 @@ static vnode_cliententry_t *vnode_server_newclient(vnode_server_t *server,
|
||||||
int fd);
|
int fd);
|
||||||
static void vnode_server_delclient(vnode_cliententry_t *client);
|
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)
|
static void client_ioerror(vnode_msgio_t *msgio)
|
||||||
{
|
{
|
||||||
vnode_cliententry_t *client = msgio->data;
|
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);
|
WARNX("new client on fd %d", fd);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cloexec(fd);
|
set_cloexec(fd);
|
||||||
|
|
||||||
if ((client = malloc(sizeof(*client))) == NULL)
|
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);
|
WARNX("vnode_listen() failed for '%s'", ctrlchnlname);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
cloexec(ctrlfd);
|
set_cloexec(ctrlfd);
|
||||||
|
|
||||||
if (newnetns)
|
if (newnetns)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue