From 66cb3548061a70d8b72ab92f808d567475dcbc7c Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 23 Jul 2024 13:57:46 +0200 Subject: [PATCH] scriptlive: add --echo It would be beneficial to have a method for controlling the ECHO flag. References: https://github.com/util-linux/util-linux/pull/3133 Signed-off-by: Karel Zak --- term-utils/scriptlive.1.adoc | 5 +++++ term-utils/scriptlive.c | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/term-utils/scriptlive.1.adoc b/term-utils/scriptlive.1.adoc index 73e8faf5d3..1efb429bb6 100644 --- a/term-utils/scriptlive.1.adoc +++ b/term-utils/scriptlive.1.adoc @@ -33,6 +33,11 @@ File containing *script*'s terminal input. *-B*, *--log-io* _file_:: File containing *script*'s terminal output and input. +*-E*, *--echo* _when_:: +This option controls the *ECHO* flag for the slave end of the session's pseudoterminal. The supported modes are _always_, _never_, or _auto_. ++ +The default is _auto_ -- in this case, *ECHO* enabled; this default behavior is subject to change. + *-t*, *--timing* _file_:: File containing *script*'s timing output. This option overrides old-style arguments. diff --git a/term-utils/scriptlive.c b/term-utils/scriptlive.c index 36c195cc0d..af946a08d0 100644 --- a/term-utils/scriptlive.c +++ b/term-utils/scriptlive.c @@ -72,6 +72,7 @@ usage(void) fputs(USAGE_SEPARATOR, out); fputs(_(" -c, --command run command rather than interactive shell\n"), out); fputs(_(" -d, --divisor speed up or slow down execution with time divisor\n"), out); + fputs(_(" -E, --echo echo input in session (auto, always or never)\n"), out); fputs(_(" -m, --maxdelay wait at most this many seconds between updates\n"), out); fprintf(out, USAGE_HELP_OPTIONS(25)); @@ -164,13 +165,14 @@ main(int argc, char *argv[]) *shell = NULL, *command = NULL; double divi = 1; int diviopt = FALSE, idx; - int ch, caught_signal = 0; + int ch, caught_signal = 0, echo = 1; struct ul_pty_callbacks *cb; struct scriptlive ss = { .pty = NULL }; pid_t child; static const struct option longopts[] = { { "command", required_argument, 0, 'c' }, + { "echo", required_argument, 0, 'E' }, { "timing", required_argument, 0, 't' }, { "log-timing", required_argument, 0, 'T' }, { "log-in", required_argument, 0, 'I'}, @@ -200,7 +202,7 @@ main(int argc, char *argv[]) replay_init_debug(); timerclear(&maxdelay); - while ((ch = getopt_long(argc, argv, "c:B:I:T:t:d:m:Vh", longopts, NULL)) != -1) { + while ((ch = getopt_long(argc, argv, "c:B:E:I:T:t:d:m:Vh", longopts, NULL)) != -1) { err_exclusive_options(ch, longopts, excl, excl_st); @@ -208,6 +210,16 @@ main(int argc, char *argv[]) case 'c': command = optarg; break; + case 'E': + if (strcmp(optarg, "auto") == 0) + ; /* keep default */ + else if (strcmp(optarg, "never") == 0) + echo = 0; + else if (strcmp(optarg, "always") == 0) + echo = 1; + else + errx(EXIT_FAILURE, _("unssuported echo mode: '%s'"), optarg); + break; case 't': case 'T': log_tm = optarg; @@ -289,7 +301,7 @@ main(int argc, char *argv[]) cb->mainloop = mainloop_cb; /* We keep ECHO flag for compatibility with script(1) */ - ul_pty_slave_echo(ss.pty, 1); + ul_pty_slave_echo(ss.pty, echo); if (ul_pty_setup(ss.pty)) err(EXIT_FAILURE, _("failed to create pseudo-terminal")); -- 2.47.2