[libvirt PATCH 03/17] util: Always pass a pid to virProcessSetMax*()

Andrea Bolognani abologna at redhat.com
Fri Mar 5 19:13:50 UTC 2021


Currently, the functions accept either an explicit pid or zero,
in which case the current process should be modified: the latter
might sound like a convenient little feature, but in reality
obtaining the pid of the current process is a single additional
function call away, so it hardly makes a difference.

Removing the few cases in which we're passing zero will allow us
to simplify and improve the functions later.

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 src/util/vircommand.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 1a4b77ea24..3eef0767bb 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -780,11 +780,13 @@ virExec(virCommandPtr cmd)
         }
     }
 
+    pid = getpid();
+
     if (cmd->pidfile) {
         int pidfilefd = -1;
         char c;
 
-        pidfilefd = virPidFileAcquirePath(cmd->pidfile, false, getpid());
+        pidfilefd = virPidFileAcquirePath(cmd->pidfile, false, pid);
         if (pidfilefd < 0)
             goto fork_error;
         if (virSetInherit(pidfilefd, true) < 0) {
@@ -804,14 +806,14 @@ virExec(virCommandPtr cmd)
         /* pidfilefd is intentionally leaked. */
     }
 
-    if (virProcessSetMaxMemLock(0, cmd->maxMemLock) < 0)
+    if (virProcessSetMaxMemLock(pid, cmd->maxMemLock) < 0)
         goto fork_error;
-    if (virProcessSetMaxProcesses(0, cmd->maxProcesses) < 0)
+    if (virProcessSetMaxProcesses(pid, cmd->maxProcesses) < 0)
         goto fork_error;
-    if (virProcessSetMaxFiles(0, cmd->maxFiles) < 0)
+    if (virProcessSetMaxFiles(pid, cmd->maxFiles) < 0)
         goto fork_error;
     if (cmd->setMaxCore &&
-        virProcessSetMaxCoreSize(0, cmd->maxCore) < 0)
+        virProcessSetMaxCoreSize(pid, cmd->maxCore) < 0)
         goto fork_error;
 
     if (cmd->hook) {
-- 
2.26.2




More information about the libvir-list mailing list