Improve with-tty portability

0 views
Skip to first unread message

Rob Browning

unread,
Dec 23, 2025, 2:14:36 PM (3 days ago) Dec 23
to bup-...@googlegroups.com
Pushed to main.

--
Rob Browning
rlb @defaultvalue.org and @debian.org
GPG as of 2011-07-10 E6A9 DA3C C9FD 1FF8 C676 D2C4 C0F0 39E9 ED1B 597A
GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4

Rob Browning

unread,
Dec 23, 2025, 2:14:37 PM (3 days ago) Dec 23
to bup-...@googlegroups.com, Greg Troxel
From: Greg Troxel <g...@lexort.com>

- Document script(1) invocations on various systems.
- Change script(1) arg order to accomodate a greater variety of
systems.
- On NetBSD, sleep after script(1) invocation because it returns
before the commands have finished, when stdin is /dev/null.

[r...@defaultvalue.org: adjust commit summary]

Signed-off-by: Greg Troxel <g...@lexort.com>
Reviewed-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
Signed-off-by: Rob Browning <r...@defaultvalue.org>
---
dev/with-tty | 39 +++++++++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/dev/with-tty b/dev/with-tty
index 7f3de35f..a715f8a3 100755
--- a/dev/with-tty
+++ b/dev/with-tty
@@ -11,11 +11,36 @@ case "$OSTYPE" in
netbsd) exit 2 ;; # https://gnats.netbsd.org/56254
esac

+# script(1), originating in 3.0BSD, is not specified by POSIX and has
+# varying forms.
+
+# FreeBSD 15: script [-aeFfkqrw] [-t time] [file [command ...]]
+# FreeBSD 14: script [-aeFfkqr] [-t time] [file [command ...]]
+# FreeBSD 13: script [-aefkqr] [-F pipe] [-t time] [file [command ...]]
+# FreeBSD 12: script [-adfkpqr] [-F pipe] [-t time] [file [command ...]]
+# FreeBSD 11: script [-adfkpqr] [-F pipe] [-t time] [file [command ...]]
+# FreeBSD 10: script [-adfkpqr] [-t time] [file [command ...]]
+# FreeBSD 8: script [-akq] [-t time] [file [command ...]]
+# FreeBSD 3.0: script [-a] [-k] [-q] [-t time] [file] [command ...]
+# FreeBSD 1.0: script [-a] [file]
+
+# Linux ?: script [options] [file] [-- command [argument...]]
+# but also "-c, --command command", and -eq
+
+# macos ?: script [-aeFkqr] [-t time] [file [command ...]]
+
+# NetBSD 10: script [-adefpqr] [-c command] [file]
+# NetBSD 6-9: script [-adfpqr] [-c command] [file]
+# NetBSD 5: script [-adpr] [file]
+
if script -qec true /dev/null; then
- # at least linux and netbsd
+ # Linux and NetBSD 10+
script -qec "$(printf ' %q' "$@")" /dev/null
+elif script -q -c true /dev/null; then
+ # NetBSD 6-9
+ script -q -c "$(printf ' %q' "$@")" /dev/null
elif script -q /dev/null true; then
- # at least freebsd
+ # FreeBSD and macOS
script -q /dev/null "$@"
else
rc=0
@@ -27,3 +52,13 @@ else
fi
exit 2
fi
+
+case `uname` in
+ NetBSD)
+ # On NetBSD, the top-level script(1) process exits when read()
+ # reports EOF on stdin; this happens when running tests with
+ # /dev/null as stdin. As a workaround, wait after script, so
+ # that the command will have finished.
+ sleep 5
+ ;;
+esac
--
2.47.3

Rob Browning

unread,
Dec 23, 2025, 2:14:37 PM (3 days ago) Dec 23
to bup-...@googlegroups.com
Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---
dev/with-tty | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/dev/with-tty b/dev/with-tty
index a715f8a3..b263e0f2 100755
--- a/dev/with-tty
+++ b/dev/with-tty
@@ -33,14 +33,21 @@ esac
# NetBSD 6-9: script [-adfpqr] [-c command] [file]
# NetBSD 5: script [-adpr] [file]

+# Try variants; insist on exit with child status/ (-e behavior).
+
if script -qec true /dev/null; then
- # Linux and NetBSD 10+
script -qec "$(printf ' %q' "$@")" /dev/null
elif script -q -c true /dev/null; then
- # NetBSD 6-9
+ if script -q -c false /dev/null; then # -e behavior?
+ printf '%q ignores child exit status\n' "$(command -v script)" 1>&2
+ exit 2
+ fi
script -q -c "$(printf ' %q' "$@")" /dev/null
elif script -q /dev/null true; then
- # FreeBSD and macOS
+ if script -q /dev/null false; then # -e behavior?
+ printf '%q ignores child exit status\n' "$(command -v script)" 1>&2
+ exit 2
+ fi
script -q /dev/null "$@"
else
rc=0
@@ -53,8 +60,8 @@ else
exit 2
fi

-case `uname` in
- NetBSD)
+case "$OSTYPE" in
+ netbsd)
# On NetBSD, the top-level script(1) process exits when read()
# reports EOF on stdin; this happens when running tests with
# /dev/null as stdin. As a workaround, wait after script, so
--
2.47.3

Reply all
Reply to author
Forward
0 new messages