diff options
author | Sam Bingner <sam@bingner.com> | 2018-12-28 13:35:09 -1000 |
---|---|---|
committer | Sam Bingner <sam@bingner.com> | 2020-07-17 00:22:23 -1000 |
commit | cdd93209431f84bb0c59d5ef2b57802f3ee48c95 (patch) | |
tree | 0e1bf5f471837b09706e37239d07f6fed46d9229 | |
parent | 0c5bc15b2d8158f4eeec5db6718246e6924243ec (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 9005b81b5..e003f8cb4 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -30,6 +30,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 |