]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: virExec may blocked by reading pipe if grandchild prematurely exit
authorXu Chao <xu.chao6@zte.com.cn>
Wed, 24 Nov 2021 02:33:11 +0000 (10:33 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 24 Nov 2021 10:59:50 +0000 (11:59 +0100)
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 <xu.chao6@zte.com.cn>
Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/vircommand.c

index fead373729b7868ef63141b4e6d51e435d115143..ba5a2090768b62b9c5d2f14ec90e41de7d9a06e6 100644 (file)
@@ -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 &&