Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3: fix impure /bin/sh call in subprocess #95242

Merged
merged 1 commit into from Aug 15, 2020

Conversation

danieldk
Copy link
Contributor

@danieldk danieldk commented Aug 12, 2020

Motivation for this change

I am not sure if we care about this, but the subprocess module relies on the impure /bin/sh symlink. This fails in sandboxes/containers without this symlink present. E.g.:

$ bwrap --ro-bind /nix /nix $(nix-build -A python3 --no-out-link)/bin/python3
>>> import subprocess
>>> subprocess.run("exit 1", shell=True, check=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nix/store/fjgnz0xfl04hsblsi4ym5y5akfh6mlmy-python3-3.8.5/lib/python3.8/subprocess.py", line 489, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/nix/store/fjgnz0xfl04hsblsi4ym5y5akfh6mlmy-python3-3.8.5/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/nix/store/fjgnz0xfl04hsblsi4ym5y5akfh6mlmy-python3-3.8.5/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/bin/sh'

After this change:

$ bwrap --ro-bind /nix /nix $(nix-build -A python3 --no-out-link)/bin/python3
>>> import subprocess
>>> subprocess.run("exit 1", shell=True, check=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nix/store/c9b1hkcsdwvkh8cr7d1wjq16j6vfcpsb-python3-3.8.5/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1.

Found while reviewing #95218.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@Mic92
Copy link
Member

Mic92 commented Aug 13, 2020

Can you rebase this to only include your commit?

@FRidh FRidh changed the base branch from master to staging August 13, 2020 06:53
@danieldk
Copy link
Contributor Author

Can you rebase this to only include your commit?

Whoops, I rebased on staging, but forgot to change the target branch on GitHub. Thanks @FRidh!

@FRidh FRidh merged commit 900b2d5 into NixOS:staging Aug 15, 2020
@danieldk danieldk deleted the subprocess-impure-sh branch August 17, 2020 06:36
@danieldk danieldk restored the subprocess-impure-sh branch August 17, 2020 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants