-
Notifications
You must be signed in to change notification settings - Fork 1
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
Perl script fails when executed via argv[0] symlink but works when script is passed as argument #10
Comments
Cool use of APPerl! With cosmopolitan binaries, you can pass Does the issue happen if you make copies instead of symlinks? I'm not familiar with sanoid, but maybe it tries to execute another copy of the currently running binary, but resolves the symlink itself and loses info on what binary is executing. Another possibility is it's attempting to run a script with In any case, assuming it's not an APPerl bug, sanoid can be patched to run the subprocesses in a way compatible with APPerl, or if it works with |
Thank you for the Following the code path, I found that Sanoid is using dagolden/Capture-Tiny to capture stderr output by calling In looking at Capture-Tiny, turns out that library does indeed use Do you have any ideas of ways I can workaround this? I really like the elegance of being able to just symlink I also don't quite want to submit a patch to the upstream Sanoid tool just to make it work with my portable binary. I'd like that tool to work as-is in a portable fashion. Although I'm not opposed to monkey patching Sanoid during the APPerl build if necessary to make it work. I'm also wondering if I could somehow leverage the
My idea perhaps is to not use the APPerl I'd really like to get my project to work with the |
APPerl should ignore argv[0] script execution and run Perl if the Perl-Dist-APPerl/share/5.36-cosmo-apperl.patch Lines 23 to 66 in d759d22
The patch to set the environment variable could probably applied to Capture-Tiny or Sanoid as long as it's applied before |
That worked perfectly. I was able to add a one-line patch to the build that added That got me thinking, how is the I would like to do something similar, where I bundle some additional tools in With strace I was able to confirm that perl can stat the file: fstatat(AT_FDCWD, "/zip/bin/pv", [{.st_size=1'177'661, .st_blocks=548'864/512, .st_mode=0100644, .st_dev=0x14ccab, .st_ino=0x18a352c, .st_blksize=65'536}], 0) → 0 ENOENT But can't exec it: execve("/zip/bin/pv") failed -1 ENOENT Is there a special way that other binaries located in the PKZIP need to be executed? Is this even possible to do with APPerl/Cosmopolitan? |
Excellent, I'm glad that works! It would nice to include this by default with APPerl, but it would interfere with running other APPerl executables from APPerl.
An APPerl executable only consists of one executable,
Shelling out to run
Unfortunately, Cosmopolitan doesn't currently support As a workaround, you should be able to copy it to disk and then execute it, to copy it should be something like: use File::Copy 'cp';
cp('/zip/bin/pv', '/tmp'); I'm not sure if the executable bit is preserved by |
That's correct and makes perfect sense. I was getting hung up on the PKZIP content and forgetting that it's still an executable binary that launches Perl.
Of course, makes sense. I again got too lost trying to work in the zip.
I did think I was perhaps a bit too ambitious with my usage of cosmopolitan/APE but that confirms it, I just got a bit too excited with what I wanted to do 😄 Anyways, thanks again for all the help and for the awesome project! |
First of all, thank you for an amazing project. Using APPerl, I was able to build a truly portable binary of a ZFS snapshot management tool called Sanoid, which I have hosted at decoyjoe/sanoid-portable.
However I'm seeing a strange issue when executing the portable binary using the
argv[0]
feature.The binary contains a Perl script at
/zip/bin/sanoid
, so I create a symlink to automatically execute that script viaargv[0]
:ln -s sanoid-portable sanoid
When I execute the binary using the symlink, it fails with an error related to launching subprocesses:
If I rename the binary back to
perl.com
and execute the script by passing it as an argument to Perl, it works fine:Is this behavior a bug in the
argv[0]
functionality, or am I using APPerl (or Perl itself) incorrectly?I'm not very familiar with Perl, so it's possible I'm misunderstanding something fundamental. Any guidance or insights would be greatly appreciated.
The text was updated successfully, but these errors were encountered: