From a9b7300f6fac43011318554c0b942fa143b8a392 Mon Sep 17 00:00:00 2001 From: Matt Christ Date: Fri, 21 May 2021 12:59:30 -0500 Subject: brscan5: init at 1.2.6-0 --- pkgs/build-support/libredirect/libredirect.c | 81 +++++++++++++++++++++++++++- pkgs/build-support/libredirect/test.c | 6 +++ 2 files changed, 85 insertions(+), 2 deletions(-) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/libredirect/libredirect.c b/pkgs/build-support/libredirect/libredirect.c index c8d6956a6bfe..dfa2978e9f44 100644 --- a/pkgs/build-support/libredirect/libredirect.c +++ b/pkgs/build-support/libredirect/libredirect.c @@ -9,6 +9,7 @@ #include #include #include +#include #define MAX_REDIRECTS 128 @@ -189,9 +190,85 @@ int posix_spawnp(pid_t * pid, const char * file, return posix_spawnp_real(pid, rewrite(file, buf), file_actions, attrp, argv, envp); } -int execv(const char *path, char *const argv[]) +int execv(const char * path, char * const argv[]) { - int (*execv_real) (const char *path, char *const argv[]) = dlsym(RTLD_NEXT, "execv"); + int (*execv_real) (const char * path, char * const argv[]) = dlsym(RTLD_NEXT, "execv"); char buf[PATH_MAX]; return execv_real(rewrite(path, buf), argv); } + +int execvp(const char * path, char * const argv[]) +{ + int (*_execvp) (const char *, char * const argv[]) = dlsym(RTLD_NEXT, "execvp"); + char buf[PATH_MAX]; + return _execvp(rewrite(path, buf), argv); +} + +int execve(const char * path, char * const argv[], char * const envp[]) +{ + int (*_execve) (const char *, char * const argv[], char * const envp[]) = dlsym(RTLD_NEXT, "execve"); + char buf[PATH_MAX]; + return _execve(rewrite(path, buf), argv, envp); +} + +DIR * opendir(const char * path) +{ + char buf[PATH_MAX]; + DIR * (*_opendir) (const char*) = dlsym(RTLD_NEXT, "opendir"); + + return _opendir(rewrite(path, buf)); +} + +#define SYSTEM_CMD_MAX 512 + +char *replace_substring(char * source, char * buf, char * replace_string, char * start_ptr, char * suffix_ptr) { + char head[SYSTEM_CMD_MAX] = {0}; + strncpy(head, source, start_ptr - source); + + char tail[SYSTEM_CMD_MAX] = {0}; + if(suffix_ptr < source + strlen(source)) { + strcpy(tail, suffix_ptr); + } + + sprintf(buf, "%s%s%s", head, replace_string, tail); + return buf; +} + +char *replace_string(char * buf, char * from, char * to) { + int num_matches = 0; + char * matches[SYSTEM_CMD_MAX]; + int from_len = strlen(from); + for(int i=0; i #include #include +#include #include #include @@ -31,6 +32,10 @@ void test_execv(void) { assert(execv(TESTPATH, argv) == 0); } +void test_system(void) { + assert(system(TESTPATH) == 0); +} + int main(void) { FILE *testfp; @@ -50,6 +55,7 @@ int main(void) assert(stat(TESTPATH, &testsb) != -1); test_spawn(); + test_system(); test_execv(); /* If all goes well, this is never reached because test_execv() replaces -- cgit 1.4.1