commands: add ability to audit fd connection and cleanup path

parent ab92468c
......@@ -11,6 +11,13 @@
#include "macro.h"
#include "state.h"
/*
* Value command callbacks should return when they want the client fd to be
* cleaned up by the main loop. This is most certainly what you want unless you
* have specific reasons to keep the file descriptor alive.
*/
#define LXC_CMD_REAP_CLIENT_FD 1
typedef enum {
LXC_CMD_CONSOLE,
LXC_CMD_TERMINAL_WINCH,
......
......@@ -185,5 +185,6 @@ int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler,
move_ptr(newclient);
move_ptr(tmplist);
return log_trace(MAX_STATE, "Added state client %d to state client list", state_client_fd);
TRACE("Added state client fd %d to state client list", state_client_fd);
return MAX_STATE;
}
......@@ -2064,10 +2064,11 @@ WRAP_API_1(bool, lxcapi_reboot2, int)
static bool do_lxcapi_shutdown(struct lxc_container *c, int timeout)
{
__do_close_prot_errno int state_client_fd = -EBADF;
int haltsignal = SIGPWR;
lxc_state_t states[MAX_STATE] = {0};
int killret, ret;
pid_t pid;
int haltsignal = SIGPWR, state_client_fd = -EBADF;
lxc_state_t states[MAX_STATE] = {0};
if (!c)
return false;
......@@ -2107,20 +2108,15 @@ static bool do_lxcapi_shutdown(struct lxc_container *c, int timeout)
/* Send shutdown signal to container. */
killret = kill(pid, haltsignal);
if (killret < 0) {
if (state_client_fd >= 0)
close(state_client_fd);
if (killret < 0)
return log_warn(false, "Failed to send signal %d to pid %d", haltsignal, pid);
WARN("Failed to send signal %d to pid %d", haltsignal, pid);
return false;
}
TRACE("Sent signal %d to pid %d", haltsignal, pid);
if (timeout == 0)
return true;
ret = lxc_cmd_sock_rcv_state(state_client_fd, timeout);
close(state_client_fd);
if (ret < 0)
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment