support: Also return fd when it is 0
The fd validity check in open_dev_null checks if fd > 0, which would lead to a leaked fd if it is == 0. Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
parent
3234a31b48
commit
27b6edbb09
|
@ -40,16 +40,16 @@ increase_nofile (void)
|
||||||
static int
|
static int
|
||||||
open_dev_null (int flags, mode_t mode)
|
open_dev_null (int flags, mode_t mode)
|
||||||
{
|
{
|
||||||
int fd = open64 ("/dev/null", flags, mode);
|
int fd = open64 ("/dev/null", flags, mode);
|
||||||
if (fd > 0)
|
if (fd >= 0)
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
if (fd < 0 && errno != EMFILE)
|
if (fd < 0 && errno != EMFILE)
|
||||||
FAIL_EXIT1 ("open64 (\"/dev/null\", 0x%x, 0%o): %m", flags, mode);
|
FAIL_EXIT1 ("open64 (\"/dev/null\", 0x%x, 0%o): %m", flags, mode);
|
||||||
|
|
||||||
increase_nofile ();
|
increase_nofile ();
|
||||||
|
|
||||||
return xopen ("/dev/null", flags, mode);
|
return xopen ("/dev/null", flags, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct range
|
struct range
|
||||||
|
|
Loading…
Reference in a new issue