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.0.8~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed338df9686b1969b9d751abc6a8c98a13e12002;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 a239cf7aa..a97741136 100644 --- a/src/lxc/lxc_autostart.c +++ b/src/lxc/lxc_autostart.c @@ -174,8 +174,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)); @@ -353,7 +355,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, default_start_args)) + if (!c->start(c, 0, default_start_args)) { fprintf(stderr, "Error starting container: %s\n", c->name); + fflush(stderr); + } else sleep(get_config_integer(c, "lxc.start.delay")); }