From: Bruno Haible <bruno@clisp.org>
To: cygwin@cygwin.com
Subject: Re: posix_spawn_file_actions_add[f]chdir_np
Date: Wed, 19 Apr 2023 13:24:07 +0200 [thread overview]
Message-ID: <1962645.3CdzvNlvnA@nimes> (raw)
In-Reply-To: <ZD+lJeaXDZ8V4WWk@calimero.vinschen.de>
Hi Corinna,
> Actually I had some spare time yesterday so I came up with an
> implementation of posix_spawn_file_actions_addchdir_np and
> posix_spawn_file_actions_addfchdir_np. It's pretty straightforward:
>
> https://cygwin.com/cgit/newlib-cygwin/commit/?id=7e03fc35f528
Yes, it's pretty straightforward on Unix-like platforms.
Note that there is a small inconsistency between implementations:
The manual page
https://man.freebsd.org/cgi/man.cgi?query=posix_spawn_file_actions_addfchdir_np&apropos=0&sektion=3&manpath=FreeBSD+13.2-RELEASE+and+Ports&arch=default&format=html
mentions that when the dirfd argument is negative, the
posix_spawn_file_actions_addfchdir function should fail with error EBADF.
musl libc, FreeBSD, macOS do this; glibc doesn't. Test program attached below.
Confirmed by looking at the source code:
- musl libc:
if (fd < 0) return EBADF;
- FreeBSD:
if (fildes < 0)
return (EBADF);
> You can install the just building test release
> cygwin-3.5.0-0.287.g53f7fb20a064 via our installer, if you'd
> like to test it.
>
> Actually... do you have a testcase readily available to share with us?
Indeed, I'm not likely to install test releases. (Due to the way I work
with my Windows VM, it's a bit clumsy to create a snapshot.) It's easier
for me to provide you a test case, with the unit tests from Gnulib.
I ran the command
./gnulib-tool --create-testdir --dir=../testdir-posix-spawn --single-configure \
posix_spawn \
posix_spawnattr_destroy \
posix_spawnattr_getflags \
posix_spawnattr_getpgroup \
posix_spawnattr_getschedparam \
posix_spawnattr_getschedpolicy \
posix_spawnattr_getsigdefault \
posix_spawnattr_getsigmask \
posix_spawnattr_init \
posix_spawnattr_setflags \
posix_spawnattr_setpgroup \
posix_spawnattr_setschedparam \
posix_spawnattr_setschedpolicy \
posix_spawnattr_setsigdefault \
posix_spawnattr_setsigmask \
posix_spawn_file_actions_addclose \
posix_spawn_file_actions_adddup2 \
posix_spawn_file_actions_addopen \
posix_spawn_file_actions_addchdir \
posix_spawn_file_actions_addfchdir \
posix_spawn_file_actions_destroy \
posix_spawn_file_actions_init \
posix_spawnp
You can download the resulting tarball from
https://haible.de/bruno/gnu/testdir-posix-spawn.tar.gz .
When configuring it, set the environment variable
gl_cv_func_posix_spawnp_secure_exec=yes . This will prevent the
autoconfiguration from attempting to override the entire posix_spawn facility:
$ env gl_cv_func_posix_spawnp_secure_exec=yes ./configure
Verify through
$ grep REPLACE_POSIX_SPAWN config.status
that the values of REPLACE_POSIX_SPAWN and REPLACE_POSIX_SPAWNP are 0;
if they are 1, the output of 'configure' should reveal why.
Then build it:
$ make
Verify through
$ ls -l gllib/*.o
that no posix_spawn_*.o object file was built.
Then run
$ make check
and it will run the unit tests against the Cygwin libc. It's likely
that you will see 1 test failure (test-posix_spawnp-script); but
other than that, there ought to be no test failures.
Bruno
================ Test program for EBADF check ================
#include <spawn.h>
int
main (void)
{
posix_spawn_file_actions_t actions;
if (posix_spawn_file_actions_init (&actions) != 0)
return 1;
if (posix_spawn_file_actions_addfchdir_np (&actions, -3) != 0)
return 2;
else
return 3;
}
next prev parent reply other threads:[~2023-04-19 11:24 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-16 11:46 posix_spawn facility Bruno Haible
2023-04-17 9:18 ` Corinna Vinschen
2023-04-17 18:44 ` Bruno Haible
2023-04-18 9:25 ` Corinna Vinschen
2023-04-18 20:49 ` Eric Blake
2023-04-18 21:00 ` Corinna Vinschen
2023-04-18 22:10 ` Bruno Haible
2023-04-19 2:39 ` Eric Blake
2023-04-19 8:19 ` Corinna Vinschen
2023-04-19 11:56 ` Bruno Haible
2023-04-20 6:52 ` Csaba Raduly
2023-07-31 18:58 ` Eric Blake
2023-07-31 19:12 ` Corinna Vinschen
2023-04-19 8:24 ` Corinna Vinschen
2023-04-19 11:24 ` Bruno Haible [this message]
2023-04-19 15:05 ` posix_spawn_file_actions_add[f]chdir_np Corinna Vinschen
2023-04-19 19:13 ` posix_spawn_file_actions_add[f]chdir_np Corinna Vinschen
2023-04-19 21:33 ` posix_spawn_file_actions_add[f]chdir_np Eliot Moss
2023-04-20 10:27 ` posix_spawn_file_actions_add[f]chdir_np Bruno Haible
2023-04-19 10:48 ` posix_spawn facility Bruno Haible
2023-04-20 7:14 ` gs-cygwin.com
2023-04-20 8:35 ` Corinna Vinschen
2023-04-20 10:18 ` Bruno Haible
2023-04-20 14:21 ` Corinna Vinschen
2023-04-20 14:40 ` Corinna Vinschen
2023-04-20 14:58 ` Bruno Haible
2023-04-20 15:40 ` Corinna Vinschen
2023-04-20 18:46 ` gs-cygwin.com
2023-04-20 18:40 ` gs-cygwin.com
2023-04-20 19:31 ` Bruno Haible
2023-04-20 20:00 ` gs-cygwin.com
2023-05-10 9:15 ` gs-cygwin.com
2023-04-20 18:04 ` gs-cygwin.com
2023-05-10 8:59 ` gs-cygwin.com
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=1962645.3CdzvNlvnA@nimes \
--to=bruno@clisp.org \
--cc=cygwin@cygwin.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).