diff options
author | Sam Bingner <sam@bingner.com> | 2018-12-28 13:35:09 -1000 |
---|---|---|
committer | Sam Bingner <sam@bingner.com> | 2019-01-22 08:45:24 -1000 |
commit | 6ff13d9bd5b09dd85f853ba543bfe350b06d186f (patch) | |
tree | abaa1fcf83ab9c374063548ba3d4616c8e16b4f3 | |
parent | b3d27b44eaa5986d1066257bf9cc020814f99275 (diff) |
Workaround for shell scripts
-rw-r--r-- | apt-pkg/contrib/fileutl.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 446120a3c..bb05239c9 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -31,6 +31,28 @@ #include <zlib.h> +#include <errno.h> +static inline int _execvp(const char *file, char *const argv[]) { + int rv = execvp(file, argv); + fprintf(stderr, "execvp failed, trying shell\n"); + if (errno == ENOEXEC || errno == EPERM) { + int argc; + for (argc = 0; argv[argc] != NULL; argc++); + char *newargv[argc+4]; + newargv[0] = "/bin/sh"; + newargv[1] = "-c"; + newargv[2] = "exec \"$0\" \"$@\""; + for (int i = 0; i<argc; i++) { + newargv[i+3] = argv[i]; + } + newargv[argc+3] = NULL; + return execvp(newargv[0], newargv); + } + return rv; +} + +#define execvp(x, y) _execvp(x, y) + #ifndef APT_8_CLEANER_HEADERS using std::string; #endif |