* [PATCH v2 2/5] tools/nolibc: always use openat(2) instead of open(2)
2025-03-04 7:58 [PATCH v2 1/5] tools/nolibc: add support for openat(2) Louis Taylor
@ 2025-03-04 7:58 ` Louis Taylor
2025-03-06 16:56 ` Thomas Weißschuh
2025-03-04 7:58 ` [PATCH v2 3/5] tools/nolibc: process open() vararg as mode_t Louis Taylor
` (4 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Louis Taylor @ 2025-03-04 7:58 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh; +Cc: Louis Taylor, linux-kernel
All architectures support openat, so we don't need to make its use
conditional.
Signed-off-by: Louis Taylor <louis@kragniz.eu>
---
tools/include/nolibc/sys.h | 6 ------
1 file changed, 6 deletions(-)
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 3cd938f9abda..a8dca5ac6542 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -798,13 +798,7 @@ int openat(int dirfd, const char *path, int flags, ...)
static __attribute__((unused))
int sys_open(const char *path, int flags, mode_t mode)
{
-#ifdef __NR_openat
return my_syscall4(__NR_openat, AT_FDCWD, path, flags, mode);
-#elif defined(__NR_open)
- return my_syscall3(__NR_open, path, flags, mode);
-#else
- return __nolibc_enosys(__func__, path, flags, mode);
-#endif
}
static __attribute__((unused))
--
2.45.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v2 2/5] tools/nolibc: always use openat(2) instead of open(2)
2025-03-04 7:58 ` [PATCH v2 2/5] tools/nolibc: always use openat(2) instead of open(2) Louis Taylor
@ 2025-03-06 16:56 ` Thomas Weißschuh
0 siblings, 0 replies; 15+ messages in thread
From: Thomas Weißschuh @ 2025-03-06 16:56 UTC (permalink / raw)
To: Louis Taylor; +Cc: Willy Tarreau, linux-kernel
On 2025-03-04 07:58:16+0000, Louis Taylor wrote:
> All architectures support openat, so we don't need to make its use
> conditional.
>
> Signed-off-by: Louis Taylor <louis@kragniz.eu>
> ---
> tools/include/nolibc/sys.h | 6 ------
> 1 file changed, 6 deletions(-)
>
> diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
> index 3cd938f9abda..a8dca5ac6542 100644
> --- a/tools/include/nolibc/sys.h
> +++ b/tools/include/nolibc/sys.h
> @@ -798,13 +798,7 @@ int openat(int dirfd, const char *path, int flags, ...)
> static __attribute__((unused))
> int sys_open(const char *path, int flags, mode_t mode)
> {
> -#ifdef __NR_openat
> return my_syscall4(__NR_openat, AT_FDCWD, path, flags, mode);
> -#elif defined(__NR_open)
> - return my_syscall3(__NR_open, path, flags, mode);
> -#else
> - return __nolibc_enosys(__func__, path, flags, mode);
> -#endif
Linus at some point was unhappy with usage of the *at() system calls
over the regular ones for perfomance reasons.
But that probably doesn't matter for nolibc and we are preferring
openat() anyways.
So:
Acked-by: Thomas Weißschuh <linux@weissschuh.net>
> }
>
> static __attribute__((unused))
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 3/5] tools/nolibc: process open() vararg as mode_t
2025-03-04 7:58 [PATCH v2 1/5] tools/nolibc: add support for openat(2) Louis Taylor
2025-03-04 7:58 ` [PATCH v2 2/5] tools/nolibc: always use openat(2) instead of open(2) Louis Taylor
@ 2025-03-04 7:58 ` Louis Taylor
2025-03-06 16:56 ` Thomas Weißschuh
2025-03-04 7:58 ` [PATCH v2 4/5] tools/nolibc: drop outdated example from overview comment Louis Taylor
` (3 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Louis Taylor @ 2025-03-04 7:58 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh; +Cc: Louis Taylor, linux-kernel
openat() uses mode_t for this, so also update open() to be consistent.
Signed-off-by: Louis Taylor <louis@kragniz.eu>
---
tools/include/nolibc/sys.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index a8dca5ac6542..5d8adc778575 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -810,7 +810,7 @@ int open(const char *path, int flags, ...)
va_list args;
va_start(args, flags);
- mode = va_arg(args, int);
+ mode = va_arg(args, mode_t);
va_end(args);
}
--
2.45.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v2 3/5] tools/nolibc: process open() vararg as mode_t
2025-03-04 7:58 ` [PATCH v2 3/5] tools/nolibc: process open() vararg as mode_t Louis Taylor
@ 2025-03-06 16:56 ` Thomas Weißschuh
0 siblings, 0 replies; 15+ messages in thread
From: Thomas Weißschuh @ 2025-03-06 16:56 UTC (permalink / raw)
To: Louis Taylor; +Cc: Willy Tarreau, linux-kernel
On 2025-03-04 07:58:17+0000, Louis Taylor wrote:
> openat() uses mode_t for this, so also update open() to be consistent.
>
> Signed-off-by: Louis Taylor <louis@kragniz.eu>
Acked-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> tools/include/nolibc/sys.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
> index a8dca5ac6542..5d8adc778575 100644
> --- a/tools/include/nolibc/sys.h
> +++ b/tools/include/nolibc/sys.h
> @@ -810,7 +810,7 @@ int open(const char *path, int flags, ...)
> va_list args;
>
> va_start(args, flags);
> - mode = va_arg(args, int);
> + mode = va_arg(args, mode_t);
> va_end(args);
> }
>
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 4/5] tools/nolibc: drop outdated example from overview comment
2025-03-04 7:58 [PATCH v2 1/5] tools/nolibc: add support for openat(2) Louis Taylor
2025-03-04 7:58 ` [PATCH v2 2/5] tools/nolibc: always use openat(2) instead of open(2) Louis Taylor
2025-03-04 7:58 ` [PATCH v2 3/5] tools/nolibc: process open() vararg as mode_t Louis Taylor
@ 2025-03-04 7:58 ` Louis Taylor
2025-03-06 16:58 ` Thomas Weißschuh
2025-03-04 7:58 ` [PATCH v2 5/5] tools/nolibc: mark more test functions as static Louis Taylor
` (2 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Louis Taylor @ 2025-03-04 7:58 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh; +Cc: Louis Taylor, linux-kernel
This behaviour was changed in commit a7604ba149e7 ("tools/nolibc/sys:
make open() take a vararg on the 3rd argument").
Signed-off-by: Louis Taylor <louis@kragniz.eu>
---
tools/include/nolibc/nolibc.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index 05d92afedb72..70872401aca8 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -31,8 +31,7 @@
* - The third level is the libc call definition. It exposes the lower raw
* sys_<name>() calls in a way that looks like what a libc usually does,
* takes care of specific input values, and of setting errno upon error.
- * There can be minor variations compared to standard libc calls. For
- * example the open() call always takes 3 args here.
+ * There can be minor variations compared to standard libc calls.
*
* The errno variable is declared static and unused. This way it can be
* optimized away if not used. However this means that a program made of
--
2.45.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v2 4/5] tools/nolibc: drop outdated example from overview comment
2025-03-04 7:58 ` [PATCH v2 4/5] tools/nolibc: drop outdated example from overview comment Louis Taylor
@ 2025-03-06 16:58 ` Thomas Weißschuh
0 siblings, 0 replies; 15+ messages in thread
From: Thomas Weißschuh @ 2025-03-06 16:58 UTC (permalink / raw)
To: Louis Taylor; +Cc: Willy Tarreau, linux-kernel
On 2025-03-04 07:58:18+0000, Louis Taylor wrote:
> This behaviour was changed in commit a7604ba149e7 ("tools/nolibc/sys:
> make open() take a vararg on the 3rd argument").
>
> Signed-off-by: Louis Taylor <louis@kragniz.eu>
Acked-by : Thomas Weißschuh <linux@weissschuh.net>
> ---
> tools/include/nolibc/nolibc.h | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
> index 05d92afedb72..70872401aca8 100644
> --- a/tools/include/nolibc/nolibc.h
> +++ b/tools/include/nolibc/nolibc.h
> @@ -31,8 +31,7 @@
> * - The third level is the libc call definition. It exposes the lower raw
> * sys_<name>() calls in a way that looks like what a libc usually does,
> * takes care of specific input values, and of setting errno upon error.
> - * There can be minor variations compared to standard libc calls. For
> - * example the open() call always takes 3 args here.
> + * There can be minor variations compared to standard libc calls.
> *
> * The errno variable is declared static and unused. This way it can be
> * optimized away if not used. However this means that a program made of
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 5/5] tools/nolibc: mark more test functions as static
2025-03-04 7:58 [PATCH v2 1/5] tools/nolibc: add support for openat(2) Louis Taylor
` (2 preceding siblings ...)
2025-03-04 7:58 ` [PATCH v2 4/5] tools/nolibc: drop outdated example from overview comment Louis Taylor
@ 2025-03-04 7:58 ` Louis Taylor
2025-03-06 17:00 ` Thomas Weißschuh
2025-03-04 8:11 ` [PATCH v2 1/5] tools/nolibc: add support for openat(2) Willy Tarreau
2025-03-06 17:10 ` Thomas Weißschuh
5 siblings, 1 reply; 15+ messages in thread
From: Louis Taylor @ 2025-03-04 7:58 UTC (permalink / raw)
To: Willy Tarreau, Thomas Weißschuh, Shuah Khan
Cc: Louis Taylor, linux-kselftest, linux-kernel
It was mentioned that a new test_ function should be static, so go back
over existing functions and mark those static as well.
Signed-off-by: Louis Taylor <louis@kragniz.eu>
---
tools/testing/selftests/nolibc/nolibc-test.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 2a1629938dd6..b5464ca8d050 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -807,7 +807,7 @@ static int test_dirent(void)
return 0;
}
-int test_getpagesize(void)
+static int test_getpagesize(void)
{
int x = getpagesize();
int c;
@@ -836,7 +836,7 @@ int test_getpagesize(void)
return !c;
}
-int test_fork(void)
+static int test_fork(void)
{
int status;
pid_t pid;
@@ -861,7 +861,7 @@ int test_fork(void)
}
}
-int test_stat_timestamps(void)
+static int test_stat_timestamps(void)
{
struct stat st;
@@ -883,7 +883,7 @@ int test_stat_timestamps(void)
return 0;
}
-int test_uname(void)
+static int test_uname(void)
{
struct utsname buf;
char osrelease[sizeof(buf.release)];
@@ -922,7 +922,7 @@ int test_uname(void)
return 0;
}
-int test_mmap_munmap(void)
+static int test_mmap_munmap(void)
{
int ret, fd, i, page_size;
void *mem;
@@ -980,7 +980,7 @@ int test_mmap_munmap(void)
return !!ret;
}
-int test_pipe(void)
+static int test_pipe(void)
{
const char *const msg = "hello, nolibc";
int pipefd[2];
@@ -1001,7 +1001,7 @@ int test_pipe(void)
return !!memcmp(buf, msg, len);
}
-int test_rlimit(void)
+static int test_rlimit(void)
{
struct rlimit rlim = {
.rlim_cur = 1 << 20,
--
2.45.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v2 5/5] tools/nolibc: mark more test functions as static
2025-03-04 7:58 ` [PATCH v2 5/5] tools/nolibc: mark more test functions as static Louis Taylor
@ 2025-03-06 17:00 ` Thomas Weißschuh
2025-03-06 17:06 ` Willy Tarreau
0 siblings, 1 reply; 15+ messages in thread
From: Thomas Weißschuh @ 2025-03-06 17:00 UTC (permalink / raw)
To: Louis Taylor; +Cc: Willy Tarreau, Shuah Khan, linux-kselftest, linux-kernel
On 2025-03-04 07:58:19+0000, Louis Taylor wrote:
> It was mentioned that a new test_ function should be static, so go back
> over existing functions and mark those static as well.
Actually Willy wants these non-static for debugging purposes.
I can't seem to get that into my head -.-
Let's drop this one.
> Signed-off-by: Louis Taylor <louis@kragniz.eu>
> ---
> tools/testing/selftests/nolibc/nolibc-test.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index 2a1629938dd6..b5464ca8d050 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -807,7 +807,7 @@ static int test_dirent(void)
> return 0;
> }
>
> -int test_getpagesize(void)
> +static int test_getpagesize(void)
> {
> int x = getpagesize();
> int c;
> @@ -836,7 +836,7 @@ int test_getpagesize(void)
> return !c;
> }
>
> -int test_fork(void)
> +static int test_fork(void)
> {
> int status;
> pid_t pid;
> @@ -861,7 +861,7 @@ int test_fork(void)
> }
> }
>
> -int test_stat_timestamps(void)
> +static int test_stat_timestamps(void)
> {
> struct stat st;
>
> @@ -883,7 +883,7 @@ int test_stat_timestamps(void)
> return 0;
> }
>
> -int test_uname(void)
> +static int test_uname(void)
> {
> struct utsname buf;
> char osrelease[sizeof(buf.release)];
> @@ -922,7 +922,7 @@ int test_uname(void)
> return 0;
> }
>
> -int test_mmap_munmap(void)
> +static int test_mmap_munmap(void)
> {
> int ret, fd, i, page_size;
> void *mem;
> @@ -980,7 +980,7 @@ int test_mmap_munmap(void)
> return !!ret;
> }
>
> -int test_pipe(void)
> +static int test_pipe(void)
> {
> const char *const msg = "hello, nolibc";
> int pipefd[2];
> @@ -1001,7 +1001,7 @@ int test_pipe(void)
> return !!memcmp(buf, msg, len);
> }
>
> -int test_rlimit(void)
> +static int test_rlimit(void)
> {
> struct rlimit rlim = {
> .rlim_cur = 1 << 20,
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v2 5/5] tools/nolibc: mark more test functions as static
2025-03-06 17:00 ` Thomas Weißschuh
@ 2025-03-06 17:06 ` Willy Tarreau
0 siblings, 0 replies; 15+ messages in thread
From: Willy Tarreau @ 2025-03-06 17:06 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Louis Taylor, Shuah Khan, linux-kselftest, linux-kernel
On Thu, Mar 06, 2025 at 06:00:17PM +0100, Thomas Weißschuh wrote:
> On 2025-03-04 07:58:19+0000, Louis Taylor wrote:
> > It was mentioned that a new test_ function should be static, so go back
> > over existing functions and mark those static as well.
>
> Actually Willy wants these non-static for debugging purposes.
> I can't seem to get that into my head -.-
> Let's drop this one.
I don't remember but it was probably to be able to break into them with
gdb and/or to check the disassembled code when in doubt about anything.
Willy
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/5] tools/nolibc: add support for openat(2)
2025-03-04 7:58 [PATCH v2 1/5] tools/nolibc: add support for openat(2) Louis Taylor
` (3 preceding siblings ...)
2025-03-04 7:58 ` [PATCH v2 5/5] tools/nolibc: mark more test functions as static Louis Taylor
@ 2025-03-04 8:11 ` Willy Tarreau
2025-03-06 17:22 ` Thomas Weißschuh
2025-03-06 17:10 ` Thomas Weißschuh
5 siblings, 1 reply; 15+ messages in thread
From: Willy Tarreau @ 2025-03-04 8:11 UTC (permalink / raw)
To: Louis Taylor
Cc: Thomas Weißschuh, Shuah Khan, linux-kernel, linux-kselftest
Hi Louis,
On Tue, Mar 04, 2025 at 07:58:15AM +0000, Louis Taylor wrote:
> openat is useful to avoid needing to construct relative paths, so expose
> a wrapper for using it directly.
Reviewed the whole series, no comments from me. Let's wait for Thomas
to double-check but for me it's OK:
Acked-by: Willy Tarreau <w@1wt.eu>
Thomas, since you already have plenty of changes in queue, do you mind
if I let you pick this series ?
Thanks!
Willy
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v2 1/5] tools/nolibc: add support for openat(2)
2025-03-04 8:11 ` [PATCH v2 1/5] tools/nolibc: add support for openat(2) Willy Tarreau
@ 2025-03-06 17:22 ` Thomas Weißschuh
2025-03-06 17:42 ` Willy Tarreau
0 siblings, 1 reply; 15+ messages in thread
From: Thomas Weißschuh @ 2025-03-06 17:22 UTC (permalink / raw)
To: Willy Tarreau; +Cc: Louis Taylor, Shuah Khan, linux-kernel, linux-kselftest
Hi Willy,
On 2025-03-04 09:11:16+0100, Willy Tarreau wrote:
> On Tue, Mar 04, 2025 at 07:58:15AM +0000, Louis Taylor wrote:
> > openat is useful to avoid needing to construct relative paths, so expose
> > a wrapper for using it directly.
>
> Reviewed the whole series, no comments from me. Let's wait for Thomas
> to double-check but for me it's OK:
>
> Acked-by: Willy Tarreau <w@1wt.eu>
Fairly happy with it, only some tiny nitpicks.
> Thomas, since you already have plenty of changes in queue, do you mind
> if I let you pick this series ?
Sure.
Also we need to send a PR to Shuah soon.
I have some patches I want to get into it.
In case you missed it:
https://lore.kernel.org/lkml/20250305-nolibc-asm-headers-v1-1-f2053def2ee7@linutronix.de/
Also the removal of the constructor order validation.
Will you send a patch or should I?
Thomas
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/5] tools/nolibc: add support for openat(2)
2025-03-06 17:22 ` Thomas Weißschuh
@ 2025-03-06 17:42 ` Willy Tarreau
0 siblings, 0 replies; 15+ messages in thread
From: Willy Tarreau @ 2025-03-06 17:42 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Louis Taylor, Shuah Khan, linux-kernel, linux-kselftest
Hi Thomas,
On Thu, Mar 06, 2025 at 06:22:45PM +0100, Thomas Weißschuh wrote:
> Hi Willy,
>
> On 2025-03-04 09:11:16+0100, Willy Tarreau wrote:
> > On Tue, Mar 04, 2025 at 07:58:15AM +0000, Louis Taylor wrote:
> > > openat is useful to avoid needing to construct relative paths, so expose
> > > a wrapper for using it directly.
> >
> > Reviewed the whole series, no comments from me. Let's wait for Thomas
> > to double-check but for me it's OK:
> >
> > Acked-by: Willy Tarreau <w@1wt.eu>
>
> Fairly happy with it, only some tiny nitpicks.
Thanks for double-checking, you caught way more things than me!
> > Thomas, since you already have plenty of changes in queue, do you mind
> > if I let you pick this series ?
>
> Sure.
>
> Also we need to send a PR to Shuah soon.
> I have some patches I want to get into it.
> In case you missed it:
> https://lore.kernel.org/lkml/20250305-nolibc-asm-headers-v1-1-f2053def2ee7@linutronix.de/
Yes I noticed them, these days I'm totally overwhelmed and tend to only
be able to have a look at them during my week-ends :-(
> Also the removal of the constructor order validation.
Yes, not sure I'll have time for it yet :-( I can try, though!
> Will you send a patch or should I?
As last time it will greatly help me if you take care of it. I
feel like I'm leaving you with all the work these days :-/
Cheers,
Willy
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/5] tools/nolibc: add support for openat(2)
2025-03-04 7:58 [PATCH v2 1/5] tools/nolibc: add support for openat(2) Louis Taylor
` (4 preceding siblings ...)
2025-03-04 8:11 ` [PATCH v2 1/5] tools/nolibc: add support for openat(2) Willy Tarreau
@ 2025-03-06 17:10 ` Thomas Weißschuh
2025-03-06 18:30 ` Louis Taylor
5 siblings, 1 reply; 15+ messages in thread
From: Thomas Weißschuh @ 2025-03-06 17:10 UTC (permalink / raw)
To: Louis Taylor; +Cc: Willy Tarreau, Shuah Khan, linux-kernel, linux-kselftest
On 2025-03-04 07:58:15+0000, Louis Taylor wrote:
> openat is useful to avoid needing to construct relative paths, so expose
> a wrapper for using it directly.
>
> Signed-off-by: Louis Taylor <louis@kragniz.eu>
Looks good. I have some tiny nitpicks inline,
but if you prefer I can also pick it up as-is.
Acked-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> tools/include/nolibc/sys.h | 25 ++++++++++++++++++++
> tools/testing/selftests/nolibc/nolibc-test.c | 21 ++++++++++++++++
> 2 files changed, 46 insertions(+)
>
> diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
> index 8f44c33b1213..3cd938f9abda 100644
> --- a/tools/include/nolibc/sys.h
> +++ b/tools/include/nolibc/sys.h
> @@ -765,6 +765,31 @@ int mount(const char *src, const char *tgt,
> return __sysret(sys_mount(src, tgt, fst, flags, data));
> }
>
> +/*
> + * int openat(int dirfd, const char *path, int flags[, mode_t mode]);
> + */
> +
> +static __attribute__((unused))
> +int sys_openat(int dirfd, const char *path, int flags, mode_t mode)
> +{
> + return my_syscall4(__NR_openat, dirfd, path, flags, mode);
> +}
> +
> +static __attribute__((unused))
> +int openat(int dirfd, const char *path, int flags, ...)
> +{
> + mode_t mode = 0;
> +
> + if (flags & O_CREAT) {
> + va_list args;
> +
> + va_start(args, flags);
> + mode = va_arg(args, mode_t);
> + va_end(args);
> + }
> +
> + return __sysret(sys_openat(dirfd, path, flags, mode));
> +}
>
> /*
> * int open(const char *path, int flags[, mode_t mode]);
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index 79c3e6a845f3..2a1629938dd6 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -1028,6 +1028,26 @@ int test_rlimit(void)
> return 0;
> }
>
> +static int test_openat(void)
As mentioned in my other mail, this in fact should not be static.
Sorry for the back and forth.
> +{
> + int dev;
> + int null;
Can be on a single line.
> +
> + dev = openat(AT_FDCWD, "/dev", O_DIRECTORY);
> + if (dev < 0)
> + return -1;
> +
> + null = openat(dev, "null", 0);
As per the standard:
The argument flags must include one of the following access modes:
O_RDONLY, O_WRONLY, or O_RDWR.
The other tests don't do it either and on Linux it doesn't matter
because O_RDONLY == 0. But if we are here anyways.
close(dev) could be moved here for some saved lines.
> + if (null < 0) {
> + close(dev);
> + return -1;
> + }
> +
> + close(dev);
> + close(null);
> +
> + return 0;
> +}
>
> /* Run syscall tests between IDs <min> and <max>.
> * Return 0 on success, non-zero on failure.
> @@ -1116,6 +1136,7 @@ int run_syscall(int min, int max)
> CASE_TEST(mmap_munmap_good); EXPECT_SYSZR(1, test_mmap_munmap()); break;
> CASE_TEST(open_tty); EXPECT_SYSNE(1, tmp = open("/dev/null", 0), -1); if (tmp != -1) close(tmp); break;
> CASE_TEST(open_blah); EXPECT_SYSER(1, tmp = open("/proc/self/blah", 0), -1, ENOENT); if (tmp != -1) close(tmp); break;
> + CASE_TEST(openat_dir); EXPECT_SYSNE(1, test_openat(), -1); break;
EXPECT_SYSZR() should work here.
> CASE_TEST(pipe); EXPECT_SYSZR(1, test_pipe()); break;
> CASE_TEST(poll_null); EXPECT_SYSZR(1, poll(NULL, 0, 0)); break;
> CASE_TEST(poll_stdout); EXPECT_SYSNE(1, ({ struct pollfd fds = { 1, POLLOUT, 0}; poll(&fds, 1, 0); }), -1); break;
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v2 1/5] tools/nolibc: add support for openat(2)
2025-03-06 17:10 ` Thomas Weißschuh
@ 2025-03-06 18:30 ` Louis Taylor
0 siblings, 0 replies; 15+ messages in thread
From: Louis Taylor @ 2025-03-06 18:30 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Willy Tarreau, Shuah Khan, linux-kernel, linux-kselftest
On Thu Mar 6, 2025 at 5:10 PM GMT, Thomas Weißschuh wrote:
> On 2025-03-04 07:58:15+0000, Louis Taylor wrote:
> > openat is useful to avoid needing to construct relative paths, so expose
> > a wrapper for using it directly.
> >
> > Signed-off-by: Louis Taylor <louis@kragniz.eu>
>
> Looks good. I have some tiny nitpicks inline,
> but if you prefer I can also pick it up as-is.
>
> Acked-by: Thomas Weißschuh <linux@weissschuh.net>
No problem, I'll send another version.
> > ---
> > tools/include/nolibc/sys.h | 25 ++++++++++++++++++++
> > tools/testing/selftests/nolibc/nolibc-test.c | 21 ++++++++++++++++
> > 2 files changed, 46 insertions(+)
> >
> > diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
> > index 8f44c33b1213..3cd938f9abda 100644
> > --- a/tools/include/nolibc/sys.h
> > +++ b/tools/include/nolibc/sys.h
> > @@ -765,6 +765,31 @@ int mount(const char *src, const char *tgt,
> > return __sysret(sys_mount(src, tgt, fst, flags, data));
> > }
> >
> > +/*
> > + * int openat(int dirfd, const char *path, int flags[, mode_t mode]);
> > + */
> > +
> > +static __attribute__((unused))
> > +int sys_openat(int dirfd, const char *path, int flags, mode_t mode)
> > +{
> > + return my_syscall4(__NR_openat, dirfd, path, flags, mode);
> > +}
> > +
> > +static __attribute__((unused))
> > +int openat(int dirfd, const char *path, int flags, ...)
> > +{
> > + mode_t mode = 0;
> > +
> > + if (flags & O_CREAT) {
> > + va_list args;
> > +
> > + va_start(args, flags);
> > + mode = va_arg(args, mode_t);
> > + va_end(args);
> > + }
> > +
> > + return __sysret(sys_openat(dirfd, path, flags, mode));
> > +}
> >
> > /*
> > * int open(const char *path, int flags[, mode_t mode]);
> > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> > index 79c3e6a845f3..2a1629938dd6 100644
> > --- a/tools/testing/selftests/nolibc/nolibc-test.c
> > +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> > @@ -1028,6 +1028,26 @@ int test_rlimit(void)
> > return 0;
> > }
> >
> > +static int test_openat(void)
>
> As mentioned in my other mail, this in fact should not be static.
> Sorry for the back and forth.
Ah that's fine, I'll drop the other patch as well.
> > +{
> > + int dev;
> > + int null;
>
> Can be on a single line.
>
> > +
> > + dev = openat(AT_FDCWD, "/dev", O_DIRECTORY);
> > + if (dev < 0)
> > + return -1;
> > +
> > + null = openat(dev, "null", 0);
>
> As per the standard:
>
> The argument flags must include one of the following access modes:
> O_RDONLY, O_WRONLY, or O_RDWR.
>
> The other tests don't do it either and on Linux it doesn't matter
> because O_RDONLY == 0. But if we are here anyways.
>
> close(dev) could be moved here for some saved lines.
>
> > + if (null < 0) {
> > + close(dev);
> > + return -1;
> > + }
> > +
> > + close(dev);
> > + close(null);
> > +
> > + return 0;
> > +}
> >
> > /* Run syscall tests between IDs <min> and <max>.
> > * Return 0 on success, non-zero on failure.
> > @@ -1116,6 +1136,7 @@ int run_syscall(int min, int max)
> > CASE_TEST(mmap_munmap_good); EXPECT_SYSZR(1, test_mmap_munmap()); break;
> > CASE_TEST(open_tty); EXPECT_SYSNE(1, tmp = open("/dev/null", 0), -1); if (tmp != -1) close(tmp); break;
> > CASE_TEST(open_blah); EXPECT_SYSER(1, tmp = open("/proc/self/blah", 0), -1, ENOENT); if (tmp != -1) close(tmp); break;
> > + CASE_TEST(openat_dir); EXPECT_SYSNE(1, test_openat(), -1); break;
>
> EXPECT_SYSZR() should work here.
>
> > CASE_TEST(pipe); EXPECT_SYSZR(1, test_pipe()); break;
> > CASE_TEST(poll_null); EXPECT_SYSZR(1, poll(NULL, 0, 0)); break;
> > CASE_TEST(poll_stdout); EXPECT_SYSNE(1, ({ struct pollfd fds = { 1, POLLOUT, 0}; poll(&fds, 1, 0); }), -1); break;
> > --
> > 2.45.2
> >
^ permalink raw reply [flat|nested] 15+ messages in thread