From: Daniel Lezcano Date: Tue, 26 Oct 2010 15:42:38 +0000 (+0200) Subject: fix multiple console for a container X-Git-Tag: lxc-0.7.3~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43eb6f2931cd3af5eee734e46fed122301e4d0cf;p=thirdparty%2Flxc.git fix multiple console for a container Don't close the socket when we ask for a console, otherwise this will make the console slot to be freed, so the next console will use the same slot leading to an erratic behavior. Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/commands.c b/src/lxc/commands.c index 73d711156..b83d65a41 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -69,8 +69,8 @@ static int receive_answer(int sock, struct lxc_answer *answer) return ret; } -extern int lxc_command(const char *name, struct lxc_command *command, - int *stopped) +static int __lxc_command(const char *name, struct lxc_command *command, + int *stopped, int stay_connected) { int sock, ret = -1; char path[sizeof(((struct sockaddr_un *)0)->sun_path)] = { 0 }; @@ -103,10 +103,25 @@ extern int lxc_command(const char *name, struct lxc_command *command, ret = receive_answer(sock, &command->answer); out: - close(sock); + if (!stay_connected || ret < 0) + close(sock); + return ret; } +extern int lxc_command(const char *name, + struct lxc_command *command, int *stopped) +{ + return __lxc_command(name, command, stopped, 0); +} + +extern int lxc_command_connected(const char *name, + struct lxc_command *command, int *stopped) +{ + return __lxc_command(name, command, stopped, 1); +} + + pid_t get_init_pid(const char *name) { struct lxc_command command = { diff --git a/src/lxc/commands.h b/src/lxc/commands.h index b013b7d46..d5c013fc7 100644 --- a/src/lxc/commands.h +++ b/src/lxc/commands.h @@ -48,9 +48,13 @@ struct lxc_command { }; extern pid_t get_init_pid(const char *name); + extern int lxc_command(const char *name, struct lxc_command *command, int *stopped); +extern int lxc_command_connected(const char *name, struct lxc_command *command, + int *stopped); + struct lxc_epoll_descr; struct lxc_handler; diff --git a/src/lxc/console.c b/src/lxc/console.c index 417babdee..b5fc270a9 100644 --- a/src/lxc/console.c +++ b/src/lxc/console.c @@ -47,7 +47,7 @@ extern int lxc_console(const char *name, int ttynum, int *fd) .request = { .type = LXC_COMMAND_TTY, .data = ttynum }, }; - ret = lxc_command(name, &command, &stopped); + ret = lxc_command_connected(name, &command, &stopped); if (ret < 0 && stopped) { ERROR("'%s' is stopped", name); return -1;