public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org,
	Luca Boccassi <luca.boccassi@gmail.com>,
	Philip Withnall <bugzilla@tecnocode.co.uk>
Subject: Re: [PATCH v4 1/3] posix: Add pidfd_spawn and pidfd_spawnp (BZ# 30349)
Date: Mon, 22 May 2023 11:18:08 -0300	[thread overview]
Message-ID: <4b1387c4-6f36-f2b7-167c-97a4fe6cf331@linaro.org> (raw)
In-Reply-To: <87zg5w4piy.fsf@oldenburg3.str.redhat.com>



On 22/05/23 07:41, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> Returning a pidfd allows a process to keep a race-free handle to a child
>> process, otherwise the caller will need to either use pidfd_open (which
>> still might be subject to TOCTOU) or keep using the old racy interface.
>>
>> The implementation makes sure that kernel must support the complete
>> pidfd interface, meaning that waitid (P_PIDFD) should be supported
>> (added on Linux 5.4).  It ensure that non racy workaround is required
>> (such as reading procfs fdinfo pid to use along with old wait interfaces).
>>  If kernel does not have the required support the interface returns ENOSYS.
> 
> “It avoids workarounds with race conditions”?

Ack.

> 
>> These interfaces are similar to the posix_spawn and posix_spawnp, with
>> the only different diferent being it returns a process file descriptor
>> (int) instead of process ID (pid_t).  Their prototypes are:
>>
>>   int pidfd_spawn (int *restrict pidfd,
>>  		   const char *restrict file,
>>   		   const posix_spawn_file_actions_t *restrict facts,
>>   		   const posix_spawnattr_t *restrict attrp,
>>   		   char *const argv[restrict],
>>   		   char *const envp[restrict])
>>
>>   int pidfd_spawnp (int *restrict pidfd,
>>  		    const char *restrict path,
>>   		    const posix_spawn_file_actions_t *restrict facts,
>>   		    const posix_spawnattr_t *restrict attrp,
>>   		    char *const argv[restrict_arr],
>>   		    char *const envp[restrict_arr]);
> 
> Should we return the pid_t value as we..

That's a key point where I was not sure and ended up to omit since the
patchset also adds pidfd_getpid (so if call is successful pidfd_getpid
will get you the pid).

Returning the pid will also deviate the interface for posix_spawnp, which
means that either we will need to add the pid_t as an additional input/output
argument or change the interface to return errors through errno.

> 
>> A new symbol is used instead of a posix_spawn extension to avoid possible
>> issue with language bindings that might track the return argument
>> lifetime.  Although, on Linux pid_t and int are interchangeable, POSIX
>> only state that pid_t should be a signed interger.
>>
>> Both symbols reuse the posix_spawn posix_spawn_file_actions_t and
>> posix_spawnattr_t, to void rehash posix_spawn API or add a new one.
>>  It also mean that both interfaces support the same attribute and
>> file actions, and a new flag or file actions on posix_spawn is also
>> added automatically for pidfd_spawn.
> 
> Same question as with pidfd_fork: how does this interact with SIGCHLD,
> and can the PID be used with waitpid?

It follows posix_spawn semantic to setup SIGCHLD on lower bits of clone
flags.  I think it should be feasible to add an extra posix_spawn flag
to remove it.

> 
>> diff --git a/posix/spawn.h b/posix/spawn.h
>> index 0a6a070523..2e20991627 100644
>> --- a/posix/spawn.h
>> +++ b/posix/spawn.h
>> @@ -229,6 +229,8 @@ posix_spawn_file_actions_addtcsetpgrp_np (posix_spawn_file_actions_t *,
>>  
>>  #endif /* __USE_MISC */
>>  
>> +#include <bits/spawn_ext.h>
>> +
>>  __END_DECLS
> 
> Nested __BEGIN_DECLS.  You should probably move the #include after
> __END_DECLS.

Ack.

> 
>> diff --git a/sysdeps/unix/sysv/linux/clone-pidfd-support.c b/sysdeps/unix/sysv/linux/clone-pidfd-support.c
>> new file mode 100644
>> index 0000000000..4bf2317c17
>> --- /dev/null
>> +++ b/sysdeps/unix/sysv/linux/clone-pidfd-support.c
> 
>> +         Also tThe waitid is a cancellation entrypoint, so issue the syscall
>> +	 directly.  */
> 
> Typo: “tThe”
> 
> Thanks,
> Florian
> 

  parent reply	other threads:[~2023-05-22 14:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17 17:35 [PATCH v4 0/3] Add pidfd_spawn, pidfd_spawnp, pidfd_fork, and pidfd_getpid Adhemerval Zanella
2023-05-17 17:35 ` [PATCH v4 1/3] posix: Add pidfd_spawn and pidfd_spawnp (BZ# 30349) Adhemerval Zanella
2023-05-22 10:41   ` Florian Weimer
2023-05-22 10:46     ` Andreas Schwab
2023-05-22 14:18     ` Adhemerval Zanella Netto [this message]
2023-05-17 17:35 ` [PATCH v4 2/3] posix: Add pidfd_fork Adhemerval Zanella
2023-05-22 10:12   ` Florian Weimer
2023-05-22 12:44     ` Christian Brauner
2023-05-22 14:48     ` Adhemerval Zanella Netto
2023-05-17 17:35 ` [PATCH v4 3/3] linux: Add pidfd_getpid Adhemerval Zanella
2023-05-22 13:00   ` Florian Weimer
2023-05-22 17:13     ` Adhemerval Zanella Netto
2023-05-22 13:53   ` Joe Simmons-Talbott

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=4b1387c4-6f36-f2b7-167c-97a4fe6cf331@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=bugzilla@tecnocode.co.uk \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=luca.boccassi@gmail.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).