mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
dup3: don't set FD_CLOEXEC on failure on kernels without dup3 syscall
this is the best-effort fallback path for kernels that can't actually support the dup3 functionality. it was setting FD_CLOEXEC flag on the target fd (new) even if the dup2 operation failed. normally that shouldn't happen under correct usage, but it's possible if the source fd is not open or intentionally invalid (e.g. -1).
This commit is contained in:
parent
c99b7daafd
commit
3281047cfc
1 changed files with 2 additions and 1 deletions
|
@ -15,7 +15,8 @@ int __dup3(int old, int new, int flags)
|
|||
if (flags & ~O_CLOEXEC) return __syscall_ret(-EINVAL);
|
||||
}
|
||||
while ((r=__syscall(SYS_dup2, old, new))==-EBUSY);
|
||||
if (flags & O_CLOEXEC) __syscall(SYS_fcntl, new, F_SETFD, FD_CLOEXEC);
|
||||
if (r >= 0 && (flags & O_CLOEXEC))
|
||||
__syscall(SYS_fcntl, new, F_SETFD, FD_CLOEXEC);
|
||||
#else
|
||||
while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue