[lxc-devel] [lxc/master] tools: Indicate container startup failure
tcharding on Github
lxc-bot at linuxcontainers.org
Fri Aug 17 07:17:04 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1803 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180817/3abcf5b4/attachment.bin>
-------------- next part --------------
From 5b7672143600700b0acba9960245e6ba9af16466 Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Fri, 17 Aug 2018 16:49:46 +1000
Subject: [PATCH] tools: Indicate container startup failure
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.
We specifically use -1 instead of EXIT_FAILURE. Even if EXIT_FAILURE is
defined as 1 this is congruent with 'total failure'.
Indicate container startup failure. For total failure return -1, for
partial failure return -2.
Signed-off-by: Tobin C. Harding <me at tobin.cc>
---
src/lxc/tools/lxc_autostart.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/lxc/tools/lxc_autostart.c b/src/lxc/tools/lxc_autostart.c
index 5d0445258..f259f76c8 100644
--- a/src/lxc/tools/lxc_autostart.c
+++ b/src/lxc/tools/lxc_autostart.c
@@ -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)
+ return -1; /* Total failure */
+ else if (failed > 0)
+ return -2; /* Partial failure */
+
exit(EXIT_SUCCESS);
}
More information about the lxc-devel
mailing list