mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-06 10:02:23 +00:00
returns a specific info when we have ECONNREFUSED
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>
This commit is contained in:
parent
787dc17c3b
commit
d97b36f8f8
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user