From 463d3a6b9b960410d4a0304209f4e660d7f1faf2 Mon Sep 17 00:00:00 2001
Message-Id: <463d3a6b9b960410d4a0304209f4e660d7f1faf2@dist-git>
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
Date: Thu, 5 Aug 2021 13:49:45 +0200
Subject: [PATCH] util: introduce virProcessGroupGet
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 4b39c2aa2e840c9f0c51cf5a7a0d93de51ba8439)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
https://bugzilla.redhat.com/show_bug.cgi?id=1940276
Message-Id: <365bb0eb78d11505a2b0d6be798462e667074404.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 b5e86019a5..8b892cf255 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3069,6 +3069,7 @@ virProcessGetMaxMemLock;
virProcessGetNamespaces;
virProcessGetPids;
virProcessGetStartTime;
+virProcessGroupGet;
virProcessGroupKill;
virProcessKill;
virProcessKillPainfully;
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 5f01dd1f67..1bc840120a 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -378,6 +378,23 @@ int virProcessGroupKill(pid_t pid, int sig G_GNUC_UNUSED)
}
+/* get process group from a pid */
+pid_t virProcessGroupGet(pid_t pid)
+{
+ if (pid <= 1) {
+ errno = ESRCH;
+ return -1;
+ }
+
+#ifdef WIN32
+ errno = ENOSYS;
+ return -1;
+#else
+ return getpgid(pid);
+#endif
+}
+
+
/*
* Try to kill the process and verify it has exited
*
diff --git a/src/util/virprocess.h b/src/util/virprocess.h
index 0359d7fd9f..9d7c0f479a 100644
--- a/src/util/virprocess.h
+++ b/src/util/virprocess.h
@@ -53,6 +53,7 @@ virProcessWait(pid_t pid, int *exitstatus, bool raw)
int virProcessKill(pid_t pid, int sig);
int virProcessGroupKill(pid_t pid, int sig);
+pid_t virProcessGroupGet(pid_t pid);
int virProcessKillPainfully(pid_t pid, bool force);
int virProcessKillPainfullyDelay(pid_t pid,
--
2.32.0