diff --git a/patches/libfuse/mount.c.diff b/patches/libfuse/mount.c.diff deleted file mode 100644 index e3a6981..0000000 --- a/patches/libfuse/mount.c.diff +++ /dev/null @@ -1,105 +0,0 @@ -diff --git a/lib/mount.c b/lib/mount.c -index d71e6fc..ab3f54b 100644 ---- a/lib/mount.c -+++ b/lib/mount.c -@@ -41,7 +41,6 @@ - #define umount2(mnt, flags) unmount(mnt, (flags == 2) ? MNT_FORCE : 0) - #endif - --#define FUSERMOUNT_PROG "fusermount3" - #define FUSE_COMMFD_ENV "_FUSE_COMMFD" - - #ifndef HAVE_FORK -@@ -117,17 +116,44 @@ static const struct fuse_opt fuse_mount_opts[] = { - FUSE_OPT_END - }; - -+/** -+ * Returns FUSERMOUNT_PROG path from environment variable. -+ * -+ * If $FUSERMOUNT_PROG is not set, the program exits. -+ * -+ * Call with FUSERMOUNT_PROG_DEBUG=nonzerovalue to make the code print the value before evaluation. -+ */ -+static const char *fusermountProg(void) -+{ -+ static const char envVar[] = "FUSERMOUNT_PROG"; -+ char *fusermountProg = getenv(envVar); -+ -+ static const char debugEnvVarSuffix[] = "_DEBUG"; -+ char debugEnvVar[sizeof(envVar) + sizeof(debugEnvVarSuffix) + 1]; -+ sprintf(debugEnvVar, "%s%s", envVar, debugEnvVarSuffix); -+ -+ if (fusermountProg == NULL) { -+ fprintf(stderr, "Error: $%s not set\n", envVar); -+ exit(1); -+ } -+ -+ if (getenv(debugEnvVar) != NULL) { -+ fprintf(stderr, "$%s: %s\n", envVar, fusermountProg); -+ } -+ -+ return fusermountProg; -+} -+ - static void exec_fusermount(const char *argv[]) - { -- execv(FUSERMOUNT_DIR "/" FUSERMOUNT_PROG, (char **) argv); -- execvp(FUSERMOUNT_PROG, (char **) argv); -+ execv(fusermountProg(), (char **) argv); - } - - void fuse_mount_version(void) - { - int pid = fork(); - if (!pid) { -- const char *argv[] = { FUSERMOUNT_PROG, "--version", NULL }; -+ const char *argv[] = { fusermountProg(), "--version", NULL }; - exec_fusermount(argv); - _exit(1); - } else if (pid != -1) -@@ -300,7 +326,7 @@ void fuse_kern_unmount(const char *mountpoint, int fd) - return; - - if(pid == 0) { -- const char *argv[] = { FUSERMOUNT_PROG, "-u", "-q", "-z", -+ const char *argv[] = { fusermountProg(), "-u", "-q", "-z", - "--", mountpoint, NULL }; - - exec_fusermount(argv); -@@ -346,7 +372,7 @@ static int setup_auto_unmount(const char *mountpoint, int quiet) - } - } - -- argv[a++] = FUSERMOUNT_PROG; -+ argv[a++] = fusermountProg(); - argv[a++] = "--auto-unmount"; - argv[a++] = "--"; - argv[a++] = mountpoint; -@@ -357,7 +383,7 @@ static int setup_auto_unmount(const char *mountpoint, int quiet) - snprintf(env, sizeof(env), "%i", fds[0]); - setenv(FUSE_COMMFD_ENV, env, 1); - exec_fusermount(argv); -- perror("fuse: failed to exec fusermount3"); -+ perror("fuse: failed to exec $FUSERMOUNT_PROG"); - _exit(1); - } - -@@ -407,7 +433,7 @@ static int fuse_mount_fusermount(const char *mountpoint, struct mount_opts *mo, - } - } - -- argv[a++] = FUSERMOUNT_PROG; -+ argv[a++] = fusermountProg(); - if (opts) { - argv[a++] = "-o"; - argv[a++] = opts; -@@ -421,7 +447,7 @@ static int fuse_mount_fusermount(const char *mountpoint, struct mount_opts *mo, - snprintf(env, sizeof(env), "%i", fds[0]); - setenv(FUSE_COMMFD_ENV, env, 1); - exec_fusermount(argv); -- perror("fuse: failed to exec fusermount3"); -+ perror("fuse: failed to exec $FUSERMOUNT_PROG"); - _exit(1); - } - diff --git a/scripts/chroot/chroot_build.sh b/scripts/chroot/chroot_build.sh index 1d0fedc..e0d57b7 100755 --- a/scripts/chroot/chroot_build.sh +++ b/scripts/chroot/chroot_build.sh @@ -55,7 +55,6 @@ cd - ############################################# sudo cp -r "$repo_root_dir"/src miniroot/src -sudo cp -r "$repo_root_dir"/patches miniroot/patches sudo mount -o bind /dev miniroot/dev sudo mount -t proc none miniroot/proc diff --git a/scripts/common/install-dependencies.sh b/scripts/common/install-dependencies.sh index 0e21cdb..4949121 100755 --- a/scripts/common/install-dependencies.sh +++ b/scripts/common/install-dependencies.sh @@ -12,17 +12,12 @@ cleanup() { } trap cleanup EXIT -# store current file's path -# needed to determine the path of the patches -this_dir="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")" - cd "$tmpdir" wget https://github.com/libfuse/libfuse/releases/download/fuse-3.15.0/fuse-3.15.0.tar.xz echo "70589cfd5e1cff7ccd6ac91c86c01be340b227285c5e200baa284e401eea2ca0 fuse-3.15.0.tar.xz" | sha256sum -c - tar xf fuse-3.*.tar.xz pushd fuse-3*/ -patch -p1 < "$this_dir"/../../patches/libfuse/mount.c.diff mkdir build cd build meson setup --prefix=/usr .. diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile index 07b6533..3bc7449 100644 --- a/scripts/docker/Dockerfile +++ b/scripts/docker/Dockerfile @@ -7,7 +7,6 @@ RUN apk add --no-cache \ zstd-dev zstd-static zlib-dev zlib-static clang musl-dev mimalloc-dev COPY scripts/common/install-dependencies.sh /tmp/scripts/common/install-dependencies.sh -COPY patches/ /tmp/patches/ WORKDIR /tmp RUN bash scripts/common/install-dependencies.sh diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index a073f60..7ae0872 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -62,10 +62,6 @@ extern int sqfs_opt_proc(void* data, const char* arg, int key, struct fuse_args* #include #include #include -#include -#include - -const char* fusermountPath = NULL; typedef struct { uint32_t lo; @@ -414,106 +410,6 @@ int appimage_print_binary(char* fname, unsigned long offset, unsigned long lengt return 0; } -char* find_fusermount(bool verbose) { - char* fusermount_base = "fusermount"; - - char* fusermount_path = getenv("PATH"); - if (fusermount_path == NULL) { - return NULL; - } - - char* path_copy = strdup(fusermount_path); - char* dir = strtok(path_copy, ":"); - - while (dir != NULL) { - DIR* dir_ptr = opendir(dir); - if (dir_ptr == NULL) { - dir = strtok(NULL, ":"); - continue; - } - - struct dirent* entry; - while ((entry = readdir(dir_ptr)) != NULL) { - // Check if the entry starts with "fusermount" - if (strncmp(entry->d_name, fusermount_base, 10) == 0) { - // Check if the rest of the entry is a digit - char* suffix = entry->d_name + 10; - int j = 0; - while (suffix[j] != '\0' && isdigit(suffix[j])) { - j++; - } - - if (suffix[j] == '\0') { - // Construct the full path of the entry - char* fusermount_full_path = malloc(strlen(dir) + strlen(entry->d_name) + 2); - sprintf(fusermount_full_path, "%s/%s", dir, entry->d_name); - - // Check if the binary is setuid root - struct stat sb; - if (stat(fusermount_full_path, &sb) == -1) { - perror("stat"); - free(fusermount_full_path); - continue; - } - - if (sb.st_uid != 0 || (sb.st_mode & S_ISUID) == 0) { - if (verbose) { - printf("Not setuid root, skipping...\n"); - } - free(fusermount_full_path); - continue; - } - - if (verbose) { - printf("Found setuid root executable: %s\n", fusermount_full_path); - } - - pid_t pid = fork(); - if (pid == -1) { - perror("fork"); - free(fusermount_full_path); - continue; - } - - if (pid == 0) { - // Child process - - // close stdout and stderr if not in verbose mode - if (!verbose) { - close(1); - close(2); - } - - char* args[] = {fusermount_full_path, "--version", NULL}; - execvp(fusermount_full_path, args); - // If execvp returns, it means the executable was not found - exit(1); - } else { - // Parent process - int status; - waitpid(pid, &status, 0); - - if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { - // The executable was found and executed successfully - closedir(dir_ptr); - free(path_copy); - return fusermount_full_path; - } - - free(fusermount_full_path); - } - } - } - } - - closedir(dir_ptr); - dir = strtok(NULL, ":"); - } - - free(path_copy); - return NULL; -} - /* Exit status to use when launching an AppImage fails. * For applications that assign meanings to exit status codes (e.g. rsync), * we avoid "cluttering" pre-defined exit status codes by using 127 which @@ -1737,20 +1633,6 @@ int main(int argc, char* argv[]) { if (pid == 0) { /* in child */ - fusermountPath = getenv("FUSERMOUNT_PROG"); - if (fusermountPath == NULL) { - char* new_prog = find_fusermount(verbose); - if (new_prog != NULL) { - setenv("FUSERMOUNT_PROG", new_prog, 1); - if (verbose) { - fprintf(stderr, "FUSERMOUNT_PROG set to %s\n", new_prog); - } - free(new_prog); - } else { - printf("Error: No suitable fusermount binary found on the $PATH\n"); - } - } - char* child_argv[5]; /* close read pipe */