[LTP] [PATCH v5 6/8] syscalls/mknod06: Convert to new API

Petr Vorel pvorel@suse.cz
Fri Jun 6 14:06:36 CEST 2025


Hi Ricardo,

> +static struct tcase {
>  	char *pathname;
>  	char *desc;
>  	int exp_errno;
> -	int (*setupfunc) ();
> -} Test_cases[] = {
> -	{"tnode_1", "Specified node already exists", EEXIST, setup1}, {
> -	NULL, "Invalid address", EFAULT, no_setup}, {
> -	"testdir_2/tnode_2", "Non-existent file", ENOENT, no_setup}, {
> -	"", "Pathname is empty", ENOENT, no_setup}, {
> -	Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, {
> -	"tnode/tnode_3", "Path contains regular file", ENOTDIR, setup3}, {

> -	NULL, NULL, 0, no_setup}
> +} tcases[] = {
> +	{ NULL, "Pathname too long", ENAMETOOLONG },
> +	{ "tnode_1", "Specified node already exists", EEXIST },
> +	{ NULL, "Invalid address", EFAULT },
> +	{ "testdir_2/tnode_2", "Non-existent file", ENOENT },
> +	{ "", "Pathname is empty", ENOENT },
> +	{ "tnode/tnode_3", "Path contains regular file", ENOTDIR },
>  };
Using some constants for path reused ("tnode_1" and "tnode") would be slightly
clearer, but it can stay as is.

...
> +static void setup(void)
>  {
> +	SAFE_MKNOD("tnode_1", MODE_FIFO_RWX, 0);
> +	SAFE_MKNOD("tnode", MODE_FIFO_RWX, 0);

NOTE: if I were the original patch writer, I would really create an empty file,
not a named pipe:
fd = SAFE_OPEN("tnode", O_WRONLY | O_CREAT | O_TRUNC, 0644);
SAFE_CLOSE(fd);

But maybe there was a reason to create named pipe instead of a regular file.

...
> +static struct tst_test test = {
> +	.setup = setup,
> +	.test = run,
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.needs_tmpdir = 1,
> +	.bufs = (struct tst_buffers[]) {
> +		{ &longpathname, .size = PATH_MAX + 2 },
> +		{},

+1 for using Guarded buffers.

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

Kind regards,
Petr


More information about the ltp mailing list