summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2016-01-04 12:13:40 +0000
committerPádraig Brady <P@draigBrady.com>2016-01-04 23:45:19 +0000
commit5171befcb122b12677f60715603be091625a9e08 (patch)
tree6f1dd7bdfb491ea7037204227804a2ed6c1f3df3 /src
parentc6be0b39437890876692606c233b47a1751b40e9 (diff)
downloadcoreutils-5171befcb122b12677f60715603be091625a9e08.tar.xz
stty: support -I, --immediate to not wait for pending transmission
In some cases an initial drain may block indefinitely as discussed at: http://lists.gnu.org/archive/html/coreutils/2016-01/msg00007.html * src/stty.c (main): Use TCSANOW rather than TCSADRAIN if -I specified. (usage): Document the new option. * doc/coreutils.texi (stty invocation): Likewise. * tests/misc/stty.sh: Ensure -I is supported. * NEWS: Mention the new feature.
Diffstat (limited to 'src')
-rw-r--r--src/stty.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/stty.c b/src/stty.c
index 37fbb25be..93f36de35 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -469,6 +469,7 @@ static struct option const longopts[] =
{"all", no_argument, NULL, 'a'},
{"save", no_argument, NULL, 'g'},
{"file", required_argument, NULL, 'F'},
+ {"immediate", no_argument, NULL, 'I'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
@@ -522,7 +523,7 @@ usage (int status)
else
{
printf (_("\
-Usage: %s [-F DEVICE | --file=DEVICE] [SETTING]...\n\
+Usage: %s [-F DEVICE | --file=DEVICE] [-I] [SETTING]...\n\
or: %s [-F DEVICE | --file=DEVICE] [-a|--all]\n\
or: %s [-F DEVICE | --file=DEVICE] [-g|--save]\n\
"),
@@ -538,6 +539,9 @@ Print or change terminal characteristics.\n\
-g, --save print all current settings in a stty-readable form\n\
-F, --file=DEVICE open and use the specified DEVICE instead of stdin\n\
"), stdout);
+ fputs (_("\
+ -I, --immediate apply setting without waiting for pending transmission\n\
+"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
fputs (_("\
@@ -1080,6 +1084,7 @@ main (int argc, char **argv)
bool noargs = true;
char *file_name = NULL;
const char *device_name;
+ int tcsetattr_options = TCSADRAIN;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -1103,7 +1108,7 @@ main (int argc, char **argv)
stty parses options, be sure it still works with combinations of
short and long options, --, POSIXLY_CORRECT, etc. */
- while ((optc = getopt_long (argc - argi, argv + argi, "-agF:",
+ while ((optc = getopt_long (argc - argi, argv + argi, "-agF:I",
longopts, NULL))
!= -1)
{
@@ -1125,6 +1130,10 @@ main (int argc, char **argv)
file_name = optarg;
break;
+ case 'I':
+ tcsetattr_options = TCSANOW;
+ break;
+
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -1361,7 +1370,7 @@ main (int argc, char **argv)
spurious difference in an uninitialized portion of the structure. */
static struct termios new_mode;
- if (tcsetattr (STDIN_FILENO, TCSADRAIN, &mode))
+ if (tcsetattr (STDIN_FILENO, tcsetattr_options, &mode))
error (EXIT_FAILURE, errno, "%s", quotef (device_name));
/* POSIX (according to Zlotnick's book) tcsetattr returns zero if