提交 aa605628 编写于 作者: A Andrea Bolognani

util: Make it safe to call virFileWrapperFdClose() multiple times

We'll want to use this function in the cleanup path soon,
and in order to be able to do that we need to make sure we
can call it multiple times on the same virFileWrapperFd
without side effects.
Signed-off-by: NAndrea Bolognani <abologna@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 d7be1b1c
...@@ -175,6 +175,7 @@ virFileDirectFdFlag(void) ...@@ -175,6 +175,7 @@ virFileDirectFdFlag(void)
/* Opaque type for managing a wrapper around a fd. For now, /* Opaque type for managing a wrapper around a fd. For now,
* read-write is not supported, just a single direction. */ * read-write is not supported, just a single direction. */
struct _virFileWrapperFd { struct _virFileWrapperFd {
bool closed; /* Whether virFileWrapperFdClose() has been already called */
virCommandPtr cmd; /* Child iohelper process to do the I/O. */ virCommandPtr cmd; /* Child iohelper process to do the I/O. */
char *err_msg; /* stderr of @cmd */ char *err_msg; /* stderr of @cmd */
}; };
...@@ -323,16 +324,21 @@ virFileWrapperFdNew(int *fd ATTRIBUTE_UNUSED, ...@@ -323,16 +324,21 @@ virFileWrapperFdNew(int *fd ATTRIBUTE_UNUSED,
* callers can conditionally create a virFileWrapperFd wrapper but * callers can conditionally create a virFileWrapperFd wrapper but
* unconditionally call the cleanup code. To avoid deadlock, only * unconditionally call the cleanup code. To avoid deadlock, only
* call this after closing the fd resulting from virFileWrapperFdNew(). * call this after closing the fd resulting from virFileWrapperFdNew().
*
* This function can be safely called multiple times on the same @wfd.
*/ */
int int
virFileWrapperFdClose(virFileWrapperFdPtr wfd) virFileWrapperFdClose(virFileWrapperFdPtr wfd)
{ {
int ret; int ret;
if (!wfd) if (!wfd || wfd->closed)
return 0; return 0;
ret = virCommandWait(wfd->cmd, NULL); ret = virCommandWait(wfd->cmd, NULL);
wfd->closed = true;
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册