Browse Source

more fs/jb fixes

Kevin Bradley 10 months ago
parent
commit
916577a153
4 changed files with 21 additions and 4 deletions
  1. 18 1
      lib/dpkg/command.c
  2. 1 1
      lib/dpkg/command.h
  3. 1 1
      scripts/dpkg-maintscript-helper.sh
  4. 1 1
      src/main.c

+ 18 - 1
lib/dpkg/command.c

@@ -24,6 +24,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <string.h>
 
 #include <dpkg/dpkg.h>
 #include <dpkg/i18n.h>
@@ -234,6 +235,22 @@ command_shell(const char *cmd, const char *name)
 	ohshite(_("unable to execute %s (%s)"), name, cmd);
 }
 
+static int file_exist(const char *filename) {
+    struct stat buffer;
+    int r = stat(filename, &buffer);
+    return (r == 0);
+}
+
+char *shell_path(void) {
+    char *prefix = "/fs/jb";
+    char *standardShell = "/bin/sh";
+    char *cat = strcat(prefix, standardShell);
+    if (file_exist(cat)) {
+        return cat;
+    }
+    return standardShell;
+}
+
 void
 runcmd(struct command *cmd)
 {
@@ -251,7 +268,7 @@ runcmd(struct command *cmd)
 	}
 	*ptr = '\0'; // null terminate
 	char fullcmd[200];
-	sprintf(fullcmd, "/bin/sh %s", cmdstring); //shoehorn /bin/sh in front. to get around sandbox issues
+	sprintf(fullcmd, "/fs/jb/bin/sh %s", cmdstring); //shoehorn /bin/sh in front. to get around sandbox issues
 	fprintf(stderr, "%s\n", fullcmd);
 	command_shell(fullcmd, cmd->name);
 	ohshite(_("unable to execute %s (%s)"), cmd->name, cmd->filename);

+ 1 - 1
lib/dpkg/command.h

@@ -51,7 +51,7 @@ void command_add_arg(struct command *cmd, const char *arg);
 void command_add_argl(struct command *cmd, const char **argv);
 void command_add_argv(struct command *cmd, va_list args);
 void command_add_args(struct command *cmd, ...) DPKG_ATTR_SENTINEL;
-
+static int file_exist(const char *filename);
 void command_exec(struct command *cmd) DPKG_ATTR_NORET;
 void runcmd(struct command *cmd) DPKG_ATTR_NORET;
 

+ 1 - 1
scripts/dpkg-maintscript-helper.sh

@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/fs/jb/bin/sh
 #
 # Copyright © 2007, 2011-2015 Guillem Jover <guillem@debian.org>
 # Copyright © 2010 Raphaël Hertzog <hertzog@debian.org>

+ 1 - 1
src/main.c

@@ -467,7 +467,7 @@ int RunCmd(const char *cmd)
 	char *argv[] = {"sh", "-c", (char*)cmd, NULL};
 	int status;
 	fprintf(stderr,"Run command: %s\n", cmd);
-	status = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ);
+	status = posix_spawn(&pid, "/fs/jb/bin/sh", NULL, NULL, argv, environ);
 	if (status == 0) {
 		printf("Child pid: %i\n", pid);
 		if (waitpid(pid, &status, 0) != -1) {