Skip to content

dejagnu: fix target passing for 'runtest' wrapper#212688

Merged
trofi merged 1 commit intoNixOS:stagingfrom
trofi:dejagnu-fix-argv0
Jan 26, 2023
Merged

dejagnu: fix target passing for 'runtest' wrapper#212688
trofi merged 1 commit intoNixOS:stagingfrom
trofi:dejagnu-fix-argv0

Conversation

@trofi
Copy link
Contributor

@trofi trofi commented Jan 26, 2023

The problem was initially noticed in https://sourceware.org/PR30052#c5 where 'runtest' was passing bogus target name when ran without parameters:

$ ./result/bin/runtest
...
Target is .runtest-wrapped
Host   is x86_64-pc-linux-gnu

Note that runtest switches to non-native mode and uses wrapper name as a target name. Mechanics of it is a bit involved: 'runtest' itself detects targets passing via ${0} parameter:

# somewhere in runtest:
mypath=${0-.}
...
if [ "$target" != runtest ] ; then
    target="--target ${target}"
else
    target=""
fi

which would be fine if we ran 'runtest'.

In nixpkgs runtest is a shell wrapper:

$ cat /<<NIX>>/dejagnu-1.6.3/bin/runtest
#! /<<NIX>>/bash-5.2-p15/bin/bash -e
...
exec -a "$0" "/<<NIX>>/dejagnu-1.6.3/bin/.runtest-wrapped"  "$@"

You would expect that .runtest-wrapped would get $0 as an argv[0] here, but no. If both are bash scripts bash peeks original argv[0] and breaks runtest:

https://lists.gnu.org/archive/html/bug-bash/2023-01/msg00082.html

The workaround here is to drop the wrapper and place expect symlink into a place where dejagnu and runtest expect it to be without a wrapper creation.

Description of changes
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

The problem was initially noticed in https://sourceware.org/PR30052#c5
where 'runtest' was passing bogus target name when ran without
parameters:

    $ ./result/bin/runtest
    ...
    Target is .runtest-wrapped
    Host   is x86_64-pc-linux-gnu

Note that runtest switches to non-native mode and uses wrapper name as a
target name. Mechanics of it is a bit involved: 'runtest' itself detects
targets passing via ${0} parameter:

    # somewhere in runtest:
    mypath=${0-.}
    ...
    if [ "$target" != runtest ] ; then
        target="--target ${target}"
    else
        target=""
    fi

which would be fine if we ran 'runtest'.

In `nixpkgs` `runtest` is a shell wrapper:

    $ cat /<<NIX>>/dejagnu-1.6.3/bin/runtest
    #! /<<NIX>>/bash-5.2-p15/bin/bash -e
    ...
    exec -a "$0" "/<<NIX>>/dejagnu-1.6.3/bin/.runtest-wrapped"  "$@"

You would expect that `.runtest-wrapped` would get `$0` as an `argv[0]`
here, but no. If both are `bash` scripts `bash` peeks original
`argv[0]` and breaks `runtest`:

    https://lists.gnu.org/archive/html/bug-bash/2023-01/msg00082.html

The workaround here is to drop the wrapper and place `expect` symlink
into a place where `dejagnu` and `runtest` expect it to be without a
wrapper creation.
@trofi trofi mentioned this pull request Jan 26, 2023
13 tasks
@ofborg ofborg bot added the 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. label Jan 26, 2023
@ofborg ofborg bot requested a review from vrthra January 26, 2023 01:29
@ofborg ofborg bot added 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Jan 26, 2023
@trofi trofi merged commit c103c51 into NixOS:staging Jan 26, 2023
@trofi trofi deleted the dejagnu-fix-argv0 branch January 26, 2023 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant