system/FileDescriptor: add CheckDuplicate()
This commit is contained in:
parent
b188ae0e5c
commit
a13897cf6f
@ -188,6 +188,16 @@ FileDescriptor::DisableCloseOnExec() noexcept
|
||||
fcntl(fd, F_SETFD, old_flags & ~FD_CLOEXEC);
|
||||
}
|
||||
|
||||
bool
|
||||
FileDescriptor::CheckDuplicate(int new_fd) noexcept
|
||||
{
|
||||
if (fd == new_fd) {
|
||||
DisableCloseOnExec();
|
||||
return true;
|
||||
} else
|
||||
return Duplicate(new_fd);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_EVENTFD
|
||||
|
@ -146,6 +146,14 @@ public:
|
||||
bool Duplicate(int new_fd) const noexcept {
|
||||
return ::dup2(Get(), new_fd) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to Duplicate(), but if destination and source file
|
||||
* descriptor are equal, clear the close-on-exec flag. Use
|
||||
* this method to inject file descriptors into a new child
|
||||
* process, to be used by a newly executed program.
|
||||
*/
|
||||
bool CheckDuplicate(int new_fd) noexcept;
|
||||
#endif
|
||||
|
||||
#ifdef USE_EVENTFD
|
||||
|
Loading…
Reference in New Issue
Block a user