script portability

2 views
Skip to first unread message

Greg Troxel

unread,
Nov 25, 2025, 8:52:26 PM (12 days ago) Nov 25
to bup-...@googlegroups.com
I continue to struggle with making bup tests not hang because of the new
"script" usage, and I keep confusing myelf. This note serves to explain
where I am, ask if anyone else is testing on a BSD flavor, and I hope to
force me to be clearer with myself when writing it.

The basic issue is
dev
which tries to invoke script multiple ways as an autoconf-style probe to
decide which form to use.

The arguments that it tries are:
-q: Don't print Script started, Script done.
-e: Exit with the status of shell or command, instead of success.
-c: Execute this command, instead of the shell.

script is not specified by POSIX. The 4.4-Lite2 man page says it was
introduced in 3.0BSD, and the only arguments are -a for append and the
file.

NetBSD 6 documents -q and -c, and this seems to continue to NetBSD 9.
NetBSD 10 documents all 3 flags.

Old OpenBSD is like 4.4-Lite2, and 6.3 adds -c; that continues to 6.9.

FreeBSD 10 has -q, and many others, but not -c -or -e. Only in FreeBSD
13 is -e accepted, but -c is not.

See https://man.bsd.lv/ for historical man pages if you wish :-)


On NetBSD 10, which should be ok with all of this, tests hang with

UID PID PPID CPU PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
12345 1803 1 28859 29 0 17652 1072 parked I+ pts/37 0:00.00 script -qec true /dev/null

and script was started 14 minutes ago. With gdb, that's starting to
look like a script bug (or some deep async-signal-safe fail) that I am
having trouble provoking outside of bup tests.

[Switching to LWP 1803 of process 1803]
0x00007f7f9aa0abba in ___lwp_park60 () from /usr/libexec/ld.elf_so
(gdb) bt
#0 0x00007f7f9aa0abba in ___lwp_park60 () from /usr/libexec/ld.elf_so
#1 0x00007f7f9aa05d45 in _rtld_exclusive_enter () from /usr/libexec/ld.elf_so
#2 0x00007f7f9aa0680d in _rtld_exit () from /usr/libexec/ld.elf_so
#3 0x000079176e95a6c9 in __cxa_finalize () from /usr/lib/libc.so.12
#4 0x000079176e95a3ed in exit () from /usr/lib/libc.so.12
#5 0x00000001cdc0179b in done ()
#6 0x00000001cdc0189a in finish ()
#7 <signal handler called>
#8 0x00007f7f9aa07ff3 in _rtld_symlook_obj () from /usr/libexec/ld.elf_so
#9 0x00007f7f9aa083ea in _rtld_symlook_list () from /usr/libexec/ld.elf_so
#10 0x00007f7f9aa0889f in _rtld_symlook_default () from /usr/libexec/ld.elf_so
#11 0x00007f7f9aa08d4a in _rtld_find_plt_symdef () from /usr/libexec/ld.elf_so
#12 0x00007f7f9aa00bc0 in _rtld_bind () from /usr/libexec/ld.elf_so
#13 0x00007f7f9aa0082d in _rtld_bind_start () from /usr/libexec/ld.elf_so
#14 0x0000000000000246 in ?? ()
#15 0x0000000000002d4f in ?? ()
#16 0x000079176e913b80 in _malloc_prefork () from /usr/lib/libc.so.12
#17 0x00000001cdc0213b in main ()


That leaves three things:
- fix the bug
- ensure that bup avoids it, so people can test anyway
- understand how tests work on FreeBSD, OpenBSD, Dragonfly

Greg Troxel

unread,
Nov 26, 2025, 8:56:00 AM (12 days ago) Nov 26
to bup-...@googlegroups.com
Greg Troxel <g...@lexort.com> writes:

> On NetBSD 10, which should be ok with all of this, tests hang with
>
> UID PID PPID CPU PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
> 12345 1803 1 28859 29 0 17652 1072 parked I+ pts/37 0:00.00 script -qec true /dev/null
>
> and script was started 14 minutes ago. With gdb, that's starting to
> look like a script bug (or some deep async-signal-safe fail) that I am
> having trouble provoking outside of bup tests.

Indeed, this is a bug in NetBSD script, basically:

atexit hooks for terminal restoration
signal handler for SIGCHILD is a done procedure
done procedure calls exit() which invokes atexit hooks
at least one atexit hook calls something which is not async-signal-safe

I'm personally working around this by s/exit/_exit/ in script. Really
fixing it is harder and beyond the scope of bup.

With script fixed, tests run to completion on NetBSD 10. Some had
issues, but I think that's unrelated to script problems, and in any case
will analyze and try to resolve before raising.

Rob Browning

unread,
Nov 26, 2025, 1:23:44 PM (11 days ago) Nov 26
to Greg Troxel, bup-...@googlegroups.com
Greg Troxel <g...@lexort.com> writes:

> I'm personally working around this by s/exit/_exit/ in script. Really
> fixing it is harder and beyond the scope of bup.

Glad you found it. For now I could just change with-tty to exit 2 until
it's fixed there.

> With script fixed, tests run to completion on NetBSD 10. Some had
> issues, but I think that's unrelated to script problems, and in any case
> will analyze and try to resolve before raising.

Thanks again for the testing.
--
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,
Nov 26, 2025, 2:20:25 PM (11 days ago) Nov 26
to Rob Browning, bup-...@googlegroups.com
Rob Browning <r...@defaultvalue.org> writes:

> Greg Troxel <g...@lexort.com> writes:
>
>> I'm personally working around this by s/exit/_exit/ in script. Really
>> fixing it is harder and beyond the scope of bup.
>
> Glad you found it. For now I could just change with-tty to exit 2 until
> it's fixed there.

I think it would be reasonable to basically not try to use script on
NetBSD, sort of if uname matches, just assume not possible.

There's a further issue, which is that the "bsd flavor" invocation seems
to be backwards.

I don't think I've seen a script manpage that takes a command and
doesn't take -c. I have tested this diff on NetBSD 9 only.



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

if script -qec true /dev/null; then
- # linux flavor
+ # Linux flavor (also NetBSD 10+)
script -qec "$(printf ' %q' "$@")" /dev/null
-elif script -q /dev/null true; then
- # bsd flavor
- script -q /dev/null "$@"
+elif script -qc true /dev/null; then
+ # Relatively modern BSD flavor
+ script -q -c "$@" /dev/null
else
rc=0
cmd="$(command -v script)" || rc=$?

Rob Browning

unread,
Nov 26, 2025, 3:57:43 PM (11 days ago) Nov 26
to Greg Troxel, bup-...@googlegroups.com
Greg Troxel <g...@lexort.com> writes:

> I think it would be reasonable to basically not try to use script on
> NetBSD, sort of if uname matches, just assume not possible.

Right, here's what I'd added locally to with-tty (not yet tested):

case "$OSTYPE" in
netbsd) exit 2 ;; # https://gnats.netbsd.org/56254
esac

Similar to other netbsd checks we already have, and we can make it more
discriminating if we like, once the bug's fixed.

> I don't think I've seen a script manpage that takes a command and
> doesn't take -c. I have tested this diff on NetBSD 9 only.

Hmm, I suspect I might have just read this (or maybe I checked in a
FreeBSD vm, not sure): https://man.freebsd.org/cgi/man.cgi?script(1)

Greg Troxel

unread,
Nov 26, 2025, 5:09:39 PM (11 days ago) Nov 26
to Rob Browning, bup-...@googlegroups.com
Rob Browning <r...@defaultvalue.org> writes:

> Greg Troxel <g...@lexort.com> writes:
>
>> I think it would be reasonable to basically not try to use script on
>> NetBSD, sort of if uname matches, just assume not possible.
>
> Right, here's what I'd added locally to with-tty (not yet tested):
>
> case "$OSTYPE" in
> netbsd) exit 2 ;; # https://gnats.netbsd.org/56254
> esac
>
> Similar to other netbsd checks we already have, and we can make it more
> discriminating if we like, once the bug's fixed.

Sure, that sounds good.

>> I don't think I've seen a script manpage that takes a command and
>> doesn't take -c. I have tested this diff on NetBSD 9 only.
>
> Hmm, I suspect I might have just read this (or maybe I checked in a
> FreeBSD vm, not sure): https://man.freebsd.org/cgi/man.cgi?script(1)

Wow, that's unusual. Seems like FreeBDS only, and introduced in 2.2.6
(seems odd to have a synopsis change in a point release). Perhaps
guard that with OSTYPE=freebsd?
Reply all
Reply to author
Forward
0 new messages