提交 296eb0bb 编写于 作者: E Eric Blake

util: allow clearing cloexec bit

* src/util/util.h (virSetInherit): New prototype.
* src/util/util.c (virSetCloseExec): Move guts...
(virSetInherit): ...to new function, and allow clearing.
* src/libvirt_private.syms (util.h): Export it.
上级 60dea30b
......@@ -913,6 +913,7 @@ virRun;
virRunWithHook;
virSetBlocking;
virSetCloseExec;
virSetInherit;
virSetNonBlock;
virSetUIDGID;
virSkipSpaces;
......
......@@ -273,13 +273,21 @@ int virSetNonBlock(int fd) {
}
int virSetCloseExec(int fd)
{
return virSetInherit(fd, false);
}
#ifndef WIN32
int virSetCloseExec(int fd) {
int virSetInherit(int fd, bool inherit) {
int flags;
if ((flags = fcntl(fd, F_GETFD)) < 0)
return -1;
flags |= FD_CLOEXEC;
if (inherit)
flags &= ~FD_CLOEXEC;
else
flags |= FD_CLOEXEC;
if ((fcntl(fd, F_SETFD, flags)) < 0)
return -1;
return 0;
......@@ -931,7 +939,7 @@ virRunWithHook(const char *const*argv,
#else /* WIN32 */
int virSetCloseExec(int fd ATTRIBUTE_UNUSED)
int virSetInherit(int fd ATTRIBUTE_UNUSED, bool inherit ATTRIBUTE_UNUSED)
{
return -1;
}
......
......@@ -51,6 +51,7 @@ enum {
int virSetBlocking(int fd, bool blocking) ATTRIBUTE_RETURN_CHECK;
int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK;
int virSetInherit(int fd, bool inherit) ATTRIBUTE_RETURN_CHECK;
int virSetCloseExec(int fd) ATTRIBUTE_RETURN_CHECK;
/* This will execute in the context of the first child
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册