]> git.kaiwu.me - njs.git/commitdiff
Shell: fixed interactive mode detection for piped stdin.
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 13 Feb 2026 05:31:23 +0000 (21:31 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 27 Feb 2026 23:44:30 +0000 (15:44 -0800)
Previously, libedit callback API (rl_callback_read_char) was used for
interactive input processing.  Unlike the blocking readline() API, the
callback interface does not work correctly when stdin is a pipe: input
characters are silently dropped and the line handler is never invoked.

The issue was introduced in 4988565c6ea7 (0.8.0).

The fix is to check isatty(STDIN_FILENO) and fall back to the file
processing mode when stdin is not a terminal.

external/njs_shell.c

index 63f502ab30239fcbadf89803f4cc335b3e5df7b1..b65b98aae73c4f215746faf87b33fe3e5a3236f6 100644 (file)
@@ -479,6 +479,11 @@ main(int argc, char **argv)
         goto done;
     }
 
+    if (opts.interactive && !isatty(STDIN_FILENO)) {
+        opts.interactive = 0;
+        opts.file = (char *) "-";
+    }
+
     if (opts.version != 0) {
         njs_printf("%s\n", NJS_VERSION);
         ret = NJS_OK;