diff --git a/bin/stty/stty.1 b/bin/stty/stty.1 --- a/bin/stty/stty.1 +++ b/bin/stty/stty.1 @@ -32,7 +32,7 @@ .\" @(#)stty.1 8.4 (Berkeley) 4/18/94 .\" $FreeBSD$ .\" -.Dd May 24, 2022 +.Dd September 27, 2022 .Dt STTY 1 .Os .Sh NAME @@ -40,7 +40,7 @@ .Nd set the options for a terminal device interface .Sh SYNOPSIS .Nm -.Op Fl a | e | g +.Op Fl a | e | g | i .Op Fl f Ar file .Op Ar arguments .Sh DESCRIPTION @@ -85,6 +85,23 @@ .Nm to restore the current terminal state as per .St -p1003.2 . +.It Fl i +Allow +.Nm +to change terminal settings even when executing in background +process group (see description of the job control in +.Xr termios 4 ) . +.Pp +Normally, such attempt results in kernel sending the +.Va SIGTTOU +signal and stopping the process until its group is returned +to foreground. +Using this option makes +.Nm +ignore +.Va SIGTTOU . +Note that changing terminal settings for running foreground +job that is not prepared for it might cause inconsistencies. .El .Pp The following arguments are available to set the terminal @@ -607,9 +624,10 @@ .St -p1003.2 compatible. The flags -.Fl e -and +.Fl e , .Fl f +and +.Fl i are extensions to the standard. .Sh HISTORY diff --git a/bin/stty/stty.c b/bin/stty/stty.c --- a/bin/stty/stty.c +++ b/bin/stty/stty.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,7 @@ main(int argc, char *argv[]) { struct info i; + struct sigaction sa; enum FMT fmt; int ch; const char *file, *errstr = NULL; @@ -69,8 +71,8 @@ opterr = 0; while (optind < argc && - strspn(argv[optind], "-aefg") == strlen(argv[optind]) && - (ch = getopt(argc, argv, "aef:g")) != -1) + strspn(argv[optind], "-aefgi") == strlen(argv[optind]) && + (ch = getopt(argc, argv, "aef:gi")) != -1) switch(ch) { case 'a': /* undocumented: POSIX compatibility */ fmt = POSIX; @@ -86,6 +88,12 @@ case 'g': fmt = GFLAG; break; + case 'i': + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = SIG_IGN; + if (sigaction(SIGTTOU, &sa, NULL) == -1) + err(1, "sigaction"); + break; case '?': default: goto args; @@ -161,6 +169,6 @@ { (void)fprintf(stderr, - "usage: stty [-a | -e | -g] [-f file] [arguments]\n"); + "usage: stty [-a | -e | -g] [-i] [-f file] [arguments]\n"); exit (1); }