From nobody Tue May 7 23:10:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587045008; cv=none; d=zohomail.com; s=zohoarc; b=SPvPcRt2O3D62tGzquKAJQuY6CYb1zBsXptalTysLLt9X0rthO8nV6kfPZRWDvxpBdU1jjNI9WPi0ZNemjb7EkThwv5EEX+SZZBfwMQj+qDw2iYDSl9eHKX14huUBkjzCHSLSi4/dRrw7LmK5FxTkbjOiZ0OExuV0xvo/AbqaeQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587045008; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=pQ+2+mqhe0ZbZ4HVk1sHZoK8KNeQuh2VesAVbXYTnpY=; b=BztmOZj9deGihvlywUCEbbBEPQprgyqbC3O1wk05/nIOx0S/UELQODYMPq7Y6/BzK7obXrEZ2zQRAjFnrnT6tnAP/WC3eCh5sn4Qt9oMKpYupGd43IlgvlDHsIFz1/KmoxSUCg5cyEi4xCwRadq8nb8llUdA0a+BRVrYHffHmF8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1587045008828241.9066367704969; Thu, 16 Apr 2020 06:50:08 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-165-_WZFWt8_MFKoYNeFuVT4hw-1; Thu, 16 Apr 2020 09:50:05 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CAC968017FF; Thu, 16 Apr 2020 13:49:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7527719C70; Thu, 16 Apr 2020 13:49:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CB5C81809567; Thu, 16 Apr 2020 13:49:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03GDnQUv001152 for ; Thu, 16 Apr 2020 09:49:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 52F997E7CD; Thu, 16 Apr 2020 13:49:26 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.40.194.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2536A7E7D6 for ; Thu, 16 Apr 2020 13:49:23 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 1CD80248B50; Thu, 16 Apr 2020 15:49:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587045007; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=pQ+2+mqhe0ZbZ4HVk1sHZoK8KNeQuh2VesAVbXYTnpY=; b=JbIXQUmuzgcWwW//omar1XJovyCHrQ0Prml6hTat9JHptzXneg+CFpxzQfuYb4gn7eQz/u VXJz4BH2DhkXkA5TdhhLrd1scFIGrL4wsYn2aimbzY+jSob8qEvaDLda5VKfk38+wxhUfC +V3ZI97lj4adkmMUq80pVepkU3GKnP0= X-MC-Unique: _WZFWt8_MFKoYNeFuVT4hw-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH] util: Fix virDaemonForkIntoBackground Date: Thu, 16 Apr 2020 15:49:18 +0200 Message-Id: <9e9850d56b69ddd52e0d4f295d6d0ff572329f27.1587044958.git.jdenemar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This commit partially reverts commit c360ea28dc267802690e129fbad08ca2f22a44e9 Refs: v6.2.0-rc1-1-gc360ea28dc Author: Rafael Fonseca AuthorDate: Fri Mar 27 18:40:47 2020 +0100 Commit: Michal Pr=C3=ADvozn=C3=ADk CommitDate: Mon Mar 30 09:48:22 2020 +0200 util: virdaemon: fix compilation on mingw The daemons are not supported on Win32 and therefore were not compiled in that platform. However, with the daemon code sharing, all the code in utils *is* compiled and it failed because `waitpid`, `fork`, and `setsid` are not available. So, as before, let's not build them on Win32 and make the code more portable by using existing vir* wrappers. Not compiling virDaemonForkIntoBackground on Win32 is good, but the second part of the original patch incorrectly replaced waitpid and fork with our virProcessWait and virFork APIs. These APIs are more than just simple wrappers and we don't want any of the extra functionality. Especially virFork would reset any setup made before virDaemonForkIntoBackground is called, such as logging, signal handling, etc. As a result of the change the additional fix in v6.2.0-67-ga87e4788d2 (util: virdaemon: fix waiting for child processes) is no longer needed and it is effectively reverted by this commit. Signed-off-by: Jiri Denemark Reviewed-by: Michal Privoznik --- src/util/virdaemon.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/util/virdaemon.c b/src/util/virdaemon.c index 99530fd146..6182ca3c21 100644 --- a/src/util/virdaemon.c +++ b/src/util/virdaemon.c @@ -20,7 +20,9 @@ =20 #include =20 +#include #include +#include #include #include #include @@ -30,8 +32,6 @@ #include "virfile.h" #include "virlog.h" #include "viralloc.h" -#include "virprocess.h" -#include "vircommand.h" =20 #include "configmake.h" =20 @@ -44,7 +44,7 @@ virDaemonForkIntoBackground(const char *argv0) if (virPipeQuiet(statuspipe) < 0) return -1; =20 - pid_t pid =3D virFork(); + pid_t pid =3D fork(); switch (pid) { case 0: { @@ -73,7 +73,7 @@ virDaemonForkIntoBackground(const char *argv0) if (setsid() < 0) goto cleanup; =20 - nextpid =3D virFork(); + nextpid =3D fork(); switch (nextpid) { case 0: /* grandchild */ return statuspipe[1]; @@ -97,14 +97,15 @@ virDaemonForkIntoBackground(const char *argv0) default: { /* parent */ - int exitstatus =3D 0; + int got, exitstatus =3D 0; int ret; char status; =20 VIR_FORCE_CLOSE(statuspipe[1]); =20 /* We wait to make sure the first child forked successfully */ - if (virProcessWait(pid, &exitstatus, 0) < 0 || + if ((got =3D waitpid(pid, &exitstatus, 0)) < 0 || + got !=3D pid || exitstatus !=3D 0) { goto error; } --=20 2.26.1