mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
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.
This commit is contained in:
parent
60dea30b7d
commit
296eb0bbe3
@ -913,6 +913,7 @@ virRun;
|
|||||||
virRunWithHook;
|
virRunWithHook;
|
||||||
virSetBlocking;
|
virSetBlocking;
|
||||||
virSetCloseExec;
|
virSetCloseExec;
|
||||||
|
virSetInherit;
|
||||||
virSetNonBlock;
|
virSetNonBlock;
|
||||||
virSetUIDGID;
|
virSetUIDGID;
|
||||||
virSkipSpaces;
|
virSkipSpaces;
|
||||||
|
@ -273,12 +273,20 @@ int virSetNonBlock(int fd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int virSetCloseExec(int fd)
|
||||||
|
{
|
||||||
|
return virSetInherit(fd, false);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
|
||||||
int virSetCloseExec(int fd) {
|
int virSetInherit(int fd, bool inherit) {
|
||||||
int flags;
|
int flags;
|
||||||
if ((flags = fcntl(fd, F_GETFD)) < 0)
|
if ((flags = fcntl(fd, F_GETFD)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
if (inherit)
|
||||||
|
flags &= ~FD_CLOEXEC;
|
||||||
|
else
|
||||||
flags |= FD_CLOEXEC;
|
flags |= FD_CLOEXEC;
|
||||||
if ((fcntl(fd, F_SETFD, flags)) < 0)
|
if ((fcntl(fd, F_SETFD, flags)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -931,7 +939,7 @@ virRunWithHook(const char *const*argv,
|
|||||||
|
|
||||||
#else /* WIN32 */
|
#else /* WIN32 */
|
||||||
|
|
||||||
int virSetCloseExec(int fd ATTRIBUTE_UNUSED)
|
int virSetInherit(int fd ATTRIBUTE_UNUSED, bool inherit ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ enum {
|
|||||||
|
|
||||||
int virSetBlocking(int fd, bool blocking) ATTRIBUTE_RETURN_CHECK;
|
int virSetBlocking(int fd, bool blocking) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virSetNonBlock(int fd) 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;
|
int virSetCloseExec(int fd) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
/* This will execute in the context of the first child
|
/* This will execute in the context of the first child
|
||||||
|
Loading…
Reference in New Issue
Block a user