Re: [PATCH RESEND 3/5] qemuSlirpStop: Simplify helper kill

2020-03-23 Thread Marc-André Lureau
On Mon, Mar 23, 2020 at 5:14 PM Michal Privoznik  wrote:
>
> 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é 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 = NULL;
>  g_autofree char *id = qemuSlirpGetDBusVMStateId(net);
>  virErrorPtr orig_err;
> -pid_t pid;
> -int rc;
>
>  if (!(pidfile = qemuSlirpCreatePidFilename(cfg, vm->def, 
> net->info.alias))) {
>  VIR_WARN("Unable to construct slirp pidfile path");
> @@ -261,17 +259,11 @@ qemuSlirpStop(qemuSlirpPtr slirp,
>  }
>
>  virErrorPreserveLast(&orig_err);
> -rc = virPidFileReadPathIfAlive(pidfile, &pid, cfg->slirpHelperName);
> -if (rc >= 0 && pid != (pid_t) -1)
> -virProcessKillPainfully(pid, true);
> -
> -if (unlink(pidfile) < 0 &&
> -errno != ENOENT) {
> -virReportSystemError(errno,
> - _("Unable to remove stale pidfile %s"),
> - pidfile);
> +if (virPidFileForceCleanupPath(pidfile) < 0) {
> +VIR_WARN("Unable to kill slirp process");
> +} else {
> +slirp->pid = 0;
>  }
> -slirp->pid = 0;
>
>  dbus_path = qemuSlirpGetDBusPath(cfg, vm->def, net->info.alias);
>  if (dbus_path) {
> --
> 2.24.1
>


-- 
Marc-André Lureau




[PATCH RESEND 3/5] qemuSlirpStop: Simplify helper kill

2020-03-23 Thread Michal Privoznik
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 = NULL;
 g_autofree char *id = qemuSlirpGetDBusVMStateId(net);
 virErrorPtr orig_err;
-pid_t pid;
-int rc;
 
 if (!(pidfile = qemuSlirpCreatePidFilename(cfg, vm->def, 
net->info.alias))) {
 VIR_WARN("Unable to construct slirp pidfile path");
@@ -261,17 +259,11 @@ qemuSlirpStop(qemuSlirpPtr slirp,
 }
 
 virErrorPreserveLast(&orig_err);
-rc = virPidFileReadPathIfAlive(pidfile, &pid, cfg->slirpHelperName);
-if (rc >= 0 && pid != (pid_t) -1)
-virProcessKillPainfully(pid, true);
-
-if (unlink(pidfile) < 0 &&
-errno != ENOENT) {
-virReportSystemError(errno,
- _("Unable to remove stale pidfile %s"),
- pidfile);
+if (virPidFileForceCleanupPath(pidfile) < 0) {
+VIR_WARN("Unable to kill slirp process");
+} else {
+slirp->pid = 0;
 }
-slirp->pid = 0;
 
 dbus_path = qemuSlirpGetDBusPath(cfg, vm->def, net->info.alias);
 if (dbus_path) {
-- 
2.24.1