]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
returns a specific info when we have ECONNREFUSED
authorDaniel Lezcano <dlezcano@fr.ibm.com>
Wed, 7 Oct 2009 14:06:09 +0000 (16:06 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Wed, 7 Oct 2009 14:06:09 +0000 (16:06 +0200)
When a command can not be send because the connection is refused,
that means the container is stopped. Let's report this specific
case instead of raising an error.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: Michel Normand <normand@fr.ibm.com>
src/lxc/commands.c
src/lxc/commands.h
src/lxc/console.c
src/lxc/state.c
src/lxc/stop.c

index 51d318eb55eac7dd8b3c1f56137d221b045a3c64..1ae9d24e158d8c877c0358be71898e1cae66ad9e 100644 (file)
@@ -52,7 +52,8 @@ static int receive_answer(int sock, struct lxc_answer *answer)
        return ret;
 }
 
-extern int lxc_command(const char *name, struct lxc_command *command)
+extern int lxc_command(const char *name, struct lxc_command *command,
+                       int *stopped)
 {
        int sock, ret = -1;
        char path[sizeof(((struct sockaddr_un *)0)->sun_path)] = { 0 };
@@ -61,20 +62,25 @@ extern int lxc_command(const char *name, struct lxc_command *command)
        sprintf(offset, "/var/run/lxc/%s/command", name);
 
        sock = lxc_af_unix_connect(path);
+       if (sock < 0 && errno == ECONNREFUSED) {
+               *stopped = 1;
+               return -1;
+       }
+
        if (sock < 0) {
-               WARN("failed to connect to '@%s': %s", offset, strerror(errno));
+               SYSERROR("failed to connect to '@%s'", offset);
                return -1;
        }
 
        ret = lxc_af_unix_send_credential(sock, &command->request,
                                        sizeof(command->request));
        if (ret < 0) {
-               SYSERROR("failed to send credentials");
+               SYSERROR("failed to send request to '@%s'", offset);
                goto out_close;
        }
 
        if (ret != sizeof(command->request)) {
-               SYSERROR("message only partially sent to '@%s'", offset);
+               SYSERROR("message partially sent to '@%s'", offset);
                goto out_close;
        }
 
index 925eb446d76e4fd66fe986773431adf4bc61fc65..3c6c08271b26938fdbdd9d33b25ba3e62913e450 100644 (file)
@@ -45,7 +45,8 @@ struct lxc_command {
        struct lxc_answer answer;
 };
 
-extern int lxc_command(const char *name, struct lxc_command *command);
+extern int lxc_command(const char *name, struct lxc_command *command,
+                       int *stopped);
 
 struct lxc_epoll_descr;
 struct lxc_handler;
index 92bbd47c62b362fd3335a27ba96a48728e12763f..05f06309b10d07d04f403f1b9dd6ff3161a03a67 100644 (file)
@@ -35,12 +35,17 @@ lxc_log_define(lxc_console, lxc);
 
 extern int lxc_console(const char *name, int ttynum, int *fd)
 {
-       int ret;
+       int ret, stopped = 0;
        struct lxc_command command = {
                .request = { .type = LXC_COMMAND_TTY, .data = ttynum },
        };
 
-       ret = lxc_command(name, &command);
+       ret = lxc_command(name, &command, &stopped);
+       if (ret < 0 && stopped) {
+               ERROR("'%s' is stopped", name);
+               return -1;
+       }
+
        if (ret < 0) {
                ERROR("failed to send command");
                return -1;
index 06b7b632f2ed5d90e05147f3be6f2090ef8693f4..1e8b8e159302a3a29f7a458b0ea0a94b9ac8bff1 100644 (file)
@@ -100,9 +100,12 @@ lxc_state_t lxc_getstate(const char *name)
                .request = { .type = LXC_COMMAND_STATE },
        };
 
-       int ret;
+       int ret, stopped = 0;
+
+       ret = lxc_command(name, &command, &stopped);
+       if (ret < 0 && stopped)
+               return STOPPED;
 
-       ret = lxc_command(name, &command);
        if (ret < 0) {
                ERROR("failed to send command");
                return -1;
index a88cb4e9db00a4c0b3db1bc4a0c18a96fd996774..504d27e585c27f44b9288e86042761a41239796d 100644 (file)
@@ -43,9 +43,14 @@ int lxc_stop(const char *name)
                .request = { .type = LXC_COMMAND_STOP },
        };
 
-       int ret;
+       int ret, stopped = 0;
+
+       ret = lxc_command(name, &command,&stopped);
+       if (ret < 0 && stopped) {
+               INFO("'%s' is already stopped", name);
+               return 0;
+       }
 
-       ret = lxc_command(name, &command);
        if (ret < 0) {
                ERROR("failed to send command");
                return -1;
@@ -55,7 +60,7 @@ int lxc_stop(const char *name)
         * closed
         */
        if (ret > 0) {
-               ERROR("stop request rejected for '%s': %s",
+               ERROR("failed to stop '%s': %s",
                        name, strerror(-command.answer.ret));
                return -1;
        }