From: Xu Chao Date: Wed, 24 Nov 2021 02:33:11 +0000 (+0800) Subject: util: virExec may blocked by reading pipe if grandchild prematurely exit X-Git-Tag: v7.10.0-rc1~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fac961b085af51340246bf51205a9f2f1615962;p=thirdparty%2Flibvirt.git util: virExec may blocked by reading pipe if grandchild prematurely exit When VIR_EXEC_DAEMON is set, if virPidFileAcquirePath/virSetInherit failed, then pipesync[0] can not be closed when granchild process exit, because pipesync[1] still opened in child process. and then saferead in child process may blocked forever, and left grandchild process in defunct state. Signed-off-by: Xu Chao Signed-off-by: Yi Wang Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- diff --git a/src/util/vircommand.c b/src/util/vircommand.c index fead373729..ba5a209076 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -782,6 +782,10 @@ virExec(virCommand *cmd) } if (pid > 0) { + /* At this point it's us and the child that holds the write end of + * the pipe open. Close the write end of the pipe, so that the pipe + * is fully closed if child dies prematurely. */ + VIR_FORCE_CLOSE(pipesync[1]); /* The parent expect us to have written the pid file before * exiting. Wait here for the child to write it and signal us. */ if (cmd->pidfile &&