diff --git a/README.md b/README.md index e3ab066..78d4ce7 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,7 @@ Options: --exclude-drivers Exclude drivers by pattern --exclude-tids Exclude topology IDs by pattern -n, --no-reconnect Do not reconnect + -N, --no-tty-restore Do not restore initial TTY device settings -e, --local-echo Enable local echo --input-mode normal|hex|line Select input mode (default: normal) --output-mode normal|hex|hexN Select output mode (default: normal) diff --git a/examples/config/config b/examples/config/config index 7bd141e..1aa038b 100644 --- a/examples/config/config +++ b/examples/config/config @@ -19,6 +19,7 @@ output-delay = 0 output-line-delay = 0 auto-connect = direct no-reconnect = false +no-tty-restore = false local-echo = false input-mode = normal output-mode = normal diff --git a/man/tio.1.in b/man/tio.1.in index aaaf8a5..dd8243e 100644 --- a/man/tio.1.in +++ b/man/tio.1.in @@ -123,6 +123,14 @@ Do not reconnect. This means that tio will exit if it fails to connect to device or an established connection is lost. +.TP +.BR \-n ", " \-\-no\-tty\-restore + +Do not restore initial TTY device settings. + +This means that tio will exit without trying to restore TTY device +settings that existed when tio was started. + .TP .BR \-e ", " "\-\-local\-echo diff --git a/man/tio.1.txt b/man/tio.1.txt index 46afb5e..f3344a0 100644 --- a/man/tio.1.txt +++ b/man/tio.1.txt @@ -94,6 +94,12 @@ OPTIONS This means that tio will exit if it fails to connect to device or an established connection is lost. + -N, --no-tty-restore + + Do not restore initial TTY device settings. + + This means that tio will exit without trying to restore TTY device settings that existed when tio was started. + -e, --local-echo Enable local echo. diff --git a/src/bash-completion/tio.in b/src/bash-completion/tio.in index b3b61cb..3d59d73 100644 --- a/src/bash-completion/tio.in +++ b/src/bash-completion/tio.in @@ -23,6 +23,7 @@ _tio() --exclude-drivers \ --exclude-tids \ -n --no-reconnect \ + -N --no-tty-restore \ -e --local-echo \ -l --log \ --log-file \ diff --git a/src/configfile.c b/src/configfile.c index 0fc230c..cc21dfb 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -196,6 +196,7 @@ static void config_parse_keys(GKeyFile *key_file, char *group) config_get_string(key_file, group, "exclude-drivers", &option.exclude_devices, NULL); config_get_string(key_file, group, "exclude-tids", &option.exclude_devices, NULL); config_get_bool(key_file, group, "no-reconnect", &option.no_reconnect); + config_get_bool(key_file, group, "no-tty-restore", &option.no_tty_restore); config_get_bool(key_file, group, "local-echo", &option.local_echo); config_get_string(key_file, group, "input-mode", &string, "normal", "hex", "line", NULL); if (string != NULL) diff --git a/src/options.c b/src/options.c index 09f35e8..5cdcbe4 100644 --- a/src/options.c +++ b/src/options.c @@ -82,6 +82,7 @@ struct option_t option = .dcd_pulse_duration = 100, .ri_pulse_duration = 100, .no_reconnect = false, + .no_tty_restore = false, .auto_connect = AUTO_CONNECT_DIRECT, .log = false, .log_append = false, @@ -153,6 +154,7 @@ void option_print_help(char *argv[]) printf(" --exclude-drivers Exclude drivers by pattern\n"); printf(" --exclude-tids Exclude topology IDs by pattern\n"); printf(" -n, --no-reconnect Do not reconnect\n"); + printf(" -N, --no-tty-restore Do not restore initial TTY device settings\n"); printf(" -e, --local-echo Enable local echo\n"); printf(" --input-mode normal|hex|line Select input mode (default: normal)\n"); printf(" --output-mode normal|hex|hexN Select output mode (default: normal)\n"); @@ -844,6 +846,7 @@ void option_parse_mappings(const char *map) void options_print() { + /* note: negative true/false settings are rephrased as affirmative no/yes. */ tio_printf(" Device: %s", device_name); tio_printf(" Baudrate: %u", option.baudrate); tio_printf(" Databits: %d", option.databits); @@ -858,6 +861,7 @@ void options_print() tio_printf(" Output line delay char: %s", option.output_line_delay_char == '\r' ? "cr" : "lf"); tio_printf(" Automatic connect strategy: %s", option_auto_connect_state_to_string(option.auto_connect)); tio_printf(" Automatic reconnect: %s", option.no_reconnect ? "true" : "false"); + tio_printf(" TTY device settings restore: %s", option.no_tty_restore ? "true" : "false"); // clang-format off tio_printf(" Pulse duration: DTR=%d RTS=%d CTS=%d DSR=%d DCD=%d RI=%d", option.dtr_pulse_duration, option.rts_pulse_duration, @@ -933,6 +937,7 @@ void options_parse(int argc, char *argv[]) {"exclude-drivers", required_argument, 0, OPT_EXCLUDE_DRIVERS }, {"exclude-tids", required_argument, 0, OPT_EXCLUDE_TIDS }, {"no-reconnect", no_argument, 0, 'n' }, + {"no-tty-restore", no_argument, 0, 'N' }, {"local-echo", no_argument, 0, 'e' }, {"timestamp", no_argument, 0, 't' }, {"timestamp-format", required_argument, 0, OPT_TIMESTAMP_FORMAT }, @@ -967,7 +972,7 @@ void options_parse(int argc, char *argv[]) int option_index = 0; /* Parse argument using getopt_long */ - c = getopt_long(argc, argv, "b:d:f:s:p:o:O:a:netLlS:m:c:xrvh", long_options, &option_index); + c = getopt_long(argc, argv, "b:d:f:s:p:o:O:a:nNetLlS:m:c:xrvh", long_options, &option_index); /* Detect the end of the options */ if (c == -1) @@ -1041,6 +1046,10 @@ void options_parse(int argc, char *argv[]) option.no_reconnect = true; break; + case 'N': + option.no_tty_restore = true; + break; + case 'e': option.local_echo = true; break; diff --git a/src/options.h b/src/options.h index 5388de2..4f501ae 100644 --- a/src/options.h +++ b/src/options.h @@ -62,6 +62,7 @@ struct option_t int dcd_pulse_duration; int ri_pulse_duration; bool no_reconnect; + bool no_tty_restore; auto_connect_t auto_connect; bool log; bool log_append; diff --git a/src/tty.c b/src/tty.c index 2bfad11..2c4ace8 100644 --- a/src/tty.c +++ b/src/tty.c @@ -2706,10 +2706,13 @@ int tty_connect(void) rs485_mode_enable(device_fd); } - /* Make sure we restore tty settings on exit */ + /* Make sure we restore tty settings on exit unless ordered to keep current settings */ if (first) { - atexit(&tty_restore); + if (option.no_tty_restore == false) + { + atexit(&tty_restore); + } first = false; }