Add option --no-tty-restore / -N that makes execution flow omit call to tty_restore().

This commit is contained in:
Erling Sigurdson 2025-11-08 04:21:25 +03:00
parent 3af4c5591e
commit 4eaf19493b
9 changed files with 33 additions and 3 deletions

View file

@ -122,6 +122,7 @@ Options:
--exclude-drivers <pattern> Exclude drivers by pattern --exclude-drivers <pattern> Exclude drivers by pattern
--exclude-tids <pattern> Exclude topology IDs by pattern --exclude-tids <pattern> Exclude topology IDs by pattern
-n, --no-reconnect Do not reconnect -n, --no-reconnect Do not reconnect
-N, --no-tty-restore Do not restore initial TTY device settings
-e, --local-echo Enable local echo -e, --local-echo Enable local echo
--input-mode normal|hex|line Select input mode (default: normal) --input-mode normal|hex|line Select input mode (default: normal)
--output-mode normal|hex|hexN Select output mode (default: normal) --output-mode normal|hex|hexN Select output mode (default: normal)

View file

@ -19,6 +19,7 @@ output-delay = 0
output-line-delay = 0 output-line-delay = 0
auto-connect = direct auto-connect = direct
no-reconnect = false no-reconnect = false
no-tty-restore = false
local-echo = false local-echo = false
input-mode = normal input-mode = normal
output-mode = normal output-mode = normal

View file

@ -123,6 +123,14 @@ Do not reconnect.
This means that tio will exit if it fails to connect to device or an This means that tio will exit if it fails to connect to device or an
established connection is lost. 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 .TP
.BR \-e ", " "\-\-local\-echo .BR \-e ", " "\-\-local\-echo

View file

@ -94,6 +94,12 @@ OPTIONS
This means that tio will exit if it fails to connect to device or an established connection is lost. 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 -e, --local-echo
Enable local echo. Enable local echo.

View file

@ -23,6 +23,7 @@ _tio()
--exclude-drivers \ --exclude-drivers \
--exclude-tids \ --exclude-tids \
-n --no-reconnect \ -n --no-reconnect \
-N --no-tty-restore \
-e --local-echo \ -e --local-echo \
-l --log \ -l --log \
--log-file \ --log-file \

View file

@ -189,6 +189,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-drivers", &option.exclude_devices, NULL);
config_get_string(key_file, group, "exclude-tids", &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-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_bool(key_file, group, "local-echo", &option.local_echo);
config_get_string(key_file, group, "input-mode", &string, "normal", "hex", "line", NULL); config_get_string(key_file, group, "input-mode", &string, "normal", "hex", "line", NULL);
if (string != NULL) if (string != NULL)

View file

@ -79,6 +79,7 @@ struct option_t option =
.dcd_pulse_duration = 100, .dcd_pulse_duration = 100,
.ri_pulse_duration = 100, .ri_pulse_duration = 100,
.no_reconnect = false, .no_reconnect = false,
.no_tty_restore = false,
.auto_connect = AUTO_CONNECT_DIRECT, .auto_connect = AUTO_CONNECT_DIRECT,
.log = false, .log = false,
.log_append = false, .log_append = false,
@ -148,6 +149,7 @@ void option_print_help(char *argv[])
printf(" --exclude-drivers <pattern> Exclude drivers by pattern\n"); printf(" --exclude-drivers <pattern> Exclude drivers by pattern\n");
printf(" --exclude-tids <pattern> Exclude topology IDs by pattern\n"); printf(" --exclude-tids <pattern> Exclude topology IDs by pattern\n");
printf(" -n, --no-reconnect Do not reconnect\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(" -e, --local-echo Enable local echo\n");
printf(" --input-mode normal|hex|line Select input mode (default: normal)\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"); printf(" --output-mode normal|hex|hexN Select output mode (default: normal)\n");
@ -833,6 +835,7 @@ void options_print()
tio_printf(" Output line delay: %d", option.output_line_delay); tio_printf(" Output line delay: %d", option.output_line_delay);
tio_printf(" Automatic connect strategy: %s", option_auto_connect_state_to_string(option.auto_connect)); 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(" Automatic reconnect: %s", option.no_reconnect ? "true" : "false");
tio_printf(" TTY device settings restore: %s", option.no_tty_restore ? "true" : "false");
tio_printf(" Pulse duration: DTR=%d RTS=%d CTS=%d DSR=%d DCD=%d RI=%d", option.dtr_pulse_duration, tio_printf(" Pulse duration: DTR=%d RTS=%d CTS=%d DSR=%d DCD=%d RI=%d", option.dtr_pulse_duration,
option.rts_pulse_duration, option.rts_pulse_duration,
option.cts_pulse_duration, option.cts_pulse_duration,
@ -904,6 +907,7 @@ void options_parse(int argc, char *argv[])
{"exclude-drivers", required_argument, 0, OPT_EXCLUDE_DRIVERS }, {"exclude-drivers", required_argument, 0, OPT_EXCLUDE_DRIVERS },
{"exclude-tids", required_argument, 0, OPT_EXCLUDE_TIDS }, {"exclude-tids", required_argument, 0, OPT_EXCLUDE_TIDS },
{"no-reconnect", no_argument, 0, 'n' }, {"no-reconnect", no_argument, 0, 'n' },
{"no-tty-restore", no_argument, 0, 'N' },
{"local-echo", no_argument, 0, 'e' }, {"local-echo", no_argument, 0, 'e' },
{"timestamp", no_argument, 0, 't' }, {"timestamp", no_argument, 0, 't' },
{"timestamp-format", required_argument, 0, OPT_TIMESTAMP_FORMAT }, {"timestamp-format", required_argument, 0, OPT_TIMESTAMP_FORMAT },
@ -937,7 +941,7 @@ void options_parse(int argc, char *argv[])
int option_index = 0; int option_index = 0;
/* Parse argument using getopt_long */ /* 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 */ /* Detect the end of the options */
if (c == -1) if (c == -1)
@ -1007,6 +1011,10 @@ void options_parse(int argc, char *argv[])
option.no_reconnect = true; option.no_reconnect = true;
break; break;
case 'N':
option.no_tty_restore = true;
break;
case 'e': case 'e':
option.local_echo = true; option.local_echo = true;
break; break;

View file

@ -61,6 +61,7 @@ struct option_t
int dcd_pulse_duration; int dcd_pulse_duration;
int ri_pulse_duration; int ri_pulse_duration;
bool no_reconnect; bool no_reconnect;
bool no_tty_restore;
auto_connect_t auto_connect; auto_connect_t auto_connect;
bool log; bool log;
bool log_append; bool log_append;

View file

@ -2600,10 +2600,13 @@ int tty_connect(void)
rs485_mode_enable(device_fd); 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) if (first)
{
if (option.no_tty_restore == false)
{ {
atexit(&tty_restore); atexit(&tty_restore);
}
first = false; first = false;
} }