system/FileDescriptor: add methods EnableCloseOnExec(), DisableCloseOnExec()
This commit is contained in:
parent
33bd9e80bb
commit
91ce76af9d
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2015 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright (C) 2012-2017 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -126,6 +126,24 @@ FileDescriptor::SetBlocking() noexcept
|
|||
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
|
||||
}
|
||||
|
||||
void
|
||||
FileDescriptor::EnableCloseOnExec() noexcept
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
const int old_flags = fcntl(fd, F_GETFD, 0);
|
||||
fcntl(fd, F_SETFD, old_flags | FD_CLOEXEC);
|
||||
}
|
||||
|
||||
void
|
||||
FileDescriptor::DisableCloseOnExec() noexcept
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
const int old_flags = fcntl(fd, F_GETFD, 0);
|
||||
fcntl(fd, F_SETFD, old_flags & ~FD_CLOEXEC);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_EVENTFD
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2015 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright (C) 2012-2017 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -114,6 +114,18 @@ public:
|
|||
*/
|
||||
void SetBlocking() noexcept;
|
||||
|
||||
/**
|
||||
* Auto-close this file descriptor when a new program is
|
||||
* executed.
|
||||
*/
|
||||
void EnableCloseOnExec() noexcept;
|
||||
|
||||
/**
|
||||
* Do not auto-close this file descriptor when a new program
|
||||
* is executed.
|
||||
*/
|
||||
void DisableCloseOnExec() noexcept;
|
||||
|
||||
/**
|
||||
* Duplicate the file descriptor onto the given file descriptor.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue