From bc59d0b407e644c0d75e5fa7fead4393e904f51e Mon Sep 17 00:00:00 2001 From: Enno Boland Date: Tue, 13 Aug 2019 13:56:32 +0200 Subject: [PATCH] lib/package_script.c: try to find a usable shell instead of using /bin/sh --- lib/package_script.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/package_script.c b/lib/package_script.c index a8c05dcf..d7306f0d 100644 --- a/lib/package_script.c +++ b/lib/package_script.c @@ -31,6 +31,13 @@ #include "xbps_api_impl.h" +const char *shells[] = { + "/bin/sh", + "/bin/dash", + "/bin/bash", + NULL +}; + int xbps_pkg_exec_buffer(struct xbps_handle *xhp, const void *blob, @@ -39,6 +46,7 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp, const char *action, bool update) { + int i; ssize_t ret; const char *tmpdir, *version; char *pkgname, *fpath; @@ -100,9 +108,27 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp, version = xbps_pkg_version(pkgver); assert(version); - rv = xbps_file_exec(xhp, "/bin/sh", fpath, action, pkgname, version, - update ? "yes" : "no", - "no", xhp->native_arch, NULL); + // find a shell that can be used to execute the script. + for (i = 0; shells[i] != NULL; i++) { + if (access(shells[i], X_OK) == 0) { + break; + } + } + if (shells[i] != NULL) { + rv = xbps_file_exec(xhp, shells[i], fpath, action, pkgname, version, + update ? "yes" : "no", + "no", xhp->native_arch, NULL); + } else if (access("/bin/busybox", X_OK) == 0) { + rv = xbps_file_exec(xhp, "/bin/busybox", "sh", fpath, action, pkgname, version, + update ? "yes" : "no", + "no", xhp->native_arch, NULL); + } else if (access("/bin/busybox.static", X_OK) == 0) { + rv = xbps_file_exec(xhp, "/bin/busybox.static", "sh", fpath, action, pkgname, version, + update ? "yes" : "no", + "no", xhp->native_arch, NULL); + } else { + rv = -1; + } free(pkgname); out: