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

patch-shebangs: use isScript to safely check for shebang start #47446

Conversation

dtzWill
Copy link
Member

@dtzWill dtzWill commented Sep 27, 2018

Fixes commonly encountered errors about broken pipes or null-bytes in
command-substitution.

Fixing another source of errors in logs produced by our setup-hooks.

Have yet to push through full rebuild but using the modified setuphook
selectively in cases of my own showed the errors no longer occurring
and shebangs were fixed where found.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • 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 nox --run "nox-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)
  • Fits CONTRIBUTING.md.

if [ "$(head -1 "$f" | head -c+2)" != '#!' ]; then
# missing shebang => not a script
continue
if ! isScript "$f"; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also seems faster the the original due less forking.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aszlig any further remarks?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No forking at all actually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I personally find isScript "$f" || continue more readable.

@@ -19,9 +19,8 @@ patchShebangs() {
local newInterpreterLine

find "$dir" -type f -perm -0100 | while read f; do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This surprisingly worked well for us. However I wonder if this should be also just use https://stackoverflow.com/a/1120952

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also go in different pull request also I thought it might be easy enough to change here as well.

@dtzWill
Copy link
Member Author

dtzWill commented Sep 28, 2018

I'm surprised it hasn't been more problematic as well, and I think we do that correctly elsewhere although don't remember where offhand. Makes sense to change that as well so only rebuild all the things once but might end up tackling separately as it's less "obviously correct" ;).

Fixes commonly encountered errors about broken pipes or null-bytes in
command-substitution.
The latter is to avoid warnings printed by find if it doesn't exist.
@dtzWill dtzWill force-pushed the fix/patch-shebangs-head-error-writing-broken-pipe branch from 4aa090c to f7db287 Compare September 28, 2018 16:25
@dtzWill
Copy link
Member Author

dtzWill commented Sep 28, 2018

Nevermind, added all the mentioned fixups :).

@dtzWill dtzWill merged commit 14fee84 into NixOS:staging Sep 28, 2018
@dtzWill dtzWill deleted the fix/patch-shebangs-head-error-writing-broken-pipe branch September 28, 2018 18:24
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

4 participants