set cloexec flag on socket pair

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
Gao feng
2015-09-16 23:39:01 +08:00
parent bf0f360935
commit 2fb02c57b6
5 changed files with 24 additions and 15 deletions
+1 -4
View File
@@ -389,9 +389,6 @@ static int hyper_container_init(void *data)
goto fail;
}
close(arg->pipe[0]);
close(arg->pipe[1]);
execvp(container->exec.argv[0], container->exec.argv);
perror("exec container command failed");
@@ -453,7 +450,7 @@ int hyper_start_container(struct hyper_container *container,
goto fail;
}
if (socketpair(PF_UNIX, SOCK_STREAM, 0, arg.pipe) < 0) {
if (hyper_socketpair(PF_UNIX, SOCK_STREAM, 0, arg.pipe) < 0) {
perror("create pipe between pod init execcmd failed");
goto fail;
}
+2 -7
View File
@@ -285,7 +285,7 @@ static int hyper_do_exec_cmd(void *data)
}
}
if (socketpair(PF_UNIX, SOCK_STREAM, 0, pipe) < 0) {
if (hyper_socketpair(PF_UNIX, SOCK_STREAM, 0, pipe) < 0) {
perror("create pipe in exec command failed");
_exit(-1);
}
@@ -333,11 +333,6 @@ static int hyper_do_exec_cmd(void *data)
_exit(-1);
}
close(pipe[0]);
close(pipe[1]);
close(arg->pipe[0]);
close(arg->pipe[1]);
if (execvp(exec->argv[0], exec->argv) < 0) {
perror("exec failed");
_exit(-1);
@@ -384,7 +379,7 @@ int hyper_exec_cmd(char *json, int length)
goto out;
}
if (socketpair(PF_UNIX, SOCK_STREAM, 0, arg.pipe) < 0) {
if (hyper_socketpair(PF_UNIX, SOCK_STREAM, 0, arg.pipe) < 0) {
perror("create pipe between pod init execcmd failed");
goto out;
}
+4 -4
View File
@@ -388,7 +388,7 @@ static int hyper_ctl_pipe_handle(struct hyper_event *de, uint32_t len)
return 0;
}
static int hyper_enter_container_pidns(void *data)
static int hyper_do_start_containers(void *data)
{
int i, pidns, ipcns, utsns, ret;
struct hyper_container *c;
@@ -467,12 +467,12 @@ int hyper_start_containers(struct hyper_pod *pod)
goto out;
}
if (socketpair(PF_UNIX, SOCK_STREAM, 0, arg.ctl_pipe) < 0) {
if (hyper_socketpair(PF_UNIX, SOCK_STREAM, 0, arg.ctl_pipe) < 0) {
perror("create pipe between hyper init and pod init failed");
goto out;
}
pid = clone(hyper_enter_container_pidns, stack + stacksize, CLONE_VM| CLONE_FILES, &arg);
pid = clone(hyper_do_start_containers, stack + stacksize, CLONE_VM| CLONE_FILES, &arg);
free(stack);
if (pid < 0) {
perror("enter container pid ns failed");
@@ -520,7 +520,7 @@ static int hyper_setup_container(struct hyper_pod *pod)
uint32_t type;
void *stack;
if (socketpair(PF_UNIX, SOCK_STREAM, 0, arg.ctl_pipe) < 0) {
if (hyper_socketpair(PF_UNIX, SOCK_STREAM, 0, arg.ctl_pipe) < 0) {
perror("create pipe between hyper init and pod init failed");
return -1;
}
+16
View File
@@ -11,6 +11,7 @@
#include <ctype.h>
#include <mntent.h>
#include <sys/mount.h>
#include <sys/socket.h>
#include <sys/reboot.h>
#include <linux/reboot.h>
@@ -323,6 +324,21 @@ int hyper_setfd_nonblock(int fd)
return 0;
}
int hyper_socketpair(int domain, int type, int protocol, int sv[2])
{
if (socketpair(domain, type, protocol, sv) < 0) {
perror("socketpair failed");
return -1;
}
if (hyper_setfd_cloexec(sv[0]) < 0 ||
hyper_setfd_cloexec(sv[1]) < 0) {
return -1;
}
return 0;
}
void hyper_unmount_all(void)
{
FILE *mtab;
+1
View File
@@ -23,6 +23,7 @@ int hyper_open_serial_dev(char *tty);
int hyper_setfd_cloexec(int fd);
int hyper_setfd_block(int fd);
int hyper_setfd_nonblock(int fd);
int hyper_socketpair(int domain, int type, int protocol, int sv[2]);
void hyper_shutdown(struct hyper_pod *pod);
int hyper_send_finish(struct hyper_pod *pod);
void hyper_unmount_all(void);