[PATCH] options: Check stderr instead of stdout for interactivity

Herbert Xu <[email protected]> Sun, 14 Sep 2025 09:45:22 +0800
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
Steffen Nurpmeso <[email protected]> wrote:
> 
> In an email communication with kre@ on NetBSD's tech-userlevel we
> came over
> 
>  commit a373e69a196cd8d45f2806d805e548fa65a982ba
>  Author:     kre <[email protected]>
>  AuthorDate: 2017-07-24 12:35:37 +0000
>  Commit:     kre <[email protected]>
>  CommitDate: 2017-07-24 12:35:37 +0000
> 
>      PR standards/52406
> 
>      Absent other information, the shell should be interactive if reading
>      from stdin, and stdin and stderr are ttys, not stdin and stdout.
> 
> and i had in mind that dash changed this already (i thought i saw
> a patch flying by on the ML?), but looking at procargs() there is
> 
>        if (iflag == 2 && sflag == 1 && stdin_istty && isatty(1))
>                iflag = 1;
> 
> where that would require
> 
>        if (iflag == 2 && sflag == 1 && stdin_istty && isatty(2))
>                iflag = 1;

Check stderr instead of stdout in procargs for interactivity.

Signed-off-by: Herbert Xu <[email protected]>

diff --git a/src/options.c b/src/options.c
index 3e6c450..c318e0f 100644
--- a/src/options.c
+++ b/src/options.c
@@ -138,7 +138,7 @@ procargs(char **xargv)
 			sh_error("-c requires an argument");
 		sflag = 1;
 	}
-	if (iflag == 2 && sflag == 1 && stdin_istty && isatty(1))
+	if (iflag == 2 && sflag == 1 && stdin_istty && isatty(2))
 		iflag = 1;
 	if (mflag == 2)
 		mflag = iflag;
-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt