Merge pull request #2366 from 2xsec/bugfix

change defines for return value of handlers
This commit is contained in:
Christian Brauner 2018-05-31 12:22:21 +02:00 committed by GitHub
commit 989ccdf1b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 15 deletions

8
src/lxc/cmd/lxc_monitord.c Normal file → Executable file
View File

@ -161,7 +161,7 @@ static int lxc_monitord_sock_handler(int fd, uint32_t events, void *data,
rc = read(fd, buf, sizeof(buf));
if (rc > 0 && !strncmp(buf, "quit", 4))
quit = 1;
quit = LXC_MAINLOOP_CLOSE;
}
if (events & EPOLLHUP)
@ -177,7 +177,7 @@ static int lxc_monitord_sock_accept(int fd, uint32_t events, void *data,
struct ucred cred;
socklen_t credsz = sizeof(cred);
ret = -1;
ret = LXC_MAINLOOP_ERROR;
clientfd = accept(fd, NULL, 0);
if (clientfd < 0) {
SYSERROR("Failed to accept connection for client file descriptor %d.", fd);
@ -301,7 +301,7 @@ static int lxc_monitord_fifo_handler(int fd, uint32_t events, void *data,
ret = read(fd, &msglxc, sizeof(msglxc));
if (ret != sizeof(msglxc)) {
SYSERROR("Reading from fifo failed: %s.", strerror(errno));
return 1;
return LXC_MAINLOOP_CLOSE;
}
for (i = 0; i < mon->clientfds_cnt; i++) {
@ -311,7 +311,7 @@ static int lxc_monitord_fifo_handler(int fd, uint32_t events, void *data,
mon->clientfds[i], strerror(errno));
}
return 0;
return LXC_MAINLOOP_CONTINUE;
}
static int lxc_monitord_mainloop_add(struct lxc_monitor *mon)

6
src/lxc/commands.c Normal file → Executable file
View File

@ -1167,7 +1167,7 @@ static int lxc_cmd_handler(int fd, uint32_t events, void *data,
if (ret != req.datalen) {
WARN("Failed to receive full command request. Ignoring "
"request for \"%s\"", lxc_cmd_str(req.cmd));
ret = -1;
ret = LXC_MAINLOOP_ERROR;
goto out_close;
}
@ -1177,7 +1177,7 @@ static int lxc_cmd_handler(int fd, uint32_t events, void *data,
ret = lxc_cmd_process(fd, &req, handler);
if (ret) {
/* This is not an error, but only a request to close fd. */
ret = 0;
ret = LXC_MAINLOOP_CONTINUE;
goto out_close;
}
@ -1201,7 +1201,7 @@ static int lxc_cmd_accept(int fd, uint32_t events, void *data,
connection = accept(fd, NULL, 0);
if (connection < 0) {
SYSERROR("Failed to accept connection to run command.");
return -1;
return LXC_MAINLOOP_ERROR;
}
ret = fcntl(connection, F_SETFD, FD_CLOEXEC);

19
src/lxc/start.c Normal file → Executable file
View File

@ -343,7 +343,7 @@ static int signal_handler(int fd, uint32_t events, void *data,
ret = read(fd, &siginfo, sizeof(siginfo));
if (ret < 0) {
ERROR("Failed to read signal info from signal file descriptor %d", fd);
return -1;
return LXC_MAINLOOP_ERROR;
}
if (ret != sizeof(siginfo)) {
@ -374,7 +374,7 @@ static int signal_handler(int fd, uint32_t events, void *data,
hdlr->exit_status = 1;
break;
default:
ERROR("Unknown si_code: %d", hdlr->init_died);
ERROR("Unknown si_code: %d", info.si_code);
hdlr->exit_status = 1;
}
}
@ -382,13 +382,13 @@ static int signal_handler(int fd, uint32_t events, void *data,
if (siginfo.ssi_signo == SIGHUP) {
kill(hdlr->pid, SIGTERM);
INFO("Killing %d since terminal hung up", hdlr->pid);
return hdlr->init_died ? LXC_MAINLOOP_CLOSE : 0;
return hdlr->init_died ? LXC_MAINLOOP_CLOSE : LXC_MAINLOOP_CONTINUE;
}
if (siginfo.ssi_signo != SIGCHLD) {
kill(hdlr->pid, siginfo.ssi_signo);
INFO("Forwarded signal %d to pid %d", siginfo.ssi_signo, hdlr->pid);
return hdlr->init_died ? LXC_MAINLOOP_CLOSE : 0;
return hdlr->init_died ? LXC_MAINLOOP_CLOSE : LXC_MAINLOOP_CONTINUE;
}
/* More robustness, protect ourself from a SIGCHLD sent
@ -397,15 +397,15 @@ static int signal_handler(int fd, uint32_t events, void *data,
if (siginfo.ssi_pid != hdlr->pid) {
NOTICE("Received %d from pid %d instead of container init %d",
siginfo.ssi_signo, siginfo.ssi_pid, hdlr->pid);
return hdlr->init_died ? LXC_MAINLOOP_CLOSE : 0;
return hdlr->init_died ? LXC_MAINLOOP_CLOSE : LXC_MAINLOOP_CONTINUE;
}
if (siginfo.ssi_code == CLD_STOPPED) {
INFO("Container init process was stopped");
return hdlr->init_died ? LXC_MAINLOOP_CLOSE : 0;
return hdlr->init_died ? LXC_MAINLOOP_CLOSE : LXC_MAINLOOP_CONTINUE;
} else if (siginfo.ssi_code == CLD_CONTINUED) {
INFO("Container init process was continued");
return hdlr->init_died ? LXC_MAINLOOP_CLOSE : 0;
return hdlr->init_died ? LXC_MAINLOOP_CLOSE : LXC_MAINLOOP_CONTINUE;
}
DEBUG("Container init process %d exited", hdlr->pid);
@ -1901,6 +1901,11 @@ int __lxc_start(const char *name, struct lxc_handler *handler,
goto out_abort;
}
if (!handler->init_died && handler->pid > 0) {
ERROR("Child process is not killed");
goto out_abort;
}
status = lxc_wait_for_pid_status(handler->pid);
if (status < 0)
SYSERROR("Failed to retrieve status for %d", handler->pid);

2
src/lxc/tools/lxc_top.c Normal file → Executable file
View File

@ -671,7 +671,7 @@ static int stdin_handler(int fd, uint32_t events, void *data,
if (events & EPOLLHUP)
*in_char = 'q';
return 1;
return LXC_MAINLOOP_CLOSE;
}
int main(int argc, char *argv[])