From nobody Mon May 6 06:30:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1584117005; cv=none; d=zohomail.com; s=zohoarc; b=IUS94LR2RTUHS/MY9VN9+zds63I40hsEUcECw2gpbigJ56hN/jkArjqzG+ijCvJsU+6PlKBVgDHRypLNweYv3+Mg+PP8XmT8kSJnbUik5BbMZDX2LeGVy6UnI7qAGig06WbqdN1PUPicpJuXio1/4ya5BKmLB4gZW0nsV5a4Lho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584117005; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Z62e2eDTilv9c8EDvSMREtJpR3jl0GknOEFOlvGITGQ=; b=A5RROR8Tdrlx5OtGO6hUR/QhYxTwmfmIyjT3Ki/2BL/4YzIUhqsZRFlzwC944NvG890INnFvEKgKpXRJTA7hA+NEBBd2NUd1SV3T7YXMGvJBoa+cSbs2gdFBsmvWhiOFTU+5rx1dfLFWtF5H8rBk4jkcYL/JrHBlPtgJwVyakg0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1584117005028302.2584645827377; Fri, 13 Mar 2020 09:30:05 -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-207-rIp9fcBWNQ6RFFqJo3Ng_Q-1; Fri, 13 Mar 2020 12:29:12 -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 774498017CC; Fri, 13 Mar 2020 16:29:06 +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 A698919756; Fri, 13 Mar 2020 16:29:05 +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 144A11809567; Fri, 13 Mar 2020 16:29:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02DGSxR9010859 for ; Fri, 13 Mar 2020 12:28:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 411161001902; Fri, 13 Mar 2020 16:28:59 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC3C2100164D for ; Fri, 13 Mar 2020 16:28:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584117003; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Z62e2eDTilv9c8EDvSMREtJpR3jl0GknOEFOlvGITGQ=; b=R7dtI4LQnZOiztQTKX1THDOtxykYibY4YGxUb5DK/7tj/XaV1EoG8NfGmj+2pOM4kkKiVN 55OMyaRomkRRnX8Hh1FG/6RfPfg1S4mOFDxoNmbZKuTHkUgGZ/DuJiHhZf/I+5vBgaQk4a iMYSx/p9Dom5pOipXQgMhshAXR+Ql6o= X-MC-Unique: rIp9fcBWNQ6RFFqJo3Ng_Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/5] virCommand: Actually acquire pidfile instead of just writing it Date: Fri, 13 Mar 2020 17:28:49 +0100 Message-Id: <54564dc6daa8ec648593a13589552d9e0c26384d.1584116228.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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" Our virCommand module allows us to set a pidfile for commands we want to spawn. The caller constructs the string of pidfile path and then uses virCommandSetPidFile() to tell the module to write the pidfile once the command is ran. This usually works, but has two flaws: 1) the child process does not hold the pidfile open & locked. Therefore, the caller (or anybody else) can't use our fancy virPidFileForceCleanupPath() function to kill the command afterwards. Also, for everybody else on the system it's needlessly harder to check if the pid from the pidfile is still alive or not. 2) if the caller ever makes a mistake and passes the same pidfile path for two different commands, the start of the second command will overwrite the pidfile even though the first command might still be running. Signed-off-by: Michal Privoznik --- docs/internals/command.html.in | 4 ++- src/util/vircommand.c | 56 +++++++++++++++++++++++++++++----- tests/commanddata/test4.log | 1 + 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/docs/internals/command.html.in b/docs/internals/command.html.in index 8a9061e70f..823d89cc71 100644 --- a/docs/internals/command.html.in +++ b/docs/internals/command.html.in @@ -226,7 +226,9 @@ virCommandSetPidFile(cmd, "/var/run/dnsmasq.pid"); =20

This PID file is guaranteed to be written before - the intermediate process exits. + the intermediate process exits. Moreover, the daemonized + process will inherit the FD of the opened and locked PID + file.

=20

Reducing command privileges

diff --git a/src/util/vircommand.c b/src/util/vircommand.c index c150d99452..276afee61c 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -612,6 +612,7 @@ virExec(virCommandPtr cmd) int null =3D -1; int pipeout[2] =3D {-1, -1}; int pipeerr[2] =3D {-1, -1}; + int pipesync[2] =3D {-1, -1}; int childin =3D cmd->infd; int childout =3D -1; int childerr =3D -1; @@ -745,9 +746,15 @@ virExec(virCommandPtr cmd) /* Initialize full logging for a while */ virLogSetFromEnv(); =20 + if (cmd->pidfile && + virPipe(pipesync) < 0) + goto fork_error; + /* Daemonize as late as possible, so the parent process can detect * the above errors with wait* */ if (cmd->flags & VIR_EXEC_DAEMON) { + char c; + if (setsid() < 0) { virReportSystemError(errno, "%s", _("cannot become session leader")); @@ -768,12 +775,13 @@ virExec(virCommandPtr cmd) } =20 if (pid > 0) { - if (cmd->pidfile && (virPidFileWritePath(cmd->pidfile, pid) < = 0)) { - if (virProcessKillPainfully(pid, true) >=3D 0) - virReportSystemError(errno, - _("could not write pidfile %s for= %d"), - cmd->pidfile, pid); - goto fork_error; + /* 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 && + saferead(pipesync[0], &c, sizeof(c)) !=3D sizeof(c)) { + virReportSystemError(errno, "%s", + _("Unable to wait for child process")= ); + _exit(EXIT_FAILURE); } _exit(EXIT_SUCCESS); } @@ -788,6 +796,37 @@ virExec(virCommandPtr cmd) if (cmd->setMaxCore && virProcessSetMaxCoreSize(0, cmd->maxCore) < 0) goto fork_error; + if (cmd->pidfile) { + VIR_AUTOCLOSE pidfilefd =3D -1; + int newpidfilefd =3D -1; + char c; + + pidfilefd =3D virPidFileAcquirePath(cmd->pidfile, false, getpid()); + if (pidfilefd < 0) + goto fork_error; + if (virSetInherit(pidfilefd, true) < 0) { + virReportSystemError(errno, "%s", + _("Cannot disable close-on-exec flag")); + goto fork_error; + } + + c =3D '1'; + if (safewrite(pipesync[1], &c, sizeof(c)) !=3D sizeof(c)) { + virReportSystemError(errno, "%s", _("Unable to notify child pr= ocess")); + goto fork_error; + } + VIR_FORCE_CLOSE(pipesync[0]); + VIR_FORCE_CLOSE(pipesync[1]); + + /* This is here only to move the pidfilefd + * to the lowest possible number. */ + if ((newpidfilefd =3D dup(pidfilefd)) < 0) { + virReportSystemError(errno, "%s", _("Unable to dup FD")); + goto fork_error; + } + + /* newpidfilefd is intentionally leaked. */ + } =20 if (cmd->hook) { VIR_DEBUG("Run hook %p %p", cmd->hook, cmd->opaque); @@ -1080,8 +1119,9 @@ virCommandPassFDGetFDIndex(virCommandPtr cmd, int fd) * @cmd: the command to modify * @pidfile: filename to use * - * Save the child PID in a pidfile. The pidfile will be populated - * before the exec of the child. + * Save the child PID in a pidfile. The pidfile will be populated before t= he + * exec of the child and the child will inherit opened and locked FD to the + * pidfile. */ void virCommandSetPidFile(virCommandPtr cmd, const char *pidfile) diff --git a/tests/commanddata/test4.log b/tests/commanddata/test4.log index f170be204e..5820f28307 100644 --- a/tests/commanddata/test4.log +++ b/tests/commanddata/test4.log @@ -9,6 +9,7 @@ ENV:USER=3Dtest FD:0 FD:1 FD:2 +FD:3 DAEMON:yes CWD:/ UMASK:0022 --=20 2.24.1 From nobody Mon May 6 06:30:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.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 205.139.110.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=1584116956; cv=none; d=zohomail.com; s=zohoarc; b=HSHTSBF0Xn/X+AKXSeXWG3AiNyldQHsy7+gstD/jaXFF8o2QeX+oukBxWKRUcAwafcstAFdtHldQ7NImnpTu4UYmi7AZ+t8vQykQ1E4x8kg4c1qBKp1HA2lI2ztyT8BboC03OnXivbfvHNBHzOtGL1nkKxwXRLZtXI4SKGrN2Zk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584116956; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GoOxxniJZ2Yjn+Br4nDS0H+NEasE6nf2Y+PVic1aZKk=; b=EDMwfUbF8Ug4UbngiPq4hWQ/py4IsWXxJJAxBTrlQi+pZzz7/ALDigrVoAinSFPx7BFaATXUyTn0hOKzgEbuALxMIFFEUWZ2rqUxEnd7uiXGSJpdzMznEoNm3IxN++uk0WgejoL2jDWN+IPEvIHolqUjI50cB9w+BqlTaOUVZYg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.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 [205.139.110.120]) by mx.zohomail.com with SMTPS id 1584116956617584.460974688875; Fri, 13 Mar 2020 09:29:16 -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-300-HbSscJcUOmOO6BnUWr3wrw-1; Fri, 13 Mar 2020 12:29:12 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 98624800D54; Fri, 13 Mar 2020 16:29:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1C5F592D20; Fri, 13 Mar 2020 16:29:06 +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 3874385ECD; Fri, 13 Mar 2020 16:29:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02DGT0op010874 for ; Fri, 13 Mar 2020 12:29:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1A10D1001B34; Fri, 13 Mar 2020 16:29:00 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 912851001902 for ; Fri, 13 Mar 2020 16:28:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584116955; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=GoOxxniJZ2Yjn+Br4nDS0H+NEasE6nf2Y+PVic1aZKk=; b=YPNMX0GfXi+Exk1PxCNah4fAH+8tGvTsyCfJOD1rkyUADLp5TZMMGUc1h8ahmsHGepPlKX JN+a115buR9RyzFoUUapF31H+KrnVZ5irfP6gc6iLAC0fSlz0xMmpAINLCh05QvIU3X38Z TweBRtGSfv/8JK+T0a7Pooe/D5M+oA4= X-MC-Unique: HbSscJcUOmOO6BnUWr3wrw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/5] qemuProcessStartManagedPRDaemon: Don't pass -f pidfile to the daemon Date: Fri, 13 Mar 2020 17:28:50 +0100 Message-Id: <8c51e10f3caa8649a8feec58af79d7f06a7e8bd3.1584116228.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.79 on 10.5.11.15 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" Now, that our virCommandSetPidFile() is more intelligent we don't need to rely on the daemon to create and lock the pidfile and use virCommandSetPidFile() at the same time. Signed-off-by: Michal Privoznik --- src/qemu/qemu_process.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 31cd553afd..d1170869cf 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2851,7 +2851,6 @@ qemuProcessStartManagedPRDaemon(virDomainObjPtr vm) g_autoptr(virQEMUDriverConfig) cfg =3D NULL; int errfd =3D -1; g_autofree char *pidfile =3D NULL; - int pidfd =3D -1; g_autofree char *socketPath =3D NULL; pid_t cpid =3D -1; g_autoptr(virCommand) cmd =3D NULL; @@ -2870,10 +2869,6 @@ qemuProcessStartManagedPRDaemon(virDomainObjPtr vm) if (!(pidfile =3D qemuProcessBuildPRHelperPidfilePath(vm))) goto cleanup; =20 - /* Just try to acquire. Dummy pid will be replaced later */ - if ((pidfd =3D virPidFileAcquirePath(pidfile, false, -1)) < 0) - goto cleanup; - if (!(socketPath =3D qemuDomainGetManagedPRSocketPath(priv))) goto cleanup; =20 @@ -2888,13 +2883,10 @@ qemuProcessStartManagedPRDaemon(virDomainObjPtr vm) =20 if (!(cmd =3D virCommandNewArgList(cfg->prHelperName, "-k", socketPath, - "-f", pidfile, NULL))) goto cleanup; =20 virCommandDaemonize(cmd); - /* We want our virCommand to write child PID into the pidfile - * so that we can read it even before exec(). */ virCommandSetPidFile(cmd, pidfile); virCommandSetErrorFD(cmd, &errfd); =20 @@ -2957,7 +2949,6 @@ qemuProcessStartManagedPRDaemon(virDomainObjPtr vm) if (pidfile) unlink(pidfile); } - VIR_FORCE_CLOSE(pidfd); VIR_FORCE_CLOSE(errfd); return ret; } --=20 2.24.1 From nobody Mon May 6 06:30:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1584116973; cv=none; d=zohomail.com; s=zohoarc; b=FvyTZHLMIxZI9QA/9NEyy1QTzG0xxbmhn1M9wckCGqPCwCJyGtjApvZrnkSePBLPFHk/JkkNiY8kQQ1LNMmrZG0A1eAo4wflf6CjnWLjEtIErJ1YkDgT/ipysdDjdJEIEtvBAw0wgwSegGP6xBkpg/S+BCm6TtLIC4YQ7bAlfxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584116973; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UWhYFPNDWref0T2FeB8iR4x/GlcZGn4HDPWw5+ueG1w=; b=Ce65DGGTXqFS4Suha6gLHX40S2I9Wi7KPtx+dhyY7iF+hqOfMqUWrmFb7tZ6/ykeuucQ6QTOQCm6WZsUksSQKx06jhOxOXuSAvwBQuER5z7SiXuFyiHylfpw7+YbDU6OdGV6P+7BxBUtT2mB857NPvuWB23jr5/b0dLe7KSaRMo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 158411697362473.75346536620486; Fri, 13 Mar 2020 09:29:33 -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-446-mG4qUjUxMDaLvPdfTbZUHA-1; Fri, 13 Mar 2020 12:29:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C893C8017CC; Fri, 13 Mar 2020 16:29:24 +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 925B360F82; Fri, 13 Mar 2020 16:29:24 +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 32A4F18089CE; Fri, 13 Mar 2020 16:29:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02DGT0PY010879 for ; Fri, 13 Mar 2020 12:29:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id E15DC1001902; Fri, 13 Mar 2020 16:29:00 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65DF2100164D for ; Fri, 13 Mar 2020 16:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584116972; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=UWhYFPNDWref0T2FeB8iR4x/GlcZGn4HDPWw5+ueG1w=; b=QBqWbkyYJ85vR31s5IMGITr1T3hewG0Rp973jr/6+WRKjU4ZO5kzjkr3BKZUN4vgH8jsfm aJaFTIZPCfuN6PAIUWAh3bS+mbDPPtNcxeLBiPXCqW8nUkSMjZK2mwDttgPhstdIBuXq3e HXXFmyDZzeaxeRz3nOsJRqR5knZ/W0Y= X-MC-Unique: mG4qUjUxMDaLvPdfTbZUHA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/5] qemuSlirpStop: Simplify helper kill Date: Fri, 13 Mar 2020 17:28:51 +0100 Message-Id: <24bae1cc72521b2df1052ee8cfba461a62c62a62.1584116228.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.79 on 10.5.11.12 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" Now, that we know that the slirp helper will have the pidfile open and locked we can use virPidFileForceCleanupPath() to kill it and unlink the pidfile. Signed-off-by: Michal Privoznik --- src/qemu/qemu_slirp.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_slirp.c b/src/qemu/qemu_slirp.c index 5266b36eaa..be586ade12 100644 --- a/src/qemu/qemu_slirp.c +++ b/src/qemu/qemu_slirp.c @@ -246,8 +246,6 @@ qemuSlirpStop(qemuSlirpPtr slirp, g_autofree char *dbus_path =3D NULL; g_autofree char *id =3D qemuSlirpGetDBusVMStateId(net); virErrorPtr orig_err; - pid_t pid; - int rc; =20 if (!(pidfile =3D qemuSlirpCreatePidFilename(cfg, vm->def, net->info.a= lias))) { VIR_WARN("Unable to construct slirp pidfile path"); @@ -261,17 +259,11 @@ qemuSlirpStop(qemuSlirpPtr slirp, } =20 virErrorPreserveLast(&orig_err); - rc =3D virPidFileReadPathIfAlive(pidfile, &pid, cfg->slirpHelperName); - if (rc >=3D 0 && pid !=3D (pid_t) -1) - virProcessKillPainfully(pid, true); - - if (unlink(pidfile) < 0 && - errno !=3D ENOENT) { - virReportSystemError(errno, - _("Unable to remove stale pidfile %s"), - pidfile); + if (virPidFileForceCleanupPath(pidfile) < 0) { + VIR_WARN("Unable to kill slirp process"); + } else { + slirp->pid =3D 0; } - slirp->pid =3D 0; =20 dbus_path =3D qemuSlirpGetDBusPath(cfg, vm->def, net->info.alias); if (dbus_path) { --=20 2.24.1 From nobody Mon May 6 06:30:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1584117369; cv=none; d=zohomail.com; s=zohoarc; b=Mgo8N/+EUxRv60YwadIrqmYLphAcaqLox682tDn5iiQfY6HhypIt5e8nRVuUL1vo33S6hDgErD+ErMTWwacAmnO7vsbgu4jOcvoePZbqOhrpD4bQfHmnMiL/Jl8Z2fmfah/ZhQPsKny0ao5m+ORvLtAuBx3zgBczzjoys/B5OVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584117369; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TjY0Y3l2JT59pBqVcUFtpa7NoTG1ze1pdxr7jch7oOU=; b=hCX0FaLJEA6P4/KD8y6kXpkmhMSr4INmW8h8xhIzDhRYJ1N039Cukh39cqryN352jdYxNBvIxrYXERgGB9bW/3bfs0Z3e2ndHYd0sler+BsGtNA6bnqRbdt+3QMDNGDg3wDWk8ISb1dxVGIVj1DClIcLNEYUIoh2U6jSxswsick= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1584117369383592.9395888866314; Fri, 13 Mar 2020 09:36:09 -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-37-VIRVq2b2MB6KcQJoorZdLw-1; Fri, 13 Mar 2020 12:29:34 -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 EB6BA802569; Fri, 13 Mar 2020 16:29:28 +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 BAC1919757; Fri, 13 Mar 2020 16:29:28 +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 5B5B918089D5; Fri, 13 Mar 2020 16:29:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02DGT1s1010892 for ; Fri, 13 Mar 2020 12:29:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id B45741001902; Fri, 13 Mar 2020 16:29:01 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A926100164D for ; Fri, 13 Mar 2020 16:29:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584117368; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=TjY0Y3l2JT59pBqVcUFtpa7NoTG1ze1pdxr7jch7oOU=; b=HQ66By7Oorvte87RTGmcqLaefPK+Pf/fCrWeA+KhEjUtTp5xSYadbol95kYKsO+ynwjD/Y m4vzRqXY97hnHHmKlDB6OeyxrU+NRUzYot74ivuLunV+v9HVt7siIMmldAKideCT0EnNZd D9nwKEO1QZaDgaMWt5XtqCPxj5rdmyo= X-MC-Unique: VIRVq2b2MB6KcQJoorZdLw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/5] qemuVirtioFSStop: Simplify daemon kill Date: Fri, 13 Mar 2020 17:28:52 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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" Now, that we know that the virtiofsd will have the pidfile open and locked we can use virPidFileForceCleanupPath() to kill it and unlink the pidfile. Signed-off-by: Michal Privoznik --- src/qemu/qemu_virtiofs.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_virtiofs.c b/src/qemu/qemu_virtiofs.c index d579ce1d33..bbe93e0186 100644 --- a/src/qemu/qemu_virtiofs.c +++ b/src/qemu/qemu_virtiofs.c @@ -36,6 +36,8 @@ =20 #define VIR_FROM_THIS VIR_FROM_QEMU =20 +VIR_LOG_INIT("qemu.virtiofs"); + =20 char * qemuVirtioFSCreatePidFilename(virDomainObjPtr vm, @@ -275,28 +277,19 @@ qemuVirtioFSStop(virQEMUDriverPtr driver G_GNUC_UNUSE= D, { g_autofree char *pidfile =3D NULL; virErrorPtr orig_err; - pid_t pid =3D -1; - int rc; =20 virErrorPreserveLast(&orig_err); =20 if (!(pidfile =3D qemuVirtioFSCreatePidFilename(vm, fs->info.alias))) goto cleanup; =20 - rc =3D virPidFileReadPathIfAlive(pidfile, &pid, NULL); - if (rc >=3D 0 && pid !=3D (pid_t) -1) - virProcessKillPainfully(pid, true); - - if (unlink(pidfile) < 0 && - errno !=3D ENOENT) { - virReportSystemError(errno, - _("Unable to remove stale pidfile %s"), - pidfile); + if (virPidFileForceCleanupPath(pidfile) < 0) { + VIR_WARN("Unable to kill virtiofsd process"); + } else { + if (QEMU_DOMAIN_FS_PRIVATE(fs)->vhostuser_fs_sock) + unlink(QEMU_DOMAIN_FS_PRIVATE(fs)->vhostuser_fs_sock); } =20 - if (QEMU_DOMAIN_FS_PRIVATE(fs)->vhostuser_fs_sock) - unlink(QEMU_DOMAIN_FS_PRIVATE(fs)->vhostuser_fs_sock); - cleanup: virErrorRestore(&orig_err); } --=20 2.24.1 From nobody Mon May 6 06:30:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1584116984; cv=none; d=zohomail.com; s=zohoarc; b=IiSjMsTTUUUPK/JGPecLHqTmjRYo2b1Q70dQ1aG4DckvJTVLuaY1zI4oE7Hu0JcH3237XRIg7ST3oSNgFYznlGzFZP7RJjs7ZwJ0i8g5SnRoHLJVYlaQt+YLQ+VsCQHE6JYW89WBRdpkwp/Bf5pRoqHhyhDW/b4BKS4lKAe0aOg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584116984; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=b5gogqGTifZlcGdAgbZyRrvoL2YufhxNQMVOimEWfWo=; b=KVZIeFh30QJUKUOvcKVn+r0ktW4WZlXcDkVsAguQPV1rjqXAtc4E2mPUHzrX6OwahhX/KihXzJomnr0R2lZ1SjktFrR4r0BWshJTgCSu5oATZ9mat5w0UgoCy05U2AsEjeu1HH8Gm/i5bmG+K0Y79dz/wTtj41+2/iFkNYv3hoU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 158411698471168.58496932911203; Fri, 13 Mar 2020 09:29:44 -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-432--7YsTlv_Nlq4ASq_7o7DXQ-1; Fri, 13 Mar 2020 12:29:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A3464107ACC7; Fri, 13 Mar 2020 16:29:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75B968FC06; Fri, 13 Mar 2020 16:29:35 +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 0CA8185EC0; Fri, 13 Mar 2020 16:29:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02DGT2BN010904 for ; Fri, 13 Mar 2020 12:29:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8ACF3100164D; Fri, 13 Mar 2020 16:29:02 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10F651001902 for ; Fri, 13 Mar 2020 16:29:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584116983; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=b5gogqGTifZlcGdAgbZyRrvoL2YufhxNQMVOimEWfWo=; b=LXDFJnD+jeES4ZWqeESS7AcfPub17GWJuPM+uR3Nj703keAItoiDKpKTugnVitDFs82nW8 SEJbCpnsq2gfgsKRGhlcrthDzHJrnC3hXVGfr4teW+FSN3t58z8ND8xPWOjmJK71MTWvlc hcux6M5pogDQgItKiCGwBfxiSI9k9fI= X-MC-Unique: -7YsTlv_Nlq4ASq_7o7DXQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/5] bridge_driver: Replace and drop networkKillDaemon Date: Fri, 13 Mar 2020 17:28:53 +0100 Message-Id: <26ec634fea69404e6496810d68c5ea9b0ecb1027.1584116228.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.79 on 10.5.11.11 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" In the network driver code there's networkKillDaemon() which is the same as virProcessKillPainfully(). Replace the former with the later and drop what becomes unused function. Signed-off-by: Michal Privoznik --- src/network/bridge_driver.c | 107 ++++++------------------------------ 1 file changed, 18 insertions(+), 89 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 369e80a889..f06099297a 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -966,68 +966,6 @@ static int networkConnectIsAlive(virConnectPtr conn G_= GNUC_UNUSED) } =20 =20 -/* networkKillDaemon: - * - * kill the specified pid/name, and wait a bit to make sure it's dead. - */ -static int -networkKillDaemon(pid_t pid, - const char *daemonName, - const char *networkName) -{ - size_t i; - int ret =3D -1; - const char *signame =3D "TERM"; - - /* send SIGTERM, then wait up to 3 seconds for the process to - * disappear, send SIGKILL, then wait for up to another 2 - * seconds. If that fails, log a warning and continue, hoping - * for the best. - */ - for (i =3D 0; i < 25; i++) { - int signum =3D 0; - if (i =3D=3D 0) { - signum =3D SIGTERM; - } else if (i =3D=3D 15) { - signum =3D SIGKILL; - signame =3D "KILL"; - } - if (kill(pid, signum) < 0) { - if (errno =3D=3D ESRCH) { - ret =3D 0; - } else { - char ebuf[1024]; - VIR_WARN("Failed to terminate %s process %d " - "for network '%s' with SIG%s: %s", - daemonName, pid, networkName, signame, - virStrerror(errno, ebuf, sizeof(ebuf))); - } - return ret; - } - /* NB: since networks have no reference count like - * domains, there is no safe way to unlock the network - * object temporarily, and so we can't follow the - * procedure used by the qemu driver of 1) unlock driver - * 2) sleep, 3) add ref to object 4) unlock object, 5) - * re-lock driver, 6) re-lock object. We may need to add - * that functionality eventually, but for now this - * function is rarely used and, at worst, leaving the - * network driver locked during this loop of sleeps will - * have the effect of holding up any other thread trying - * to make modifications to a network for up to 5 seconds; - * since modifications to networks are much less common - * than modifications to domains, this seems a reasonable - * tradeoff in exchange for less code disruption. - */ - g_usleep(20 * 1000); - } - VIR_WARN("Timed out waiting after SIG%s to %s process %d " - "(network '%s')", - signame, daemonName, pid, networkName); - return ret; -} - - /* the following does not build a file, it builds a list * which is later saved into a file */ @@ -1833,12 +1771,11 @@ static int networkRestartDhcpDaemon(virNetworkDriverStatePtr driver, virNetworkObjPtr obj) { - virNetworkDefPtr def =3D virNetworkObjGetDef(obj); pid_t dnsmasqPid =3D virNetworkObjGetDnsmasqPid(obj); =20 /* if there is a running dnsmasq, kill it */ if (dnsmasqPid > 0) { - networkKillDaemon(dnsmasqPid, "dnsmasq", def->name); + virProcessKillPainfully(dnsmasqPid, false); virNetworkObjSetDnsmasqPid(obj, -1); } /* now start dnsmasq if it should be started */ @@ -2067,23 +2004,19 @@ networkRefreshRadvd(virNetworkDriverStatePtr driver, { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); dnsmasqCapsPtr dnsmasq_caps =3D networkGetDnsmasqCaps(driver); - char *radvdpidbase; + g_autofree char *radvdpidbase =3D NULL; + g_autofree char *pidfile =3D NULL; pid_t radvdPid; =20 /* Is dnsmasq handling RA? */ if (DNSMASQ_RA_SUPPORT(dnsmasq_caps)) { virObjectUnref(dnsmasq_caps); - radvdPid =3D virNetworkObjGetRadvdPid(obj); - if (radvdPid <=3D 0) - return 0; - /* radvd should not be running but in case it is */ - if ((networkKillDaemon(radvdPid, "radvd", def->name) >=3D 0) && - ((radvdpidbase =3D networkRadvdPidfileBasename(def->name)) - !=3D NULL)) { - virPidFileDelete(driver->pidDir, radvdpidbase); - VIR_FREE(radvdpidbase); + if ((radvdpidbase =3D networkRadvdPidfileBasename(def->name)) && + (pidfile =3D virPidFileBuildPath(driver->pidDir, radvdpidbase)= )) { + /* radvd should not be running but in case it is */ + virPidFileForceCleanupPath(pidfile); + virNetworkObjSetRadvdPid(obj, -1); } - virNetworkObjSetRadvdPid(obj, -1); return 0; } virObjectUnref(dnsmasq_caps); @@ -2111,23 +2044,19 @@ static int networkRestartRadvd(virNetworkObjPtr obj) { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); - char *radvdpidbase; - pid_t radvdPid =3D virNeworkObjGetRadvdPid(obj); + g_autofree char *radvdpidbase =3D NULL; + g_autofree char *pidfile =3D NULL; =20 - /* if there is a running radvd, kill it */ - if (radvdPid > 0) { - /* essentially ignore errors from the following two functions, - * since there's really no better recovery to be done than to - * just push ahead (and that may be exactly what's needed). - */ - if ((networkKillDaemon(radvdPid, "radvd", def->name) >=3D 0) && - ((radvdpidbase =3D networkRadvdPidfileBasename(def->name)) - !=3D NULL)) { - virPidFileDelete(driver->pidDir, radvdpidbase); - VIR_FREE(radvdpidbase); - } + /* If there is a running radvd, kill it. Essentially ignore errors fro= m the + * following two functions, since there's really no better recovery to= be + * done than to just push ahead (and that may be exactly what's needed= ). + */ + if ((radvdpidbase =3D networkRadvdPidfileBasename(def->name)) && + (pidfile =3D virPidFileBuildPath(driver->pidDir, radvdpidbase))) { + virPidFileForceCleanupPath(pidfile); virNetworkObjSetRadvdPid(obj, -1); } + /* now start radvd if it should be started */ return networkStartRadvd(obj); } --=20 2.24.1