libinterfork: add and execve override
[ust.git] / libinterfork / interfork.c
index e57b7e593c06664a5cf73313185ef6cea3462935..cfdd2c475b79ae016ff470c0bb04a4dd0b358bf2 100644 (file)
 #include <dlfcn.h>
 #include <unistd.h>
 #include <stdio.h>
+#include "share/usterr.h"
+
+extern void ust_fork(void);
+extern void ust_potential_exec(void);
 
 pid_t fork(void)
 {
@@ -30,11 +34,10 @@ pid_t fork(void)
                plibc_func = dlsym(RTLD_NEXT, "fork");
                if(plibc_func == NULL) {
                        fprintf(stderr, "libcwrap: unable to find fork\n");
-                       return NULL;
+                       return -1;
                }
        }
 
-       printf("IN FORK!\n");
        retval = plibc_func();
 
        if(retval == 0)
@@ -42,3 +45,24 @@ pid_t fork(void)
 
        return retval;
 }
+
+int execve(const char *filename, char *const argv[], char *const envp[])
+{
+       static int (*plibc_func)(const char *filename, char *const argv[], char *const envp[]) = NULL;
+
+       pid_t retval;
+
+       if(plibc_func == NULL) {
+               plibc_func = dlsym(RTLD_NEXT, "execve");
+               if(plibc_func == NULL) {
+                       fprintf(stderr, "libcwrap: unable to find execve\n");
+                       return -1;
+               }
+       }
+
+       ust_potential_exec();
+
+       retval = plibc_func(filename, argv, envp);
+
+       return retval;
+}
This page took 0.022739 seconds and 4 git commands to generate.