aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@free.fr>2010-10-26 17:42:38 +0200
committerDaniel Lezcano <dlezcano@fr.ibm.com>2010-10-26 17:42:38 +0200
commit43eb6f2931cd3af5eee734e46fed122301e4d0cf (patch)
tree608924f11019bab3f1598db75a30bba02ab34080
parentdon't play with the capabilities when we are root (diff)
downloadlxc-43eb6f2931cd3af5eee734e46fed122301e4d0cf.tar.gz
lxc-43eb6f2931cd3af5eee734e46fed122301e4d0cf.tar.bz2
lxc-43eb6f2931cd3af5eee734e46fed122301e4d0cf.zip
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 <daniel.lezcano@free.fr>
-rw-r--r--src/lxc/commands.c21
-rw-r--r--src/lxc/commands.h4
-rw-r--r--src/lxc/console.c2
3 files changed, 23 insertions, 4 deletions
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 73d7111..b83d65a 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 b013b7d..d5c013f 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 417babd..b5fc270 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;