[PATCH] Ensure binary is resolved wrt $PATH in virExec

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



virExec would only resolved the binary to $PATH if no env
variables were being set. Since there is no execvep() API
in POSIX, we use virFindFileInPath to manually resolve
the binary and then use execv() instead of execvp().
---
 src/util/util.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/util/util.c b/src/util/util.c
index e573f4a..a30a542 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -475,6 +475,18 @@ __virExec(const char *const*argv,
     int childout = -1;
     int childerr = -1;
     int tmpfd;
+    const char *binary = NULL;
+
+    if (argv[0][0] != '/') {
+        if (!(binary = virFindFileInPath(argv[0]))) {
+            virReportSystemError(ENOENT,
+                                 _("Cannot find '%s' in path"),
+                                 argv[0]);
+            return -1;
+        }
+    } else {
+        binary = argv[0];
+    }
 
     if ((null = open("/dev/null", O_RDWR)) < 0) {
         virReportSystemError(errno,
@@ -694,9 +706,9 @@ __virExec(const char *const*argv,
     virLogReset();
 
     if (envp)
-        execve(argv[0], (char **) argv, (char**)envp);
+        execve(binary, (char **) argv, (char**)envp);
     else
-        execvp(argv[0], (char **) argv);
+        execv(binary, (char **) argv);
 
     virReportSystemError(errno,
                          _("cannot execute binary %s"),
-- 
1.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]