]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tools: Indicate container startup failure 2542/head
authorTobin C. Harding <me@tobin.cc>
Fri, 17 Aug 2018 06:49:46 +0000 (16:49 +1000)
committerTobin C. Harding <me@tobin.cc>
Sun, 19 Aug 2018 23:00:14 +0000 (09:00 +1000)
When running lxc-autostart we do not currently indicate failure to start
containers, either partial failure i.e. some of the containers failed to
start or total failure i.e. all of the containers failed to start.

Indicate container startup failure.  For total failure exit(1), for
partial failure exit(2).

Signed-off-by: Tobin C. Harding <me@tobin.cc>
src/lxc/tools/lxc_autostart.c

index 5d0445258ecaaefd4c4649c75005d060baf35eb7..e2702f6e926fecebb9a52c1e387a1441d52a8232 100644 (file)
@@ -318,7 +318,7 @@ static int toss_list(struct lxc_list *c_groups_list)
 
 int main(int argc, char *argv[])
 {
-       int count = 0, i = 0, ret = 0;
+       int count = 0, failed = 0, i = 0, ret = 0;
        struct lxc_list *cmd_group;
        struct lxc_container **containers = NULL;
        struct lxc_list **c_groups_lists = NULL;
@@ -491,11 +491,15 @@ int main(int argc, char *argv[])
 
        }
 
-       /* clean up any lingering detritus */
+       /* clean up any lingering detritus, if container exists here
+        * then it must have failed to start.
+        */
+       failed = 0;
        for (i = 0; i < count; i++) {
-               if (containers[i])
+               if (containers[i]) {
+                       failed++;
                        lxc_container_put(containers[i]);
-
+               }
                if (c_groups_lists && c_groups_lists[i])
                        toss_list(c_groups_lists[i]);
        }
@@ -504,5 +508,10 @@ int main(int argc, char *argv[])
        toss_list(cmd_groups_list);
        free(containers);
 
+       if (failed == count)
+               exit(1);        /* Total failure */
+       else if (failed > 0)
+               exit(2);        /* Partial failure */
+
        exit(EXIT_SUCCESS);
 }