From: "Louis Taylor" <louis@kragniz.eu>
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: "Willy Tarreau" <w@1wt.eu>, "Shuah Khan" <shuah@kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH v2 1/5] tools/nolibc: add support for openat(2)
Date: Thu, 06 Mar 2025 18:30:19 +0000 [thread overview]
Message-ID: <D89EB2A6K6H8.SDEMLB4O6NMR@kragniz.eu> (raw)
In-Reply-To: <8a1fc6ff-e36c-41b5-b959-2d667bb8279a@t-8ch.de>
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
> >
prev parent reply other threads:[~2025-03-06 18:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 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
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
2025-03-06 17:10 ` Thomas Weißschuh
2025-03-06 18:30 ` Louis Taylor [this message]
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=D89EB2A6K6H8.SDEMLB4O6NMR@kragniz.eu \
--to=louis@kragniz.eu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=shuah@kernel.org \
--cc=w@1wt.eu \
/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