From: Martin Mares Date: Tue, 21 Feb 2012 12:34:45 +0000 (+0100) Subject: logoutput: More control over verbosity X-Git-Tag: v5.0~10 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=84723a3526317ddafc5e857cddbf8ba631b72c54;p=libucw.git logoutput: More control over verbosity Patch by Tomas Ebenlendr. --- diff --git a/ucw/shell/logoutput.c b/ucw/shell/logoutput.c index ab8ca452..0ef0118b 100644 --- a/ucw/shell/logoutput.c +++ b/ucw/shell/logoutput.c @@ -27,6 +27,8 @@ #include static uns max_line = 1024; +static int launch_finish_messages = 1; +static int nonzero_status_message = 1; static struct cf_section cfsec_logoutput = { CF_ITEMS { @@ -197,26 +199,37 @@ const struct option my_long_opts[] = { { "logfile", 1, 0, 'f'}, { "logname", 1, 0, 'n'}, { "descriptor", 1, 0, 'l'}, + { "nv", 0, 0, 'q'}, + { "nonverbose", 0, 0, 'q'}, + { "non-verbose", 0, 0, 'q'}, + { "non_verbose", 0, 0, 'q'}, + { "silent", 0, 0, 's'}, { NULL, 0, 0, 0} }; #undef CF_USAGE_TAB -#define CF_USAGE_TAB "\t\t" +#define CF_USAGE_TAB "\t " static char usage[] = "Usage:\n" - "logoutput -h|--help\t\tThis help.\n" - "logoutput -i|--input\tRead filedescriptors and log them.\n" - "\t\t\t\tdefault: stdin at level I.\n" + "logoutput -h|--help\t\t This help.\n" + "logoutput -i|--input\t Read filedescriptors and log them.\n" + "\t\t\t\t default: stdin at level I.\n" "logoutput [--] [arguments for cmd ...]\n" - "\t\t\t\tOpen filedescriptors for writing for\n" - "\t\t\t\tcommand and log them.\n" - "\t\t\t\tdefault: stdout:I, stderr:W.\n" + "\t\t\t\t Open filedescriptors for writing for\n" + "\t\t\t\t command and log them.\n" + "\t\t\t\t default: stdout:I, stderr:W.\n" "Options:\n" CF_USAGE - "-n, --logname \t\t\tUse as program name in logs.\n" - "-l, --descriptor :\tOpen filedescriptor and log it\n" - "\t\t\t\t\tat level (discards defaults).\n" - "-f, --logfile \t\t\tLog to file .\n"; + "-n, --logname \t\t Use as program name in logs.\n" + "-l, --descriptor : Open filedescriptor and log it\n" + "\t\t\t\t at level (discards defaults).\n" + "-f, --logfile \t\t Log to file .\n" + "-q, --nv, --nonverbose\t\t Suppress launching and successful\n" + "\t\t\t\t finish messages.\n" + "-s, --silent\t\t\t Suppress launching message and all\n" + "\t\t\t\t finish messages (i.e., no warning if\n" + "\t\t\t\t terminates with nonzero message or by\n" + "\t\t\t\t signal.\n"; int main(int argc, char **argv) @@ -284,6 +297,13 @@ main(int argc, char **argv) } break; + case 's': + nonzero_status_message = 0; + /* fallthrough */ + case 'q': + launch_finish_messages = 0; + break; + default: optind--; goto opt_done; @@ -409,7 +429,8 @@ opt_done: } buf2[-1] = 0; - msg(L_INFO, "Launching command: %s", buf); + if (launch_finish_messages) + msg(L_INFO, "Launching command: %s", buf); } /* Set logname. */ @@ -437,10 +458,12 @@ opt_done: } if (format_exit_status(buf, status)) { - msg(L_WARN, "Child %s", buf); + if (nonzero_status_message) + msg(L_WARN, "Child %s", buf); return WIFEXITED(status) ? WEXITSTATUS(status) : 127; } else { - msg(L_INFO, "Child terminated successfully."); + if (launch_finish_messages) + msg(L_INFO, "Child terminated successfully."); return 0; } }