Add a non-interactive mode to tinc commands.
Some tinc commands, such as "tinc generate-keys", use the terminal to ask the user for information. This can be bypassed by making sure there is no terminal, which is trivial on *nix but might require jumping through some hoops on Windows depending on how the command is invoked. This commit adds a --batch option that ensures tinc will never ask the user for input, even if it is attached to a terminal.
This commit is contained in:
parent
afb175873e
commit
cc9203ee75
1 changed files with 7 additions and 2 deletions
|
@ -75,6 +75,7 @@ char *scriptextension = "";
|
||||||
static char *prompt;
|
static char *prompt;
|
||||||
|
|
||||||
static struct option const long_options[] = {
|
static struct option const long_options[] = {
|
||||||
|
{"batch", no_argument, NULL, 'b'},
|
||||||
{"config", required_argument, NULL, 'c'},
|
{"config", required_argument, NULL, 'c'},
|
||||||
{"net", required_argument, NULL, 'n'},
|
{"net", required_argument, NULL, 'n'},
|
||||||
{"help", no_argument, NULL, 1},
|
{"help", no_argument, NULL, 1},
|
||||||
|
@ -100,6 +101,7 @@ static void usage(bool status) {
|
||||||
} else {
|
} else {
|
||||||
printf("Usage: %s [options] command\n\n", program_name);
|
printf("Usage: %s [options] command\n\n", program_name);
|
||||||
printf("Valid options are:\n"
|
printf("Valid options are:\n"
|
||||||
|
" -b, --batch Don't ask for anything (non-interactive mode).\n"
|
||||||
" -c, --config=DIR Read configuration options from DIR.\n"
|
" -c, --config=DIR Read configuration options from DIR.\n"
|
||||||
" -n, --net=NETNAME Connect to net NETNAME.\n"
|
" -n, --net=NETNAME Connect to net NETNAME.\n"
|
||||||
" --pidfile=FILENAME Read control cookie from FILENAME.\n"
|
" --pidfile=FILENAME Read control cookie from FILENAME.\n"
|
||||||
|
@ -158,6 +160,10 @@ static bool parse_options(int argc, char **argv) {
|
||||||
case 0: /* long option */
|
case 0: /* long option */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'b':
|
||||||
|
tty = false;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'c': /* config file */
|
case 'c': /* config file */
|
||||||
confbase = xstrdup(optarg);
|
confbase = xstrdup(optarg);
|
||||||
confbasegiven = true;
|
confbasegiven = true;
|
||||||
|
@ -2439,6 +2445,7 @@ int main(int argc, char *argv[]) {
|
||||||
program_name = argv[0];
|
program_name = argv[0];
|
||||||
orig_argv = argv;
|
orig_argv = argv;
|
||||||
orig_argc = argc;
|
orig_argc = argc;
|
||||||
|
tty = isatty(0) && isatty(1);
|
||||||
|
|
||||||
if(!parse_options(argc, argv))
|
if(!parse_options(argc, argv))
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -2469,8 +2476,6 @@ int main(int argc, char *argv[]) {
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
crypto_init();
|
crypto_init();
|
||||||
|
|
||||||
tty = isatty(0) && isatty(1);
|
|
||||||
|
|
||||||
if(optind >= argc)
|
if(optind >= argc)
|
||||||
return cmd_shell(argc, argv);
|
return cmd_shell(argc, argv);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue