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 };
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;
}
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;
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;
.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;
.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;
* closed
*/
if (ret > 0) {
- ERROR("stop request rejected for '%s': %s",
+ ERROR("failed to stop '%s': %s",
name, strerror(-command.answer.ret));
return -1;
}