From nobody Fri Apr 19 20:42:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 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=1584980036; cv=none; d=zohomail.com; s=zohoarc; b=OChhT7nSkldCMwLb+7ownnkqog8lobCVICCVzrq2il/yD6DyjyYA2snEWbRkkqN2myHRJiDtQY8ebqDl72EFjC4w/U7wDsci9HQg8KH5KRQtc/O+zFHb3WN5DsU8WGWoKrHJq95IiZ/GvBXAzksSwHv+9Tib3/Jh+btsKpRUOrA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584980036; 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=My+47DyV2u8xhbDBsS5tJ2vK1ehy0F3jX8T/yhlfI+E=; b=EeMTZpwRpYBFs1BPndD9tfEf06+slutERFZ685FH0AOnlZa6iVjDPfWCo7A9gQeF+t3uJqvWKVvgccVOafC9utJruIzH4KzKBoJPugBWR910tgoO/yu2I87PJ3ZpSXQTS1zZp+JabaA1rcThYeSN6/8l6KJ21HLscZ2RqG3MyMQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 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-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1584980036494641.9994906544371; Mon, 23 Mar 2020 09:13:56 -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-423-vITlVegTNyy3o779PDrmsg-1; Mon, 23 Mar 2020 12:13:52 -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 568E0149C2; Mon, 23 Mar 2020 16:13:46 +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 2C5019B921; Mon, 23 Mar 2020 16:13:46 +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 D1E0018089CD; Mon, 23 Mar 2020 16:13:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02NGDeGQ005208 for ; Mon, 23 Mar 2020 12:13:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id E272494B30; Mon, 23 Mar 2020 16:13:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F34F9497F for ; Mon, 23 Mar 2020 16:13:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584980035; 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=My+47DyV2u8xhbDBsS5tJ2vK1ehy0F3jX8T/yhlfI+E=; b=XWlChh5g7AJcWISVZpWhr24pGrlYfBJpnmUeyzll24PQl2nykEYs1D15O2P3R2xLxwE8A+ Jcjm2NfrDGQLYhPAg1pgwNVKa7LXX2nqhYdPj60sfPt++o5zqAXHnchlHXG6+iU1IiA5Ow 8JD7cydxyUM116W2jn2kWFUOA82NdwM= X-MC-Unique: vITlVegTNyy3o779PDrmsg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH RESEND 1/5] virCommand: Actually acquire pidfile instead of just writing it Date: Mon, 23 Mar 2020 17:13:30 +0100 Message-Id: <6a6a7d380aecd1cf644cf04fd61a6622bc9b5d64.1584979958.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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" 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 Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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 9ffa0cf49b..77078d09fb 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 Fri Apr 19 20:42:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 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=1584980033; cv=none; d=zohomail.com; s=zohoarc; b=A1achMz7mC78Bx9eNowEF1vtFVlgWPtoQfrG83f90LngmjPvKER6/NQm5mRijjI02IU4GGScWkpdjHkyfnQqZLiBNd5lugQyL8KWJuErLyxARbtdX4VnKZNGuAEWPG/0sFt5yx2gjYKGiOZHXDlrXUydYLH7yUHpji0XTmdlkDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584980033; 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=tCb7AhRvDfRv1GJPSfl6OJvFwI8mpzRqw5RxLsFclTI=; b=POidNyT0STBEv44jdXme8UnrRLrZ65p385Z7B6yTZ5rtL+kYlN38Q4xVQPWwo2I18dfUm25bBj4GlWLVqqHDfup1C01PLyiO047m6cF7O8Ou6K1v+Fly2k5A5+HRBXXM7/kUkypGIe0dAxaCjAlRZ1m5Y5HoWE4HF8+2lf0QPs0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 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-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584980033572507.0892683799258; Mon, 23 Mar 2020 09:13:53 -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-128-iVje9G68Mc2AW6HWq2QZwQ-1; Mon, 23 Mar 2020 12:13:49 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 66998107ACCA; Mon, 23 Mar 2020 16:13:44 +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 361505C28F; Mon, 23 Mar 2020 16:13:44 +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 C701C86386; Mon, 23 Mar 2020 16:13:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02NGDf07005216 for ; Mon, 23 Mar 2020 12:13:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id C3E379497F; Mon, 23 Mar 2020 16:13:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 427D394B30 for ; Mon, 23 Mar 2020 16:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584980032; 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=tCb7AhRvDfRv1GJPSfl6OJvFwI8mpzRqw5RxLsFclTI=; b=JxwpwZZPxBMvnFvE8r+SY7jRsCPlKGF768NitrpnMdfVT/O4UgrBUFlq7xRlWUq9EFbcOb pqzqoP6B8YCg5Gmd15811Oop5n9lDXfgF10/RN8OZ3jbKhinPEE6RzcS1dJoup8lScmOYx s8qVYBzXu08N57gMnDeb8aZVBYxkg0E= X-MC-Unique: iVje9G68Mc2AW6HWq2QZwQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH RESEND 2/5] qemuProcessStartManagedPRDaemon: Don't pass -f pidfile to the daemon Date: Mon, 23 Mar 2020 17:13:31 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.16 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 Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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 e8401030a2..0324857913 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2850,7 +2850,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; @@ -2869,10 +2868,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 @@ -2887,13 +2882,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 @@ -2956,7 +2948,6 @@ qemuProcessStartManagedPRDaemon(virDomainObjPtr vm) if (pidfile) unlink(pidfile); } - VIR_FORCE_CLOSE(pidfd); VIR_FORCE_CLOSE(errfd); return ret; } --=20 2.24.1 From nobody Fri Apr 19 20:42:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 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=1584980037; cv=none; d=zohomail.com; s=zohoarc; b=AoSQedIxMzzNOv3pxEeyk87EJikOnboyLVjQGozLvYlVgsYbDxYSDvy7jg51aIxuQD8llAXB+dQBKdWn4lIoCT8E3ioq0IGEXkzymI4fIRrpSTX24a+fb7MOEAEI5i6f9GDyWjHGxBEcPsOTrbejkzLGb2DLbFL7Pesy/B0iclY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584980037; 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=LU9u/OmoTV6PQU9RLHOYKOOoLu8kZp7l+sVtzFb8gLEP0PmPkyCWYqEQkWTdZcN2HgndkD3APZlROHy42MIQ8g6mPkPKhXnI7QD1m/myHjiEVykEGPKLWSzAEje4I8jt0TGnAJ36xwhjuADh4vJqXV3MljW2yGV15G2N7xtxElE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 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-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584980037065257.8873834603396; Mon, 23 Mar 2020 09:13:57 -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-354-Ji-FfHPGPsuvC9rMFlJcvQ-1; Mon, 23 Mar 2020 12:13:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8E6DF107ACCD; Mon, 23 Mar 2020 16:13:45 +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 64CA7BBBE6; Mon, 23 Mar 2020 16:13:45 +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 1009D8639F; Mon, 23 Mar 2020 16:13:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02NGDgYg005230 for ; Mon, 23 Mar 2020 12:13:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id A69AA94B30; Mon, 23 Mar 2020 16:13:42 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 250789497F for ; Mon, 23 Mar 2020 16:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584980033; 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=DDyMMoeYTO1I1FyC/89bMu5cPty3xD/TPu99hui7uNnlg1BJK5C2W6SAvYoXWw/XEYCnC3 8xaBwYQmHgvrmCTcuMdNcXNeB/19jmNIEbqxMVAh20v304oHIJu6vDvASzVn369mHAniN0 9YFVX4HzPOi9wB6869pEqFIeevimtHg= X-MC-Unique: Ji-FfHPGPsuvC9rMFlJcvQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH RESEND 3/5] qemuSlirpStop: Simplify helper kill Date: Mon, 23 Mar 2020 17:13:32 +0100 Message-Id: <4cebca147f2955ce4233eaf227fa40f434ec7b6e.1584979958.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.13 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 Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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 Fri Apr 19 20:42:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 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=1584980040; cv=none; d=zohomail.com; s=zohoarc; b=nxGpN4tSUO0lTR+ILRbNkGZ+jXAAdJAr1uNLzxYcitqTIHg9uLfwI6+f5IpMk/UFpq6mCsRJHnlNbJdyW9HO6pHb9mlgyT9vQpaYBaLkt8PvqjBzLHhi91M09nO7Tchagd/iOyElMDqXiOIj9fr/Yy7RU70VqXOsLZmZgD36kRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584980040; 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=Cu+X7g/N9EetF/TONiF+oabtlwU2QZgKs1Y3dlrGEyPOOwbyQzq2oexCIPmmEp3UeK9XXe9Y6B6LJ6/RBvVPRzom69uXyJOwx2GRAsEKNTHPK/iFVUrP2tsiM1k5rgfaK2gN8f2XFbrDcFe/q+G4r2AATh1QKq1+qUw7NDoJn4o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 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-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1584980040756147.6384708426981; Mon, 23 Mar 2020 09:14:00 -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-191-ll0v8u79Mem9FuKQNM1SHg-1; Mon, 23 Mar 2020 12:13:57 -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 BF3CA149DC; Mon, 23 Mar 2020 16:13:49 +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 3D8E8953A5; Mon, 23 Mar 2020 16:13:49 +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 ED5CD18089CF; Mon, 23 Mar 2020 16:13:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02NGDhfU005238 for ; Mon, 23 Mar 2020 12:13:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8A8C89497F; Mon, 23 Mar 2020 16:13:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06CC894B32 for ; Mon, 23 Mar 2020 16:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584980039; 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=Sn2KeEWYdpIll/Q1xoCpzC97H5u6rEbM+vijlmairkuAqfoCIYsaYbD7QBe7TFCY/7UdYd Dn8Vht0rcC3IS7syjuJokiNemgY6mxhJnFONc8ThMmRsNhGqFtaOL80n1t6e/J6mYJ1fw5 NizJEQc44SuhndKsuB3wP07Fz7py6rU= X-MC-Unique: ll0v8u79Mem9FuKQNM1SHg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH RESEND 4/5] qemuVirtioFSStop: Simplify daemon kill Date: Mon, 23 Mar 2020 17:13:33 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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 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 Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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 Fri Apr 19 20:42:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 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=1584980048; cv=none; d=zohomail.com; s=zohoarc; b=kJOtXjEI8tGq8ir2vcGNYz3oOQ4Gv77dclurkWdexY5TkHCQKk64o4smetzevpYc7IbOVpVci7mF9PV1OTdW78AjWlDnlPIJ0jfTvEjsJXi62UxQHzrMNhe5hDD95+LU4LlIySoQxviXLGB7BCOXSA9rGKOG26F1tzE6AThpTWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584980048; 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=/XuJMXlfP0xwHa0bl0c6QK17odL9lsZaoqyxGhODWMw=; b=HiSnzy0n4wNVMRn3e6LTDMcv4vi1J50h3KZl1wIIwCbmriF3nUtC9ly1JfUc19HYBZ+W4Cu5bV2bdLiCW/quDDuitB6emJQDlv9pJVh/0QqoheQ5VND2KO9QvsZ9iyGhamBdTfCJKMi+QOPzgYn1DGNyo3iJ8+5inJ+vhhPsK+w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 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-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1584980048341264.1602420310521; Mon, 23 Mar 2020 09:14: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-477-yHKyph8vOO--Uf6St4x-cg-1; Mon, 23 Mar 2020 12:14:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A120107ACCD; Mon, 23 Mar 2020 16:13:53 +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 DCF28BBBE6; Mon, 23 Mar 2020 16:13:52 +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 8597A863A8; Mon, 23 Mar 2020 16:13:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02NGDil0005250 for ; Mon, 23 Mar 2020 12:13:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6B41294B30; Mon, 23 Mar 2020 16:13:44 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD39B9497F for ; Mon, 23 Mar 2020 16:13:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584980047; 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=/XuJMXlfP0xwHa0bl0c6QK17odL9lsZaoqyxGhODWMw=; b=dazpEMm7Q8yc2poVcEp2rSpVbAu2BOyu6dbBuF0LqWKwzPU8kwBKbK0DRpWUkJOct9ZeQg u8bEnsh7RUssq6qw5sPve13JIpNMx0kUGmGd6Rjs2NGMS3/2/9OrXIVJcA0N/dJxS34cvE FjWt5XqvNtJKU+w1VJ5jp5+PMxHBENA= X-MC-Unique: yHKyph8vOO--Uf6St4x-cg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH RESEND 5/5] bridge_driver: Replace and drop networkKillDaemon Date: Mon, 23 Mar 2020 17:13:34 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.13 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 Reviewed-by: Marc-Andr=C3=A9 Lureau --- src/network/bridge_driver.c | 106 ++++++------------------------------ 1 file changed, 18 insertions(+), 88 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index ae52455761..f06099297a 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -966,67 +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 { - VIR_WARN("Failed to terminate %s process %d " - "for network '%s' with SIG%s: %s", - daemonName, pid, networkName, signame, - g_strerror(errno)); - } - 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 */ @@ -1832,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 */ @@ -2066,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); @@ -2110,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