| 1 |
diff -Naur type2-runtime-main/src/runtime/Makefile type2-runtime-freebsd/src/runtime/Makefile |
| 2 |
--- type2-runtime-main/src/runtime/Makefile 2025-05-30 13:05:28.000000000 +0200 |
| 3 |
+++ type2-runtime-freebsd/src/runtime/Makefile 2025-06-18 19:41:01.549933400 +0200 |
| 4 |
@@ -1,12 +1,13 @@ |
| 5 |
GIT_COMMIT := $(shell cat version) |
| 6 |
-CC = clang |
| 7 |
-CFLAGS = -std=gnu99 -Os -D_FILE_OFFSET_BITS=64 -DGIT_COMMIT=\"$(GIT_COMMIT)\" -T data_sections.ld -ffunction-sections -fdata-sections -Wl,--gc-sections -static -Wall -Werror -static-pie |
| 8 |
-LIBS = -lsquashfuse -lsquashfuse_ll -lzstd -lz -lfuse3 -lmimalloc |
| 9 |
+CC = gcc |
| 10 |
+CFLAGS = -std=gnu99 -Os -D_FILE_OFFSET_BITS=64 -DGIT_COMMIT=\"$(GIT_COMMIT)\" -T data_sections.ld -ffunction-sections -fdata-sections -Wl,--gc-sections -static -Wall |
| 11 |
+LIBS = -lsquashfuse -lsquashfuse_ll -lzstd -llzma -lz -llz4 -llzo2 -lfuse3 -lmd -ldl -lpthread |
| 12 |
|
| 13 |
all: runtime |
| 14 |
|
| 15 |
runtime: runtime.c |
| 16 |
- $(CC) -I/usr/local/include/squashfuse -I/usr/include/fuse3 $(CFLAGS) $^ $(LIBS) -o $@ |
| 17 |
+ $(CC) -I/usr/local/include -I/usr/local/include/fuse3 $(CFLAGS) $^ $(LIBS) -o $@ |
| 18 |
+ elfedit --output-osabi FreeBSD $@ |
| 19 |
|
| 20 |
clean: |
| 21 |
rm -f runtime |
| 22 |
diff -Naur type2-runtime-main/src/runtime/runtime.c type2-runtime-freebsd/src/runtime/runtime.c |
| 23 |
--- type2-runtime-main/src/runtime/runtime.c 2025-05-30 13:05:28.000000000 +0200 |
| 24 |
+++ type2-runtime-freebsd/src/runtime/runtime.c 2025-06-18 19:40:25.010463700 +0200 |
| 25 |
@@ -64,8 +64,7 @@ |
| 26 |
#include <libgen.h> |
| 27 |
#include <dirent.h> |
| 28 |
#include <ctype.h> |
| 29 |
- |
| 30 |
-const char* fusermountPath = NULL; |
| 31 |
+#include <sys/sysctl.h> |
| 32 |
|
| 33 |
typedef struct { |
| 34 |
uint32_t lo; |
| 35 |
@@ -414,106 +413,6 @@ |
| 36 |
return 0; |
| 37 |
} |
| 38 |
|
| 39 |
-char* find_fusermount(bool verbose) { |
| 40 |
- char* fusermount_base = "fusermount"; |
| 41 |
- |
| 42 |
- char* fusermount_path = getenv("PATH"); |
| 43 |
- if (fusermount_path == NULL) { |
| 44 |
- return NULL; |
| 45 |
- } |
| 46 |
- |
| 47 |
- char* path_copy = strdup(fusermount_path); |
| 48 |
- char* dir = strtok(path_copy, ":"); |
| 49 |
- |
| 50 |
- while (dir != NULL) { |
| 51 |
- DIR* dir_ptr = opendir(dir); |
| 52 |
- if (dir_ptr == NULL) { |
| 53 |
- dir = strtok(NULL, ":"); |
| 54 |
- continue; |
| 55 |
- } |
| 56 |
- |
| 57 |
- struct dirent* entry; |
| 58 |
- while ((entry = readdir(dir_ptr)) != NULL) { |
| 59 |
- // Check if the entry starts with "fusermount" |
| 60 |
- if (strncmp(entry->d_name, fusermount_base, 10) == 0) { |
| 61 |
- // Check if the rest of the entry is a digit |
| 62 |
- char* suffix = entry->d_name + 10; |
| 63 |
- int j = 0; |
| 64 |
- while (suffix[j] != '\0' && isdigit(suffix[j])) { |
| 65 |
- j++; |
| 66 |
- } |
| 67 |
- |
| 68 |
- if (suffix[j] == '\0') { |
| 69 |
- // Construct the full path of the entry |
| 70 |
- char* fusermount_full_path = malloc(strlen(dir) + strlen(entry->d_name) + 2); |
| 71 |
- sprintf(fusermount_full_path, "%s/%s", dir, entry->d_name); |
| 72 |
- |
| 73 |
- // Check if the binary is setuid root |
| 74 |
- struct stat sb; |
| 75 |
- if (stat(fusermount_full_path, &sb) == -1) { |
| 76 |
- perror("stat"); |
| 77 |
- free(fusermount_full_path); |
| 78 |
- continue; |
| 79 |
- } |
| 80 |
- |
| 81 |
- if (sb.st_uid != 0 || (sb.st_mode & S_ISUID) == 0) { |
| 82 |
- if (verbose) { |
| 83 |
- printf("Not setuid root, skipping...\n"); |
| 84 |
- } |
| 85 |
- free(fusermount_full_path); |
| 86 |
- continue; |
| 87 |
- } |
| 88 |
- |
| 89 |
- if (verbose) { |
| 90 |
- printf("Found setuid root executable: %s\n", fusermount_full_path); |
| 91 |
- } |
| 92 |
- |
| 93 |
- pid_t pid = fork(); |
| 94 |
- if (pid == -1) { |
| 95 |
- perror("fork"); |
| 96 |
- free(fusermount_full_path); |
| 97 |
- continue; |
| 98 |
- } |
| 99 |
- |
| 100 |
- if (pid == 0) { |
| 101 |
- // Child process |
| 102 |
- |
| 103 |
- // close stdout and stderr if not in verbose mode |
| 104 |
- if (!verbose) { |
| 105 |
- close(1); |
| 106 |
- close(2); |
| 107 |
- } |
| 108 |
- |
| 109 |
- char* args[] = {fusermount_full_path, "--version", NULL}; |
| 110 |
- execvp(fusermount_full_path, args); |
| 111 |
- // If execvp returns, it means the executable was not found |
| 112 |
- exit(1); |
| 113 |
- } else { |
| 114 |
- // Parent process |
| 115 |
- int status; |
| 116 |
- waitpid(pid, &status, 0); |
| 117 |
- |
| 118 |
- if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { |
| 119 |
- // The executable was found and executed successfully |
| 120 |
- closedir(dir_ptr); |
| 121 |
- free(path_copy); |
| 122 |
- return fusermount_full_path; |
| 123 |
- } |
| 124 |
- |
| 125 |
- free(fusermount_full_path); |
| 126 |
- } |
| 127 |
- } |
| 128 |
- } |
| 129 |
- } |
| 130 |
- |
| 131 |
- closedir(dir_ptr); |
| 132 |
- dir = strtok(NULL, ":"); |
| 133 |
- } |
| 134 |
- |
| 135 |
- free(path_copy); |
| 136 |
- return NULL; |
| 137 |
-} |
| 138 |
- |
| 139 |
/* Exit status to use when launching an AppImage fails. |
| 140 |
* For applications that assign meanings to exit status codes (e.g. rsync), |
| 141 |
* we avoid "cluttering" pre-defined exit status codes by using 127 which |
| 142 |
@@ -722,16 +621,8 @@ |
| 143 |
|
| 144 |
if (arg && strcmp(arg, option) == 0) { |
| 145 |
char portable_dir[PATH_MAX]; |
| 146 |
- char fullpath[PATH_MAX]; |
| 147 |
- |
| 148 |
- ssize_t length = readlink(appimage_path, fullpath, sizeof(fullpath)); |
| 149 |
- if (length < 0) { |
| 150 |
- fprintf(stderr, "Error getting realpath for %s\n", appimage_path); |
| 151 |
- exit(EXIT_FAILURE); |
| 152 |
- } |
| 153 |
- fullpath[length] = '\0'; |
| 154 |
|
| 155 |
- sprintf(portable_dir, "%s.%s", fullpath, name); |
| 156 |
+ sprintf(portable_dir, "%s.%s", appimage_path, name); |
| 157 |
if (!mkdir(portable_dir, S_IRWXU)) |
| 158 |
fprintf(stderr, "Portable %s directory created at %s\n", name, portable_dir); |
| 159 |
else |
| 160 |
@@ -1481,7 +1372,14 @@ |
| 161 |
* functionality specifically for builds used by appimaged. |
| 162 |
*/ |
| 163 |
if (getenv("TARGET_APPIMAGE") == NULL) { |
| 164 |
- strcpy(appimage_path, "/proc/self/exe"); |
| 165 |
+ int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; |
| 166 |
+ size_t len = PATH_MAX; |
| 167 |
+ |
| 168 |
+ if (sysctl(mib, 4, appimage_path, &len, 0, 0) != 0) { |
| 169 |
+ perror("Failed to obtain absolute path"); |
| 170 |
+ exit(EXIT_EXECERROR); |
| 171 |
+ } |
| 172 |
+ |
| 173 |
strcpy(argv0_path, argv[0]); |
| 174 |
} else { |
| 175 |
strcpy(appimage_path, getenv("TARGET_APPIMAGE")); |
| 176 |
@@ -1510,16 +1408,7 @@ |
| 177 |
|
| 178 |
/* Print the help and then exit */ |
| 179 |
if (arg && strcmp(arg, "appimage-help") == 0) { |
| 180 |
- char fullpath[PATH_MAX]; |
| 181 |
- |
| 182 |
- ssize_t length = readlink(appimage_path, fullpath, sizeof(fullpath)); |
| 183 |
- if (length < 0) { |
| 184 |
- fprintf(stderr, "Error getting realpath for %s\n", appimage_path); |
| 185 |
- exit(EXIT_EXECERROR); |
| 186 |
- } |
| 187 |
- fullpath[length] = '\0'; |
| 188 |
- |
| 189 |
- print_help(fullpath); |
| 190 |
+ print_help(appimage_path); |
| 191 |
exit(0); |
| 192 |
} |
| 193 |
|
| 194 |
@@ -1562,12 +1451,7 @@ |
| 195 |
|
| 196 |
if (getenv("TARGET_APPIMAGE") == NULL) { |
| 197 |
// If we are operating on this file itself |
| 198 |
- ssize_t len = readlink(appimage_path, fullpath, sizeof(fullpath)); |
| 199 |
- if (len < 0) { |
| 200 |
- perror("Failed to obtain absolute path"); |
| 201 |
- exit(EXIT_EXECERROR); |
| 202 |
- } |
| 203 |
- fullpath[len] = '\0'; |
| 204 |
+ strcpy(fullpath, appimage_path); |
| 205 |
} else { |
| 206 |
char* abspath = realpath(appimage_path, NULL); |
| 207 |
if (abspath == NULL) { |
| 208 |
@@ -1737,21 +1621,6 @@ |
| 209 |
|
| 210 |
if (pid == 0) { |
| 211 |
/* in child */ |
| 212 |
- |
| 213 |
- fusermountPath = getenv("FUSERMOUNT_PROG"); |
| 214 |
- if (fusermountPath == NULL) { |
| 215 |
- char* new_prog = find_fusermount(verbose); |
| 216 |
- if (new_prog != NULL) { |
| 217 |
- setenv("FUSERMOUNT_PROG", new_prog, 1); |
| 218 |
- if (verbose) { |
| 219 |
- fprintf(stderr, "FUSERMOUNT_PROG set to %s\n", new_prog); |
| 220 |
- } |
| 221 |
- free(new_prog); |
| 222 |
- } else { |
| 223 |
- printf("Error: No suitable fusermount binary found on the $PATH\n"); |
| 224 |
- } |
| 225 |
- } |
| 226 |
- |
| 227 |
char* child_argv[5]; |
| 228 |
|
| 229 |
/* close read pipe */ |
| 230 |
@@ -1847,6 +1716,16 @@ |
| 231 |
strcpy(filename, mount_dir); |
| 232 |
strcat(filename, "/AppRun"); |
| 233 |
|
| 234 |
+ /* Wait for mounted image to become available (up to 1s) */ |
| 235 |
+ for (int i = 0; i < 100; i++) { |
| 236 |
+ struct stat s; |
| 237 |
+ if (stat(filename, &s) == 0) |
| 238 |
+ break; |
| 239 |
+ |
| 240 |
+ /* Wait 10ms */ |
| 241 |
+ usleep(10000); |
| 242 |
+ } |
| 243 |
+ |
| 244 |
/* TODO: Find a way to get the exit status and/or output of this */ |
| 245 |
execv(filename, real_argv); |
| 246 |
/* Error if we continue here */ |