From: Daniel Drake <drake@endlessm.com>
To: libc-help@sourceware.org
Cc: shea@shealevy.com, drepper@gmail.com
Subject: posix_spawn and script execution
Date: Tue, 05 Jun 2018 19:05:00 -0000 [thread overview]
Message-ID: <CAD8Lp47_bVtdJ85Bho3L0h=EnzXRgUA8PT3Ka51FfOgXA7yjMw@mail.gmail.com> (raw)
Hi,
The posix_spawn man page says:
>The only difference between posix_spawn() and posix_spawnp() is the
>manner in which they specify the file to be executed by the child
>process. With posix_spawn(), the executable file is specified as a
>pathname (which can be absolute or relative). With posix_spawnp(), the
>executable file is specified as a simple filename; the system searches
>for this file in the list of directories specified by PATH (in the same
>way as for execvp(3)). For the remainder of this page, the discussion
>is phrased in terms of posix_spawn(), with the understanding that
>posix_spawnp() differs only on the point just described.
That seems rather definitive in communicating that there are no other
differences other than the path-searching behavioural aspect.
However, I have found another difference:
posix_spawnp() can execute scripts, by that I mean a text file that
has executable permissions that does not have a shebang. When used in
this way, it will use the shell to execute the script.
You can try this by taking the sample program in the posix_spawn man
page and switching it between posix_spawn/posix_spawnp and launching a
script created with:
echo "/bin/echo hello" > test.sh
chmod a+x test.sh
posix_spawn fails to execute it, but it runs fine with posix_spawnp.
Is this an omission in the man page that should be corrected, to state
that a second difference between posix_spawn and posix_spawnp is that
the spawnp variant can execute scripts, in the same way that exec(3)
documents the exact same behavioural exception for execlp/execvp?
Or is the presence of this behavioural difference a bug in glibc?
Looking at the history, posix_spawn() used to be able to launch
scripts too, but this behaviour was changed here:
https://sourceware.org/bugzilla/show_bug.cgi?id=13134
The resulting commit looks like it tries to make the change both for
posix_spawn and posix_spawnp, in that it creates compat versions of
both functions that set SPAWN_XFLAGS_TRY_SHELL while also omitting
that flag from the "fixed" functions:
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d96de9634a334af16c0ac711074c15ac1762b23c
however ultimately posix_spawnp script execution is still possible
today because the spawnp variant uses __execvpe. Check the source code
for __execvpe and you can clearly see the script exec ENOEXEC
fallback, and I believe that's why posix_spawnp can run scripts.
Clarifications appreciated!
Thanks
Daniel
next reply other threads:[~2018-06-05 19:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-05 19:05 Daniel Drake [this message]
2018-06-06 13:21 ` Adhemerval Zanella
2018-06-06 13:59 ` Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAD8Lp47_bVtdJ85Bho3L0h=EnzXRgUA8PT3Ka51FfOgXA7yjMw@mail.gmail.com' \
--to=drake@endlessm.com \
--cc=drepper@gmail.com \
--cc=libc-help@sourceware.org \
--cc=shea@shealevy.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).