summaryrefslogtreecommitdiff
path: root/data/_dpkg/runcmd.diff
blob: 0d174c7138f4694f483bb7c01d949c62fd9d1309 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
diff -ur dpkg-1.18.25/lib/dpkg/command.c dpkg-1.18.25+iPhone/lib/dpkg/command.c
--- dpkg-1.18.25/lib/dpkg/command.c	2018-03-21 18:29:34.000000000 -1000
+++ dpkg-1.18.25+iPhone/lib/dpkg/command.c	2019-03-29 22:10:21.000000000 -1000
@@ -18,6 +18,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+#include <sys/errno.h>
 #include <config.h>
 #include <compat.h>
 
@@ -179,7 +180,24 @@
 command_exec(struct command *cmd)
 {
 	execvp(cmd->filename, (char * const *)cmd->argv);
-	ohshite(_("unable to execute %s (%s)"), cmd->name, cmd->filename);
+	if (errno == EPERM || errno == ENOEXEC) {
+		const char *shell;
+		if (access(DEFAULTSHELL, X_OK) == 0) {
+			shell = DEFAULTSHELL;
+		} else if (access("/etc/alternatives/sh", X_OK) == 0) {
+			shell = "/etc/alternatives/sh";
+		} else if (access("/bin/bash", X_OK) == 0) {
+			shell = "/bin/bash";
+		} else {
+			ohshite(_("unable to execute %s (%s): no shell!"), cmd->name, cmd->filename);
+		}
+		struct command newcmd;
+		command_init(&newcmd, shell, NULL);
+		command_add_args(&newcmd, shell, "-c", "\"$0\" \"$@\"", NULL);
+		command_add_argl(&newcmd, cmd->argv);
+		execvp(shell, (char * const *)newcmd.argv);
+		ohshite(_("unable to execute %s (%s)"), cmd->name, cmd->filename);
+	}
 }