public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Martin Doucha <mdoucha@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] open07: Convert to new API
Date: Mon, 19 Feb 2024 21:48:19 +0100	[thread overview]
Message-ID: <20240219204819.GA1057967@pevik> (raw)
In-Reply-To: <86169685-b118-4186-951f-7919796dcb93@suse.cz>

Hi Martin,

TL;DR: merged with fixes.

> On 19. 02. 24 17:09, Petr Vorel wrote:
> > Hi Martin,

> > Reviewed-by: Petr Vorel <pvorel@suse.cz>

> > Few minor things below, can be fixed before merge.

> > ...
> > >   #define _GNU_SOURCE		/* for O_NOFOLLOW */
> > nit: This now works without _GNU_SOURCE (we compile with -std=gnu99 and it would
> > work for whatever gnu*).

> > > -#include <stdio.h>
> > > -#include <errno.h>
> > > -#include <sys/types.h>
> > >   #include <sys/stat.h>
> > nit: IMHO <sys/stat.h> was not needed even in the old API version.

> Good catch x2. <sys/stat.h> is needed for umask() but it's included through
> tst_safe_macros.h

Ah, good point. I removed it before merge (I hope we never reorganize lib/*.c
that much that we'd remove some includes in include/*.h, because quite a few
tests depends on these indirect includes already).

> > > -#include <fcntl.h>
> > > -#include "test.h"
> > > -#include "safe_macros.h"
> > ...
> > > +#include "tst_test.h"
> > > +#include "tst_safe_macros.h"
> > > +
> > > +#define TESTFILE "testfile"
> > > +#define TESTDIR "testdir"
> > > +#define SYMFILE1 "symfile1"
> > > +#define SYMFILE2 "symfile2"
> > > +#define SYMDIR1 "symdir1"
> > > +#define SYMDIR2 "symdir2"
> > > +#define PASSFILE "symdir1/testfile"
> > > +
> > > +static int fd = -1;
> > nit: any reason for -1? (We don't check the input.)

> I planned to have a cleanup() where the fd would be checked and closed if
> needed. But it wasn't needed in the end and I forgot to remove the
> initialization. The variable can be moved inside setup(). Should I send v2?

Nah, fixed before merge. +1 for pointing out it was for setup() only.

> > > +static struct testcase {
> > > +	const char *path;
> > > +	int err;
> > > +	const char *desc;
> > > +} testcase_list[] = {
> > > +	{SYMFILE1, ELOOP, "open(O_NOFOLLOW) a symlink to file"},
> > > +	{SYMFILE2, ELOOP, "open(O_NOFOLLOW) a double symlink to file"},
> > > +	{SYMDIR1, ELOOP, "open(O_NOFOLLOW) a symlink to directory"},
> > > +	{SYMDIR2, ELOOP, "open(O_NOFOLLOW) a double symlink to directory"},
> > > +	{PASSFILE, 0, "open(O_NOFOLLOW) a file in symlinked directory"},

> > ...
> > > +static void setup(void)
> > >   {
> > > -	char file1[100], file2[100];
> > > -
> > > -	sprintf(file1, "open11.3.%d", getpid());
> > > -	sprintf(file2, "open12.4.%d", getpid());
> > > -	SAFE_MKDIR(cleanup, file1, 00700);
> > > +	umask(0);
> > > +	fd = SAFE_CREAT(TESTFILE, 0644);
> > > +	SAFE_CLOSE(fd);
> > > +	SAFE_MKDIR(TESTDIR, 0755);

> > > -	SAFE_SYMLINK(cleanup, file1, file2);
> > > +	SAFE_SYMLINK(TESTFILE, SYMFILE1);
> > > +	SAFE_SYMLINK(SYMFILE1, SYMFILE2);
> > > +	SAFE_SYMLINK(TESTDIR, SYMDIR1);
> > > +	SAFE_SYMLINK(SYMDIR1, SYMDIR2);

> > > -	strcpy(TC[4].filename, file2);
> > > -	strcat(TC[4].filename, "/");
> > > +	fd = SAFE_CREAT(PASSFILE, 0644);
> > > +	SAFE_CLOSE(fd);
> > >   }

> > > -static void setup(void)
> > > +static void run(unsigned int n)
> > >   {
> > > -	umask(0);
> > > +	const struct testcase *tc = testcase_list + n;

> > > -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> > > +	TST_RET = -1;
> > nit: IMHO this is not needed (we have 0 for stdin, right? Therefore open()
> > should not get 0 and check below is correct).

> Zero is still a valid file descriptor whether it's used or not. On the other
> hand, TST_RET will be set by open() in both branches below so the
> initialization is not needed at all.

+1

Removed and merged.

Thanks for taking care for these tiny details.

Kind regards,
Petr

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

      reply	other threads:[~2024-02-19 20:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-19 13:40 [LTP] [PATCH] open07: Convert to new API Martin Doucha
2024-02-19 16:09 ` Petr Vorel
2024-02-19 17:15   ` Martin Doucha
2024-02-19 20:48     ` Petr Vorel [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=20240219204819.GA1057967@pevik \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=mdoucha@suse.cz \
    /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