render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 5d90f461a7356560361dab522273ff5aabbfeefe Mon Sep 17 00:00:00 2001
Message-Id: <5d90f461a7356560361dab522273ff5aabbfeefe@dist-git>
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
Date: Thu, 5 Aug 2021 13:49:44 +0200
Subject: [PATCH] util: Introduce virProcessGroupKill
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit fc180c741f27fb24419a69f53ef682fade699b52)
Signed-off-by: Ján Tomko <jtomko@redhat.com>

https://bugzilla.redhat.com/show_bug.cgi?id=1940276
Message-Id: <ff031bb30c28c42566086a0fce4439f80a0bb645.1628164129.git.jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/util/virprocess.c    | 17 +++++++++++++++++
 src/util/virprocess.h    |  1 +
 3 files changed, 19 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0f701ed1ae..b5e86019a5 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3069,6 +3069,7 @@ virProcessGetMaxMemLock;
 virProcessGetNamespaces;
 virProcessGetPids;
 virProcessGetStartTime;
+virProcessGroupKill;
 virProcessKill;
 virProcessKillPainfully;
 virProcessKillPainfullyDelay;
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 67dd599b3e..5f01dd1f67 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -361,6 +361,23 @@ int virProcessKill(pid_t pid, int sig)
 }
 
 
+/* send signal to a process group */
+int virProcessGroupKill(pid_t pid, int sig G_GNUC_UNUSED)
+{
+    if (pid <= 1) {
+        errno = ESRCH;
+        return -1;
+    }
+
+#ifdef WIN32
+    errno = ENOSYS;
+    return -1;
+#else
+    return killpg(pid, sig);
+#endif
+}
+
+
 /*
  * Try to kill the process and verify it has exited
  *
diff --git a/src/util/virprocess.h b/src/util/virprocess.h
index d16e8b23bb..0359d7fd9f 100644
--- a/src/util/virprocess.h
+++ b/src/util/virprocess.h
@@ -52,6 +52,7 @@ virProcessWait(pid_t pid, int *exitstatus, bool raw)
     G_GNUC_WARN_UNUSED_RESULT;
 
 int virProcessKill(pid_t pid, int sig);
+int virProcessGroupKill(pid_t pid, int sig);
 
 int virProcessKillPainfully(pid_t pid, bool force);
 int virProcessKillPainfullyDelay(pid_t pid,
-- 
2.32.0