openat2: define _GNU_SOURCE and include <fcntl.h>
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
@@ -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
@@ -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
@@ -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
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
@@ -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
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
Re: [LTP] [PATCH v2 2/2] newlib_tests: add tst_filesystems01 to .gitignore
Quoted 4 lines · Petr Vorel
Hi Li,
obviously correct, thanks!
Reviewed-by Petr Vorel <[email protected]>
Patchset merged, thanks!
Signature · 6 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
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!
Reviewed-by Petr Vorel <[email protected]>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
hi Li,
Quoted 34 lines
On Fedora Rawhide (glibc 2.43+), libc exposes
openat2()and structopen_how, so our configure script definesHAVE_OPENAT2and the fallback definition inlapi/openat2.hgets 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_SOURCEand include <fcntl.h> in openat2 tests to make the prototype available and fix the build.Signed-off-by Li Wang <[email protected]>--- 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
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@@ -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@@ -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
Quoted 45 lines · Petr Vorel
hi Li,
Quoted 34 lines
On Fedora Rawhide (glibc 2.43+), libc exposes
openat2()and structopen_how, so our configure script definesHAVE_OPENAT2and the fallback definition inlapi/openat2.hgets 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_SOURCEand include <fcntl.h> in openat2 tests to make the prototype available and fix the build.Signed-off-by Li Wang <[email protected]>--- 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
-0testcases/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_SOURCEWhy
_GNU_SOURCE? glibc testtst-openat2.c[1] which includes <fcntl.h>, uses structopen_howand testopenat2()does not define it. Neitheropenat2()nor structopen_howare guarded by #ifdef__USE_GNU.
Quoted 4 lines
O_DIRECTORYis guarded by #ifdef__USE_XOPEN2K8but 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.htestcases/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.huses structopen_howdirectly, shouldn't be includedlapi/fcntl.hthere?
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
Hi Li,
...
Quoted 4 lines
Quoted 2 lines
lapi/openat2.huses structopen_howdirectly, shouldn't be includedlapi/fcntl.hthere?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
Quoted 15 lines · Petr Vorel
Hi Li,
...
Quoted 4 lines
Quoted 2 lines
lapi/openat2.huses structopen_howdirectly, shouldn't be includedlapi/fcntl.hthere?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.hbut there are more) which don't have public equivalent in libc (/usr/include/bits/openat2.hcannot be used directly, but via <fcntl.h>). Therefore I would put content oflapi/openat2.hintolapi/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.halso uses structopen_how. I would either include <fcntl.h> in both sources or just inlapi/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
Quoted 21 lines · Petr Vorel
Quoted 19 lines
Hi Li,
...
Quoted 4 lines
Quoted 2 lines
lapi/openat2.huses structopen_howdirectly, shouldn't be includedlapi/fcntl.hthere?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.hbut there are more) which don't have public equivalent in libc (/usr/include/bits/openat2.hcannot be used directly, but via <fcntl.h>). Therefore I would put content oflapi/openat2.hintolapi/fcntl.h, but that's a minor detail.
Quoted 5 lines
I am ok with it, the advantage merge
lapi/openat2.hintolapi/fcntl.his keep things more centralized.But also, keep
lapi/openat2.hseperated 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.halso uses structopen_how. I would either include <fcntl.h> in both sources or just inlapi/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
Quoted 3 lines
Thank you for your time. I try to send a patch to add the outcome to
doc/developers/ground_rules.rstand 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