[LTP] [PATCH v3 4/5] syscalls/dup2/dup205: Convert to new API

xuyang2018.jy@fujitsu.com xuyang2018.jy@fujitsu.com
Fri Sep 17 11:59:23 CEST 2021


Hi All
>> Subject: Re: [LTP] [PATCH v3 4/5] syscalls/dup2/dup205: Convert to new API

>>> +
>>> +	if (TST_ERR != EBADF)
>>> +		tst_res(TFAIL, "bad errno on dup2 failure");
>>
>> Hi Qi,
>>
>> Why do you only check EBADF? The old test checks three errno.
>
> Thanks for the comments.
> Both Xu and I got the failures with EBADF,
> so I think that checking EINVAL and ENFILE is not necessary.
Yes, My machine fails with EBADF.
Look this case history, it said nothing about why need three checks.
But kernel code in 4e1e018ecc6f ("PATCH] fix RLIM_NOFILE handling
") ,

it seems old kernel will return EINVAL when rlimit set to 0.
Then will return ENFILE when rlimit set to 0.


And now it looks only fails with EBADF from kernel fs/file.c code.

> I wonder your opinion.
>>
>>> +
>>> +	if (ifile<  min)
>>> +		tst_res(TFAIL, "Not enough files duped");
>>> +	else if (ifile>  min)
>>> +		tst_res(TFAIL, "Too many files duped");
>>> +	else
>>> +		tst_res(TPASS, "Test passed.");
>>> +
>>> +	SAFE_CLOSE(fildes[0]);
>>
>> Why do you close only fildes[0]?
>
> I did try close all fildes[ifile], and it occurred close(-1).
> After talking with Xu, we think that close oldfd is enough.
I think we don't need to close all filedes because dup2 can close newfd
before reuse.  We should close them in cleanup function.

Best Regards
Yang Xu
>
> Best,
> QI
>
>>
>> Best Regards,
>>
>> Xiao Yang
>>
>>> +	SAFE_UNLINK(pfilname);
>>> +}
>>> +
>>> +static struct tst_test test = {
>>> +	.needs_tmpdir = 1,
>>> +	.test_all = run,
>>> +	.setup = setup,
>>> +	.cleanup = cleanup,
>>> +};
>


More information about the ltp mailing list