Re: odd script(1) behavior - script bug, man bug, ?

RVP <[email protected]> Wed, 17 Dec 2025 09:11:49 +0000 (UTC)
Newsgroups gmane.os.netbsd.devel.userlevel
Message-ID <[email protected]>
On Tue, 16 Dec 2025, Greg Troxel wrote:

> In running bup regression tests, it basically does
>
>
>  script -q -c "/path/to/bup/under/test some bup args" /dev/null
>
> to ensure that the program is tested with a tty as input, separately
> from just running it.
>
> I have been running  the test suite "< /dev/null > CHECK.foo 2&1" more
> or less.
>
> This results in the top-level script exiting because no characters are
> available on stdin, even though the program is still running.
>

This patch makes script behave like the Linux one (which I think is the less
confusing behaviour):

```
diff -urN a/src/usr.bin/script/script.c b/src/usr.bin/script/script.c
--- a/src/usr.bin/script/script.c	2023-05-09 15:43:39.000000000 +0000
+++ b/src/usr.bin/script/script.c	2025-12-17 09:10:33.002285265 +0000
@@ -82,7 +82,6 @@
  static const char *fname;

  static volatile	sig_atomic_t die = 0;	/* exit if 1 */
-static int	cstat = EXIT_SUCCESS;	/* cmd. exit status */
  static int	eflag;
  static int	isterm;
  static struct	termios tt;
@@ -212,7 +211,7 @@
  			record(fscript, ibuf, cc, 'i');
  		(void)write(master, ibuf, cc);
  	}
-	done(cstat);
+	finish(0);
  }

  /**
@@ -293,7 +292,7 @@
  		if (flush)
  			(void)fflush(fscript);
  	}
-	done(cstat);
+	finish(0);
  }

  static void
@@ -358,7 +357,7 @@
  		if (!quiet)
  			(void)printf("Script done, output file is %s\n", fname);
  	}
-	exit(status);
+	_exit(status);
  }

  static void
```

It also makes the `-e' option work as intended.

-RVP