os/inputthread: Fix setting of cloexec on file descriptors
O_CLOEXEC is not a file bit. It is not setable with F_SETFL. One must
use it when calling open(2). To set it cloexec on an existing fd,
F_SETFD and FD_CLOEXEC must be used.
This also fixes a build failure regression on configurations that don't
have O_CLOEXEC defined.
cf: http://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
Regressed-in: 30ac756798
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Reviewed-by: Julien Cristau <jcristau@debian.org>
This commit is contained in:
parent
a5769de0f5
commit
065eb66124
|
@ -379,6 +379,7 @@ void
|
||||||
InputThreadPreInit(void)
|
InputThreadPreInit(void)
|
||||||
{
|
{
|
||||||
int fds[2], hotplugPipe[2];
|
int fds[2], hotplugPipe[2];
|
||||||
|
int flags;
|
||||||
|
|
||||||
if (!InputThreadEnable)
|
if (!InputThreadEnable)
|
||||||
return;
|
return;
|
||||||
|
@ -402,13 +403,23 @@ InputThreadPreInit(void)
|
||||||
* in parallel.
|
* in parallel.
|
||||||
*/
|
*/
|
||||||
inputThreadInfo->readPipe = fds[0];
|
inputThreadInfo->readPipe = fds[0];
|
||||||
fcntl(inputThreadInfo->readPipe, F_SETFL, O_NONBLOCK | O_CLOEXEC);
|
fcntl(inputThreadInfo->readPipe, F_SETFL, O_NONBLOCK);
|
||||||
|
flags = fcntl(inputThreadInfo->readPipe, F_GETFD);
|
||||||
|
if (flags != -1) {
|
||||||
|
flags |= FD_CLOEXEC;
|
||||||
|
(void)fcntl(inputThreadInfo->readPipe, F_SETFD, &flags);
|
||||||
|
}
|
||||||
SetNotifyFd(inputThreadInfo->readPipe, InputThreadNotifyPipe, X_NOTIFY_READ, NULL);
|
SetNotifyFd(inputThreadInfo->readPipe, InputThreadNotifyPipe, X_NOTIFY_READ, NULL);
|
||||||
|
|
||||||
inputThreadInfo->writePipe = fds[1];
|
inputThreadInfo->writePipe = fds[1];
|
||||||
|
|
||||||
hotplugPipeRead = hotplugPipe[0];
|
hotplugPipeRead = hotplugPipe[0];
|
||||||
fcntl(hotplugPipeRead, F_SETFL, O_NONBLOCK | O_CLOEXEC);
|
fcntl(hotplugPipeRead, F_SETFL, O_NONBLOCK);
|
||||||
|
flags = fcntl(hotplugPipeRead, F_GETFD);
|
||||||
|
if (flags != -1) {
|
||||||
|
flags |= FD_CLOEXEC;
|
||||||
|
(void)fcntl(hotplugPipeRead, F_SETFD, &flags);
|
||||||
|
}
|
||||||
hotplugPipeWrite = hotplugPipe[1];
|
hotplugPipeWrite = hotplugPipe[1];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue