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: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
states[state] = 1;
token = strtok_r(NULL, "|", &saveptr);
states[state] = 1;
token = strtok_r(NULL, "|", &saveptr);
{
struct lxc_msg msg;
int s[MAX_STATE] = { }, fd;
{
struct lxc_msg msg;
int s[MAX_STATE] = { }, fd;
if (lxc_arguments_parse(&my_args, argc, argv))
return -1;
if (lxc_arguments_parse(&my_args, argc, argv))
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 (;;) {
if (lxc_monitor_read(fd, &msg) < 0)
for (;;) {
if (lxc_monitor_read(fd, &msg) < 0)
if (strcmp(my_args.name, msg.name))
continue;
if (strcmp(my_args.name, msg.name))
continue;
if (msg.value < 0 || msg.value >= MAX_STATE) {
ERROR("Receive an invalid state number '%d'",
msg.value);
if (msg.value < 0 || msg.value >= MAX_STATE) {
ERROR("Receive an invalid state number '%d'",
msg.value);
- if (s[msg.value])
- return 0;
+ if (s[msg.value]) {
+ ret = 0;
+ goto out_close;
+ }
break;
default:
/* just ignore garbage */
break;
default:
/* just ignore garbage */
+out_close:
+ lxc_monitor_close(fd);
+ return ret;