From: Stéphane Graber Date: Fri, 17 Jul 2015 18:35:15 +0000 (-0400) Subject: lxc-autostart: Fix broken output X-Git-Tag: lxc-1.1.3~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d6347a4cd69f5593b233fcba8354986df4c1767;p=thirdparty%2Flxc.git lxc-autostart: Fix broken output This fixes some typos, missing newlines and unflushed output leading to duplicate entries when piped (similar to what we had in lxc-info). Reported-by: Marc Gariépy Signed-off-by: Stéphane Graber --- diff --git a/src/lxc/lxc_autostart.c b/src/lxc/lxc_autostart.c index f5b9e32f9..1e48f94f0 100644 --- a/src/lxc/lxc_autostart.c +++ b/src/lxc/lxc_autostart.c @@ -177,8 +177,10 @@ static struct lxc_list *accumulate_list(char *input, char *delimiter, struct lxc if ( list_contains_entry( workptr, workstr_list ) ) { if ( *workptr ) { fprintf(stderr, "Duplicate group \"%s\" in list - ignoring\n", workptr ); + fflush(stderr); } else { - fprintf(stderr, "Duilicate NULL group in list - ignoring\n" ); + fprintf(stderr, "Duplicate NULL group in list - ignoring\n" ); + fflush(stderr); } } else { worklist = malloc(sizeof(*worklist)); @@ -352,7 +354,8 @@ int main(int argc, char *argv[]) qsort(&containers[0], count, sizeof(struct lxc_container *), cmporder); if (cmd_groups_list && my_args.all) { - fprintf(stderr, "Specifying -a (all) with -g (groups) doesn't make sense. All option overrides."); + fprintf(stderr, "Specifying -a (all) with -g (groups) doesn't make sense. All option overrides.\n"); + fflush(stderr); } if (!cmd_groups_list) { @@ -423,12 +426,15 @@ int main(int argc, char *argv[]) if (my_args.shutdown) { /* Shutdown the container */ if (c->is_running(c)) { - if (my_args.list) + if (my_args.list) { printf("%s\n", c->name); + fflush(stdout); + } else { if (!c->shutdown(c, my_args.timeout)) { if (!c->stop(c)) { fprintf(stderr, "Error shutting down container: %s\n", c->name); + fflush(stderr); } } } @@ -437,23 +443,31 @@ int main(int argc, char *argv[]) else if (my_args.hardstop) { /* Kill the container */ if (c->is_running(c)) { - if (my_args.list) + if (my_args.list) { printf("%s\n", c->name); + fflush(stdout); + } else { - if (!c->stop(c)) + if (!c->stop(c)) { fprintf(stderr, "Error killing container: %s\n", c->name); + fflush(stderr); + } } } } else if (my_args.reboot) { /* Reboot the container */ if (c->is_running(c)) { - if (my_args.list) + if (my_args.list) { printf("%s %d\n", c->name, get_config_integer(c, "lxc.start.delay")); + fflush(stdout); + } else { - if (!c->reboot(c)) + if (!c->reboot(c)) { fprintf(stderr, "Error rebooting container: %s\n", c->name); + fflush(stderr); + } else sleep(get_config_integer(c, "lxc.start.delay")); } @@ -462,12 +476,16 @@ int main(int argc, char *argv[]) else { /* Start the container */ if (!c->is_running(c)) { - if (my_args.list) + if (my_args.list) { printf("%s %d\n", c->name, get_config_integer(c, "lxc.start.delay")); + fflush(stdout); + } else { - if (!c->start(c, 0, NULL)) + if (!c->start(c, 0, NULL)) { fprintf(stderr, "Error starting container: %s\n", c->name); + fflush(stderr); + } else sleep(get_config_integer(c, "lxc.start.delay")); }