[git commit] script: make it work even if fd 0 is closed

Denys Vlasenko vda.linux at googlemail.com
Sun Mar 16 11:34:53 UTC 2014


commit: http://git.busybox.net/busybox/commit/?id=438b4ac2860f4aec5b5fb82c47f75a0cb80d9cb4
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Testcase:
script -q -c "echo hey" /dev/null 0>&-

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 libbb/getpty.c      |    2 +-
 util-linux/script.c |    7 +++++++
 2 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/libbb/getpty.c b/libbb/getpty.c
index 435e4d0..391d729 100644
--- a/libbb/getpty.c
+++ b/libbb/getpty.c
@@ -16,7 +16,7 @@ int FAST_FUNC xgetpty(char *line)
 
 #if ENABLE_FEATURE_DEVPTS
 	p = open("/dev/ptmx", O_RDWR);
-	if (p > 0) {
+	if (p >= 0) {
 		grantpt(p); /* chmod+chown corresponding slave pty */
 		unlockpt(p); /* (what does this do?) */
 # ifndef HAVE_PTSNAME_R
diff --git a/util-linux/script.c b/util-linux/script.c
index 8fb991d..abcd73b 100644
--- a/util-linux/script.c
+++ b/util-linux/script.c
@@ -77,8 +77,15 @@ int script_main(int argc UNUSED_PARAM, char **argv)
 	if (!(opt & OPT_q)) {
 		printf("Script started, file is %s\n", fname);
 	}
+
 	shell = get_shell_name();
 
+	/* Some people run "script ... 0>&-".
+	 * Our code assumes that STDIN_FILENO != pty.
+	 * Ensure STDIN_FILENO is not closed:
+	 */
+	bb_sanitize_stdio();
+
 	pty = xgetpty(pty_line);
 
 	/* get current stdin's tty params */


More information about the busybox-cvs mailing list