Commit 549153a7 by Michel Normand Committed by Daniel Lezcano

lxc-wait to check if container already in requested state

Without this patch the lxc_wait may wait forever if container is already in requested state. Note that this patch avoids also to be hang if container do not exist yet. Signed-off-by: 's avatarMichel Normand <normand@fr.ibm.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 2c396e12
...@@ -86,7 +86,6 @@ static int fillwaitedstates(char *strstates, int *states) ...@@ -86,7 +86,6 @@ static int fillwaitedstates(char *strstates, int *states)
states[state] = 1; states[state] = 1;
token = strtok_r(NULL, "|", &saveptr); token = strtok_r(NULL, "|", &saveptr);
} }
return 0; return 0;
} }
...@@ -95,6 +94,7 @@ int main(int argc, char *argv[]) ...@@ -95,6 +94,7 @@ int main(int argc, char *argv[])
{ {
struct lxc_msg msg; struct lxc_msg msg;
int s[MAX_STATE] = { }, fd; int s[MAX_STATE] = { }, fd;
int state, ret;
if (lxc_arguments_parse(&my_args, argc, argv)) if (lxc_arguments_parse(&my_args, argc, argv))
return -1; return -1;
...@@ -110,9 +110,22 @@ int main(int argc, char *argv[]) ...@@ -110,9 +110,22 @@ int main(int argc, char *argv[])
if (fd < 0) if (fd < 0)
return -1; return -1;
/*
* if container present,
* then check if already in requested state
*/
ret = -1;
state = lxc_getstate(my_args.name);
if (state < 0) {
goto out_close;
} else if ((state >= 0) && (s[state])) {
ret = 0;
goto out_close;
}
for (;;) { for (;;) {
if (lxc_monitor_read(fd, &msg) < 0) if (lxc_monitor_read(fd, &msg) < 0)
return -1; goto out_close;
if (strcmp(my_args.name, msg.name)) if (strcmp(my_args.name, msg.name))
continue; continue;
...@@ -122,11 +135,13 @@ int main(int argc, char *argv[]) ...@@ -122,11 +135,13 @@ int main(int argc, char *argv[])
if (msg.value < 0 || msg.value >= MAX_STATE) { if (msg.value < 0 || msg.value >= MAX_STATE) {
ERROR("Receive an invalid state number '%d'", ERROR("Receive an invalid state number '%d'",
msg.value); msg.value);
return -1; goto out_close;
} }
if (s[msg.value]) if (s[msg.value]) {
return 0; ret = 0;
goto out_close;
}
break; break;
default: default:
/* just ignore garbage */ /* just ignore garbage */
...@@ -134,5 +149,7 @@ int main(int argc, char *argv[]) ...@@ -134,5 +149,7 @@ int main(int argc, char *argv[])
} }
} }
return 0; out_close:
lxc_monitor_close(fd);
return ret;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment