initctl: Introduce -b[atch] mode for non-interactive use

This patch introduces a new option to initctl; -b, --batch skips
screen_init(), which might otherwise leak ANSI screen resize codes
to the console.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2018-02-16 10:06:37 +01:00
parent 0a643953c0
commit 7fdb280712
+10 -3
View File
@@ -522,6 +522,7 @@ static int usage(int rc)
"Usage: %s [OPTIONS] [COMMAND]\n"
"\n"
"Options:\n"
" -b, --batch Batch mode, no screen size probing\n"
" -v, --verbose Verbose output\n"
" -h, --help This help text\n"
"\n"
@@ -567,7 +568,7 @@ static int do_help(char *arg)
int main(int argc, char *argv[])
{
int c;
int interactive = 1, c;
char *cmd, arg[120];
struct command command[] = {
{ "debug", toggle_debug },
@@ -598,6 +599,7 @@ int main(int argc, char *argv[])
{ NULL, NULL }
};
struct option long_options[] = {
{"batch", 0, NULL, 'b'},
{"help", 0, NULL, 'h'},
{"debug", 0, NULL, 'd'},
{"verbose", 0, NULL, 'v'},
@@ -605,8 +607,12 @@ int main(int argc, char *argv[])
};
progname(argv[0]);
while ((c = getopt_long(argc, argv, "h?v", long_options, NULL)) != EOF) {
while ((c = getopt_long(argc, argv, "bh?v", long_options, NULL)) != EOF) {
switch(c) {
case 'b':
interactive = 0;
break;
case 'h':
case '?':
return usage(0);
@@ -617,7 +623,8 @@ int main(int argc, char *argv[])
}
}
screen_init();
if (interactive)
screen_init();
if (optind >= argc)
return show_status(NULL);