diff mbox series

[5/5] Add F_DUPFD_QUERY from Linux 6.10 to bits/fcntl-linux.h

Message ID 20240716173702.1505620-6-adhemerval.zanella@linaro.org
State Accepted
Commit 28f8cee64a3223636d15c78f69432503d8ef1c22
Headers show
Series Updates for Linux 6.10 | expand

Commit Message

Adhemerval Zanella Netto July 16, 2024, 5:08 p.m. UTC
It was added by commit c62b758bae6af16 as a way for userspace to
check if two file descriptors refer o the same struct file.

Checked on aarch64-linux-gnu.
---
 sysdeps/unix/sysv/linux/bits/fcntl-linux.h | 1 +
 1 file changed, 1 insertion(+)

Comments

Cristian Rodríguez July 16, 2024, 5:52 p.m. UTC | #1
On Tue, Jul 16, 2024 at 1:37 PM Adhemerval Zanella <
adhemerval.zanella@linaro.org> wrote:

> It was added by commit c62b758bae6af16 as a way for userspace to
> check if two file descriptors refer o the same struct file.
>

There are a few places where this is needed too right ? I recall some
posix_spawn codepath using numeric comparison for the job..
Adhemerval Zanella Netto July 16, 2024, 6:30 p.m. UTC | #2
On 16/07/24 14:52, Cristian Rodríguez wrote:
> 
> 
> On Tue, Jul 16, 2024 at 1:37 PM Adhemerval Zanella <adhemerval.zanella@linaro.org <mailto:adhemerval.zanella@linaro.org>> wrote:
> 
>     It was added by commit c62b758bae6af16 as a way for userspace to
>     check if two file descriptors refer o the same struct file.
> 
> 
> There are a few places where this is needed too right ? I recall some posix_spawn codepath using numeric comparison for the job..
> 

I am not sure if it applied to posix_spawn_file_actions_adddup2, as per Austin
group issue #411 [1]. My understanding is the file descriptor equality is for
the input argument, since the dup operation will be issue anyway (but I might
be missing something here).

But I think might we have some internal usage where the code check for same 
inode using stat, similar to the systemd example [2] that the kernel commit 
references:

  * get_current_dir_name
  * on ldconfig create_links
  * on getttyname_r fallback.

[1] https://www.austingroupbugs.net/view.php?id=411
[2] https://github.com/systemd/systemd/blob/a4f0e0da3573a10bc5404142be8799418760b1d1/src/basic/fd-util.c#L517
Florian Weimer July 29, 2024, 6:15 p.m. UTC | #3
* Adhemerval Zanella Netto:

> On 16/07/24 14:52, Cristian Rodríguez wrote:
>> 
>> 
>> On Tue, Jul 16, 2024 at 1:37 PM Adhemerval Zanella <adhemerval.zanella@linaro.org <mailto:adhemerval.zanella@linaro.org>> wrote:
>> 
>>     It was added by commit c62b758bae6af16 as a way for userspace to
>>     check if two file descriptors refer o the same struct file.
>> 
>> 
>> There are a few places where this is needed too right ? I recall some posix_spawn codepath using numeric comparison for the job..
>> 
>
> I am not sure if it applied to posix_spawn_file_actions_adddup2, as per Austin
> group issue #411 [1]. My understanding is the file descriptor equality is for
> the input argument, since the dup operation will be issue anyway (but I might
> be missing something here).
>
> But I think might we have some internal usage where the code check for same 
> inode using stat, similar to the systemd example [2] that the kernel commit 
> references:
>
>   * get_current_dir_name
>   * on ldconfig create_links
>   * on getttyname_r fallback.
>
> [1] https://www.austingroupbugs.net/view.php?id=411
> [2] https://github.com/systemd/systemd/blob/a4f0e0da3573a10bc5404142be8799418760b1d1/src/basic/fd-util.c#L517

I thin “struct file” means “file description”.  These checks above need
to check for the same inode.  I started a thread about this today:

  Testing if two open descriptors refer to the same inode
  <https://lore.kernel.org/linux-fsdevel/874j88sn4d.fsf@oldenburg.str.redhat.com/>

Thanks,
Florian
Florian Weimer July 29, 2024, 6:19 p.m. UTC | #4
* Adhemerval Zanella:

> It was added by commit c62b758bae6af16 as a way for userspace to
> check if two file descriptors refer o the same struct file.

Typo: [t]o

Okay with that change.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Florian
diff mbox series

Patch

diff --git a/sysdeps/unix/sysv/linux/bits/fcntl-linux.h b/sysdeps/unix/sysv/linux/bits/fcntl-linux.h
index 628612b885..61c100d984 100644
--- a/sysdeps/unix/sysv/linux/bits/fcntl-linux.h
+++ b/sysdeps/unix/sysv/linux/bits/fcntl-linux.h
@@ -200,6 +200,7 @@ 
 # define F_SETLEASE	1024	/* Set a lease.  */
 # define F_GETLEASE	1025	/* Enquire what lease is active.  */
 # define F_NOTIFY	1026	/* Request notifications on a directory.  */
+# define F_DUPFD_QUERY  1027    /* Compare two file descriptors for sameness.  */
 # define F_SETPIPE_SZ	1031	/* Set pipe page size array.  */
 # define F_GETPIPE_SZ	1032	/* Set pipe page size array.  */
 # define F_ADD_SEALS	1033	/* Add seals to file.  */