[PATCH v4 15/20] tests: mock execv/execve

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

 



From: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>

Learn to override the paths to the program to execute (vhost-user
helpers are executed to check for runtime capabilities).

Signed-off-by: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>
---
 tests/virfilewrapper.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/tests/virfilewrapper.c b/tests/virfilewrapper.c
index 160cd571e0..3d3f319f2c 100644
--- a/tests/virfilewrapper.c
+++ b/tests/virfilewrapper.c
@@ -44,6 +44,8 @@ static FILE *(*real_fopen)(const char *path, const char *mode);
 static int (*real_access)(const char *path, int mode);
 static int (*real_mkdir)(const char *path, mode_t mode);
 static DIR *(*real_opendir)(const char *path);
+static int (*real_execv)(const char *path, char *const argv[]);
+static int (*real_execve)(const char *path, char *const argv[], char *const envp[]);
 
 static void init_syms(void)
 {
@@ -55,6 +57,8 @@ static void init_syms(void)
     VIR_MOCK_REAL_INIT(mkdir);
     VIR_MOCK_REAL_INIT(open);
     VIR_MOCK_REAL_INIT(opendir);
+    VIR_MOCK_REAL_INIT(execv);
+    VIR_MOCK_REAL_INIT(execve);
 }
 
 
@@ -191,4 +195,22 @@ DIR *opendir(const char *path)
     return real_opendir(newpath ? newpath : path);
 }
 
+int execv(const char *path, char *const argv[])
+{
+    VIR_AUTOFREE(char *) newpath = NULL;
+
+    PATH_OVERRIDE(newpath, path);
+
+    return real_execv(newpath ? newpath : path, argv);
+}
+
+int execve(const char *path, char *const argv[], char *const envp[])
+{
+    VIR_AUTOFREE(char *) newpath = NULL;
+
+    PATH_OVERRIDE(newpath, path);
+
+    return real_execve(newpath ? newpath : path, argv, envp);
+}
+
 #endif
-- 
2.23.0

--
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]

  Powered by Linux