[PATCH] dev: Fixes and workaound for with-tty

1 view
Skip to first unread message

g...@lexort.com

unread,
Dec 16, 2025, 9:14:17 AM (yesterday) Dec 16
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.

Signed-off-by: Greg Troxel <g...@lexort.com>
---
dev/with-tty | 40 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/dev/with-tty b/dev/with-tty
index c65aa1d4..e7616a0b 100755
--- a/dev/with-tty
+++ b/dev/with-tty
@@ -7,11 +7,37 @@ set -ueo pipefail
usage() { echo 'Usage: with-tty command [arg ...]'; }
misuse() { usage 1>&2; exit 2; }

+# 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
- # linux flavor
+ # Linux and NetBSD 10+
script -qec "$(printf ' %q' "$@")" /dev/null
+elif script -q -c true /dev/null; then
+ # NetBSD 6-9
+ ktrace -i -f with-tty.ktrace script -q -c "$(printf ' %q' "$@")" /dev/null
elif script -q /dev/null true; then
- # bsd flavor
+ # FreeBSD and macOS
script -q /dev/null "$@"
else
rc=0
@@ -23,3 +49,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.51.0

Rob Browning

unread,
Dec 16, 2025, 4:18:56 PM (23 hours ago) Dec 16
to g...@lexort.com, bup-...@googlegroups.com, Greg Troxel
g...@lexort.com writes:

> 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.

Do we not need to worry about https://gnats.netbsd.org/56254 anymore,
which I think was causing the tests to hang on affected systems?

Thanks
--
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

Greg Troxel

unread,
Dec 16, 2025, 6:13:44 PM (21 hours ago) Dec 16
to Rob Browning, bup-...@googlegroups.com
Rob Browning <r...@defaultvalue.org> writes:

> g...@lexort.com writes:
>
>> 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.
>
> Do we not need to worry about https://gnats.netbsd.org/56254 anymore,
> which I think was causing the tests to hang on affected systems?

We do still need to worry. But, my changes are orthogonal to the code
you have added in the rewrite branch to disable the use of script on
NetBSD.

However, the right path is to disable it if the version of script has
the bug, my systems have a not-clean-enough-to-commit fix, and there's
no good way to know if the bug is fixed. So I'd comment out the "don't
use script", and then the changes I sent make sense. The first part is
documentation, the second is a bug fix, and the third is a workaround
for either "script has bug if stdin is /dev/null" or "it's an error to
call script with stdin not a terminal", ambiguity not resolved...

Rob Browning

unread,
Dec 16, 2025, 6:24:34 PM (21 hours ago) Dec 16
to Greg Troxel, bup-...@googlegroups.com
Greg Troxel <g...@lexort.com> writes:

> However, the right path is to disable it if the version of script has
> the bug, my systems have a not-clean-enough-to-commit fix, and there's
> no good way to know if the bug is fixed. So I'd comment out the "don't
> use script",

"don't use script"?

Greg Troxel

unread,
Dec 16, 2025, 6:50:41 PM (20 hours ago) Dec 16
to Rob Browning, bup-...@googlegroups.com
Rob Browning <r...@defaultvalue.org> writes:

> Greg Troxel <g...@lexort.com> writes:
>
>> However, the right path is to disable it if the version of script has
>> the bug, my systems have a not-clean-enough-to-commit fix, and there's
>> no good way to know if the bug is fixed. So I'd comment out the "don't
>> use script",
>
> "don't use script"?

In the commit in the rewrite branch, there is in with-tty

if this is netbsd
# script is broken
return 2
fi

and while that's true of releases, it's not true of my systems (well,
not that bug), and thus I would just make a tiny change so that didn't
fire.
Reply all
Reply to author
Forward
0 new messages