[PATCH] util: virdaemon: fix waiting for child processes

Rafael Fonseca posted 1 patch 4 years ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20200407201434.1850252-1-r4f4rfs@gmail.com
There is a newer version of this series
src/util/virdaemon.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
[PATCH] util: virdaemon: fix waiting for child processes
Posted by Rafael Fonseca 4 years ago
Unlike `waitpid`, `virProcessWait` only returns -1 (error) or 0
(success), so comparing that to `pid` will always be false and the
parent will report failure with:

error : main:851 : Failed to fork as daemon: No such file or directory

even though the grandchild process is succesfully running. Note that the
errno message is misleading: it was last set when trying to find a
restart state file.

Signed-off-by: Rafael Fonseca <r4f4rfs@gmail.com>
---
 src/util/virdaemon.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/util/virdaemon.c b/src/util/virdaemon.c
index 5d92c7def7..99530fd146 100644
--- a/src/util/virdaemon.c
+++ b/src/util/virdaemon.c
@@ -97,15 +97,14 @@ virDaemonForkIntoBackground(const char *argv0)
     default:
         {
             /* parent */
-            int got, exitstatus = 0;
+            int exitstatus = 0;
             int ret;
             char status;
 
             VIR_FORCE_CLOSE(statuspipe[1]);
 
             /* We wait to make sure the first child forked successfully */
-            if ((got = virProcessWait(pid, &exitstatus, 0)) < 0 ||
-                got != pid ||
+            if (virProcessWait(pid, &exitstatus, 0) < 0 ||
                 exitstatus != 0) {
                 goto error;
             }
-- 
2.25.1


Re: [PATCH] util: virdaemon: fix waiting for child processes
Posted by Rafael Fonseca 4 years ago
On Tue, 7 Apr 2020, 22:14 Rafael Fonseca, <r4f4rfs@gmail.com> wrote:

> Unlike `waitpid`, `virProcessWait` only returns -1 (error) or 0
> (success), so comparing that to `pid` will always be false and the
> parent will report failure with:
>
> error : main:851 : Failed to fork as daemon: No such file or directory
>
> even though the grandchild process is succesfully running. Note that the
> errno message is misleading: it was last set when trying to find a
> restart state file.
>

Thanks to Marcin Krol who found the issue and helped me debug it.

>
Re: [PATCH] util: virdaemon: fix waiting for child processes
Posted by Ján Tomko 4 years ago
On a Wednesday in 2020, Rafael Fonseca wrote:
>On Tue, 7 Apr 2020, 22:14 Rafael Fonseca, <r4f4rfs@gmail.com> wrote:
>
>> Unlike `waitpid`, `virProcessWait` only returns -1 (error) or 0
>> (success), so comparing that to `pid` will always be false and the
>> parent will report failure with:
>>
>> error : main:851 : Failed to fork as daemon: No such file or directory
>>
>> even though the grandchild process is succesfully running. Note that the
>> errno message is misleading: it was last set when trying to find a
>> restart state file.
>
>Thanks to Marcin Krol who found the issue and helped me debug it.

You can record his contribution in the git history if you'd like,
e.g.
Reported-by: Marcin Krol <his-e-mail>

Not sure there is a standard tag used for people helping with debugging.


The patch itself looks good to me, although thanks to use of these
helpers some code paths will report an error twice.

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano