]> git.proxmox.com Git - mirror_lxc.git/commitdiff
fix multiple console for a container
authorDaniel Lezcano <daniel.lezcano@free.fr>
Tue, 26 Oct 2010 15:42:38 +0000 (17:42 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Tue, 26 Oct 2010 15:42:38 +0000 (17:42 +0200)
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>
src/lxc/commands.c
src/lxc/commands.h
src/lxc/console.c

index 73d711156c6a328a45da6fa9050e177968fae890..b83d65a41d82ba330042078d4d619c08971f1396 100644 (file)
@@ -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 = {
index b013b7d46b648ba01d248581aca992b1fbab347f..d5c013fc73294eedf9c0feefbf24c51b770f3106 100644 (file)
@@ -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;
 
index 417babdee9a4837ad49f4f6212c7e485495a5c19..b5fc270a98f3f26c8e2e41b212007eb4702cbaaf 100644 (file)
@@ -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;