Skip to contentSkip to conversation

openat2: define _GNU_SOURCE and include <fcntl.h>

PATCH In review Li Wang via ltp 2 participants 11 messages Feb 3 – Feb 5

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 openat2: define _GNU_SOURCE and include <fcntl.h>

On Fedora Rawhide (glibc 2.43+), libc exposes openat2() and struct open_how, so our configure script defines HAVE_OPENAT2 and the fallback definition in lapi/openat2.h gets skipped. But openat20*.c never included <fcntl.h> (and lacked _GNU_SOURCE), so the libc-provided prototype and struct stayed hidden, so compilation failed:

  # uname -r
  6.18.0-65.fc44.x86_64
  # rpm -qf /usr/include/fcntl.h
  glibc-devel-2.43-1.fc44.x86_64
  # nm -D /usr/lib64/libc.so.6 | grep -w openat2
  00000000000eb890 W openat2@@GLIBC_2.43
  # make -C testcase/kernel/syscalls/openat2
  openat201.c:27:62: error: invalid application of ‘sizeof’ to incomplete type ‘struct open_how’
    27 |         {&dir_fd, TEST_FILE, O_RDWR, S_IRWXU, 0, &how, sizeof(*how)},

Define _GNU_SOURCE and include <fcntl.h> in openat2 tests to make the prototype available and fix the build.

---
 testcases/kernel/syscalls/openat2/openat201.c | 3 +++
 testcases/kernel/syscalls/openat2/openat202.c | 3 +++
 testcases/kernel/syscalls/openat2/openat203.c | 3 +++
 3 files changed, 9 insertions(+)
testcases/kernel/syscalls/openat2/openat201.c +3 -0
index ecd63b150..40ac2f6d9 100644
@@ -4,6 +4,9 @@
  *
  * Basic openat2() test.
  */
+#define _GNU_SOURCE
+#include <fcntl.h>
+
 #include "tst_test.h"
 #include "lapi/openat2.h"
 
testcases/kernel/syscalls/openat2/openat202.c +3 -0
index 6d1b5a67c..329c6a4a5 100644
@@ -4,6 +4,9 @@
  *
  * openat2() tests with various resolve flags.
  */
+#define _GNU_SOURCE
+#include <fcntl.h>
+
 #include "tst_test.h"
 #include "lapi/openat2.h"
 
testcases/kernel/syscalls/openat2/openat203.c +3 -0
index 6ac49ef4c..cd0c00d75 100644
@@ -4,6 +4,9 @@
  *
  * Basic openat2() test to check various failures.
  */
+#define _GNU_SOURCE
+#include <fcntl.h>
+
 #include "tst_test.h"
 #include "lapi/openat2.h"
 
Signature · 5 lines
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v2 2/2 newlib_tests: add tst_filesystems01 to .gitignore

---
 lib/newlib_tests/.gitignore | 1 +
 1 file changed, 1 insertion(+)
lib/newlib_tests/.gitignore +1 -0
index a4984d2ec..1586e0ad6 100644
@@ -46,6 +46,7 @@ test_macros03
 test_macros04
 test_macros05
 test_macros06
+tst_filesystems01
 tst_fuzzy_sync01
 tst_fuzzy_sync02
 tst_fuzzy_sync03
Signature · 5 lines
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 2/2
#2 lore raw

Re: [LTP] [PATCH v2 2/2] newlib_tests: add tst_filesystems01 to .gitignore

Hi Li,

obviously correct, thanks!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH v2 2/2] newlib_tests: add tst_filesystems01 to .gitignore

Quoted 4 lines · Petr Vorel

Hi Li,

obviously correct, thanks!

Patchset merged, thanks!

Signature · 6 lines
Regards,
Li Wang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH v2 2/2] newlib_tests: add tst_filesystems01 to .gitignore

Quoted 7 lines · Petr Vorel
Quoted 4 lines

Hi Li,

obviously correct, thanks!

Patchset merged, thanks!

Ah, I should have sent my comments for v1 first, as I meant my RBT just for this patch, now for the first one :).

Anyway, I'll send a patch.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
In reply to Li Wang via ltp

hi Li,

Quoted 34 lines

On Fedora Rawhide (glibc 2.43+), libc exposes openat2() and struct open_how, so our configure script defines HAVE_OPENAT2 and the fallback definition in lapi/openat2.h gets skipped. But openat20*.c never included <fcntl.h> (and lacked _GNU_SOURCE), so the libc-provided prototype and struct stayed hidden, so compilation failed:

  # uname -r
  6.18.0-65.fc44.x86_64
  # rpm -qf /usr/include/fcntl.h
  glibc-devel-2.43-1.fc44.x86_64
  # nm -D /usr/lib64/libc.so.6 | grep -w openat2
  00000000000eb890 W openat2@@GLIBC_2.43
  # make -C testcase/kernel/syscalls/openat2
  openat201.c:27:62: error: invalid application of ‘sizeof’ to incomplete type ‘struct open_how’
    27 |         {&dir_fd, TEST_FILE, O_RDWR, S_IRWXU, 0, &how, sizeof(*how)},

Define _GNU_SOURCE and include <fcntl.h> in openat2 tests to make the prototype available and fix the build.

---
 testcases/kernel/syscalls/openat2/openat201.c | 3 +++
 testcases/kernel/syscalls/openat2/openat202.c | 3 +++
 testcases/kernel/syscalls/openat2/openat203.c | 3 +++
 3 files changed, 9 insertions(+)
testcases/kernel/syscalls/openat2/openat201.c +0 -0
index ecd63b150..40ac2f6d9 100644

testcases/kernel/syscalls/openat2/openat201.c line 7

Quoted 4 lines
testcases/kernel/syscalls/openat2/openat201.c +1 -0
@@ -4,6 +4,9 @@
  *
  * Basic openat2() test.
  */
+#define _GNU_SOURCE

Why _GNU_SOURCE? glibc test tst-openat2.c [1] which includes <fcntl.h>, uses struct open_how and test openat2() does not define it. Neither openat2() nor struct open_how are guarded by #ifdef __USE_GNU.

O_DIRECTORY is guarded by #ifdef __USE_XOPEN2K8 but this should be safe as we compile with -std=gnu99.

I mean it's not a big deal, but if it works without it please remove it.

[1] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/tst-openat2.c
[2] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/bits/openat2.h

testcases/kernel/syscalls/openat2/openat201.c line 8

Quoted 1 line
testcases/kernel/syscalls/openat2/openat201.c +1 -0
+#include <fcntl.h>

Should not we use include lapi/fcntl.h?

testcases/kernel/syscalls/openat2/openat201.c line 11

Quoted 3 lines
testcases/kernel/syscalls/openat2/openat201.c +1 -0
+
 #include "tst_test.h"
 #include "lapi/openat2.h"

lapi/openat2.h uses struct open_how directly, shouldn't be included lapi/fcntl.h there?

Kind regards,
Petr

Quoted 27 lines
testcases/kernel/syscalls/openat2/openat202.c +3 -0
index 6d1b5a67c..329c6a4a5 100644
@@ -4,6 +4,9 @@
  *
  * openat2() tests with various resolve flags.
  */
+#define _GNU_SOURCE
+#include <fcntl.h>
+
 #include "tst_test.h"
 #include "lapi/openat2.h"
 
testcases/kernel/syscalls/openat2/openat203.c +3 -0
index 6ac49ef4c..cd0c00d75 100644
@@ -4,6 +4,9 @@
  *
  * Basic openat2() test to check various failures.
  */
+#define _GNU_SOURCE
+#include <fcntl.h>
+
 #include "tst_test.h"
 #include "lapi/openat2.h"
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw
Quoted 45 lines · Petr Vorel

hi Li,

Quoted 34 lines

On Fedora Rawhide (glibc 2.43+), libc exposes openat2() and struct open_how, so our configure script defines HAVE_OPENAT2 and the fallback definition in lapi/openat2.h gets skipped. But openat20*.c never included <fcntl.h> (and lacked _GNU_SOURCE), so the libc-provided prototype and struct stayed hidden, so compilation failed:

  # uname -r
  6.18.0-65.fc44.x86_64
  # rpm -qf /usr/include/fcntl.h
  glibc-devel-2.43-1.fc44.x86_64
  # nm -D /usr/lib64/libc.so.6 | grep -w openat2
  00000000000eb890 W openat2@@GLIBC_2.43
  # make -C testcase/kernel/syscalls/openat2
  openat201.c:27:62: error: invalid application of ‘sizeof’ to incomplete type ‘struct open_how’
    27 |         {&dir_fd, TEST_FILE, O_RDWR, S_IRWXU, 0, &how, sizeof(*how)},

Define _GNU_SOURCE and include <fcntl.h> in openat2 tests to make the prototype available and fix the build.

---
 testcases/kernel/syscalls/openat2/openat201.c | 3 +++
 testcases/kernel/syscalls/openat2/openat202.c | 3 +++
 testcases/kernel/syscalls/openat2/openat203.c | 3 +++
 3 files changed, 9 insertions(+)
testcases/kernel/syscalls/openat2/openat201.c +0 -0
index ecd63b150..40ac2f6d9 100644

testcases/kernel/syscalls/openat2/openat201.c line 7

Quoted 4 lines
testcases/kernel/syscalls/openat2/openat201.c +1 -0
@@ -4,6 +4,9 @@
  *
  * Basic openat2() test.
  */
+#define _GNU_SOURCE

Why _GNU_SOURCE? glibc test tst-openat2.c [1] which includes <fcntl.h>, uses struct open_how and test openat2() does not define it. Neither openat2() nor struct open_how are guarded by #ifdef __USE_GNU.

Quoted 4 lines

O_DIRECTORY is guarded by #ifdef __USE_XOPEN2K8 but this should be safe as we compile with -std=gnu99.

I mean it's not a big deal, but if it works without it please remove it.

From my test on Fedora-Rawhide, it doesn't work if not define it. Let me double check. Maybe reply to you tomorrow.

Quoted 6 lines

[1] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/tst-openat2.c
[2] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/bits/openat2.h

testcases/kernel/syscalls/openat2/openat201.c line 8

Quoted 1 line
testcases/kernel/syscalls/openat2/openat201.c +1 -0
+#include <fcntl.h>
Quoted 8 lines

Should not we use include lapi/fcntl.h?

testcases/kernel/syscalls/openat2/openat201.c line 11

Quoted 3 lines
testcases/kernel/syscalls/openat2/openat201.c +1 -0
+
 #include "tst_test.h"
 #include "lapi/openat2.h"

lapi/openat2.h uses struct open_how directly, shouldn't be included lapi/fcntl.h there?

From my understand lapi/* are appendix for missing stuff in header file.

Test cases should only include standard header files, and lapi should only be used in case of missing or conflicting header files.

Signature · 6 lines
Regards,
Li Wang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Hi Li,

...

Quoted 4 lines
Quoted 2 lines

lapi/openat2.h uses struct open_how directly, shouldn't be included lapi/fcntl.h there?

From my understand lapi/* are appendix for missing stuff in header file.

Yes, but we agreed in the past, that it's better to include relevant libc/kernel header in the lapi header [1]:

LAPI header should always include original header.

[1] https://github.com/linux-test-project/ltp/blob/master/doc/old/C-Test-API.asciidoc#lapi-headers

I thought we had a discussion about it, but now I see nobody acked the change in ML (cfbc41d775), therefore I somehow pushed this approach without consensus with others. I'm sorry for that, we can revise that. At the moment quite a few lapi headers use this approach (likely majority).

IMHO it's better to include it than expect that all tests which use lapi header will include relevant header *before* (otherwise tests can happily always depend on fallback instead of using a real value from a system header).

It's a minor detail, but being consistent helps for newcomers to understand LTP code.

And *if* we agree on it, it should be now doc/developers/ground_rules.rst.

Also there is a different approach where should be fallbacks. We use some lapi headers (e.g. lapi/openat2.h but there are more) which don't have public equivalent in libc (/usr/include/bits/openat2.h cannot be used directly, but via <fcntl.h>). Therefore I would put content of lapi/openat2.h into lapi/fcntl.h, but that's a minor detail.

Quoted 2 lines

Test cases should only include standard header files, and lapi should only be used in case of missing or conflicting header files.

But lapi/openat2.h also uses struct open_how. I would either include <fcntl.h> in both sources or just in lapi/openat2.h. Having it only in tests looks to me as not ideal.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw
Quoted 15 lines · Petr Vorel

Hi Li,

...

Quoted 4 lines
Quoted 2 lines

lapi/openat2.h uses struct open_how directly, shouldn't be included lapi/fcntl.h there?

From my understand lapi/* are appendix for missing stuff in header file.

Yes, but we agreed in the past, that it's better to include relevant libc/kernel header in the lapi header [1]:

LAPI header should always include original header.

[1] https://github.com/linux-test-project/ltp/blob/master/doc/old/C-Test-API.asciidoc#lapi-headers

Quoted 8 lines

I thought we had a discussion about it, but now I see nobody acked the change in ML (cfbc41d775), therefore I somehow pushed this approach without consensus with others. I'm sorry for that, we can revise that. At the moment quite a few lapi headers use this approach (likely majority).

IMHO it's better to include it than expect that all tests which use lapi header will include relevant header *before* (otherwise tests can happily always depend on fallback instead of using a real value from a system header).

Yes, I generally agree with this, and here is my understand:

1. Testcase should include original <header.h> (but not "lapi/header.h") if *only* need the original <header.h> file.

2. LAPI-header should always include original <header.h>, it handling the missing/conflicting part there.
Thus, we can treat "lapi/header.h" as a patched <header.h> and only use it intead of the original <header.h> in testcase if needed.

3. We avoid including both original <header.h> and "lapi/header.h" in testase at the same time.

Quoted 10 lines

It's a minor detail, but being consistent helps for newcomers to understand LTP code.

And *if* we agree on it, it should be now doc/developers/ground_rules.rst.

Also there is a different approach where should be fallbacks. We use some lapi headers (e.g. lapi/openat2.h but there are more) which don't have public equivalent in libc (/usr/include/bits/openat2.h cannot be used directly, but via <fcntl.h>). Therefore I would put content of lapi/openat2.h into lapi/fcntl.h, but that's a minor detail.

I am ok with it, the advantage merge lapi/openat2.h into lapi/fcntl.h is keep things more centralized.

But also, keep lapi/openat2.h seperated is more modular, and it should contains <fcntl.h> as well.

Quoted 6 lines
Quoted 2 lines

Test cases should only include standard header files, and lapi should only be used in case of missing or conflicting header files.

But lapi/openat2.h also uses struct open_how. I would either include <fcntl.h> in both sources or just in lapi/openat2.h. Having it only in tests looks to me as not ideal.

Right, thanks for bring up this topic.

Signature · 6 lines
Regards,
Li Wang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw
Quoted 21 lines · Petr Vorel
Quoted 19 lines

Hi Li,

...

Quoted 4 lines
Quoted 2 lines

lapi/openat2.h uses struct open_how directly, shouldn't be included lapi/fcntl.h there?

From my understand lapi/* are appendix for missing stuff in header file.

Yes, but we agreed in the past, that it's better to include relevant libc/kernel header in the lapi header [1]:

LAPI header should always include original header.

[1] https://github.com/linux-test-project/ltp/blob/master/doc/old/C-Test-API.asciidoc#lapi-headers

I thought we had a discussion about it, but now I see nobody acked the change in ML (cfbc41d775), therefore I somehow pushed this approach without consensus with others. I'm sorry for that, we can revise that. At the moment quite a few lapi headers use this approach (likely majority).

Quoted 8 lines
Quoted 3 lines

IMHO it's better to include it than expect that all tests which use lapi header will include relevant header *before* (otherwise tests can happily always depend on fallback instead of using a real value from a system header).

Yes, I generally agree with this, and here is my understand:

1. Testcase should include original <header.h> (but not "lapi/header.h") if *only* need the original <header.h> file.

... and don't need any fallback from the lapi header.

Quoted 4 lines

2. LAPI-header should always include original <header.h>, it handling the missing/conflicting part there.
Thus, we can treat "lapi/header.h" as a patched <header.h> and only use it intead of the original <header.h> in testcase if needed.

+1

Quoted 2 lines

3. We avoid including both original <header.h> and "lapi/header.h" in testase at the same time.

+1

Quoted 11 lines
Quoted 10 lines

It's a minor detail, but being consistent helps for newcomers to understand LTP code.

And *if* we agree on it, it should be now doc/developers/ground_rules.rst.

Also there is a different approach where should be fallbacks. We use some lapi headers (e.g. lapi/openat2.h but there are more) which don't have public equivalent in libc (/usr/include/bits/openat2.h cannot be used directly, but via <fcntl.h>). Therefore I would put content of lapi/openat2.h into lapi/fcntl.h, but that's a minor detail.

Quoted 5 lines

I am ok with it, the advantage merge lapi/openat2.h into lapi/fcntl.h is keep things more centralized.

But also, keep lapi/openat2.h seperated is more modular, and it should contains <fcntl.h> as well.

Yeah, I don't have strong opinion about it, both ways would work.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Test cases should only include standard header files, and lapi should only be used in case of missing or conflicting header files.

But lapi/openat2.h also uses struct open_how. I would either include <fcntl.h> in both sources or just in lapi/openat2.h. Having it only in tests looks to me as not ideal.

Right, thanks for bring up this topic.

Thank you for your time. I try to send a patch to add the outcome to doc/developers/ground_rules.rst and wait for ack of others to get broader consensus about it.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw
Quoted 3 lines

Thank you for your time. I try to send a patch to add the outcome to doc/developers/ground_rules.rst and wait for ack of others to get broader consensus about it.

That's awesome.

Once we get the consensus, I think we need do a cleanup work for the whole project to drop <foo.h> from testcase which includes "lapi/foo.h".

And also go through all LAPI headers, to garantee each "lapi/foo.h" includes the original <foo.h>.

Signature · 6 lines
Regards,
Li Wang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp