fix: strip --appimage-extract-and-run from linuxdeploy args in wrapper
This commit is contained in:
+21
-15
@@ -6,32 +6,38 @@
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const char *appdir = "/root/linuxdeploy-root";
|
||||
char apprun[256], ldbin[256], new_path[4096];
|
||||
char apprun[256], ldbin[256], new_path[4096], new_ldpath[4096];
|
||||
struct stat st;
|
||||
|
||||
snprintf(apprun, sizeof(apprun), "%s/AppRun", appdir);
|
||||
snprintf(ldbin, sizeof(ldbin), "%s/usr/bin/linuxdeploy", appdir);
|
||||
|
||||
fprintf(stderr, "[ld-wrapper] APPDIR=%s\n", appdir);
|
||||
fprintf(stderr, "[ld-wrapper] AppRun exists: %s\n", stat(apprun, &st) == 0 ? "yes" : "NO");
|
||||
fprintf(stderr, "[ld-wrapper] linuxdeploy exists: %s\n", stat(ldbin, &st) == 0 ? "yes" : "NO");
|
||||
fflush(stderr);
|
||||
/* Strip --appimage-extract-and-run: that's an AppImage runtime flag,
|
||||
not a linuxdeploy flag. Passing it to the real binary causes immediate failure. */
|
||||
char **new_argv = malloc((argc + 1) * sizeof(char *));
|
||||
int new_argc = 0;
|
||||
new_argv[new_argc++] = argv[0];
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "--appimage-extract-and-run") != 0) {
|
||||
new_argv[new_argc++] = argv[i];
|
||||
}
|
||||
}
|
||||
new_argv[new_argc] = NULL;
|
||||
|
||||
setenv("APPDIR", appdir, 1);
|
||||
|
||||
char *old_path = getenv("PATH");
|
||||
snprintf(new_path, sizeof(new_path), "%s/usr/bin:%s", appdir, old_path ? old_path : "");
|
||||
setenv("PATH", new_path, 1);
|
||||
|
||||
if (stat(ldbin, &st) == 0) {
|
||||
fprintf(stderr, "[ld-wrapper] exec %s\n", ldbin);
|
||||
fflush(stderr);
|
||||
execv(ldbin, argv);
|
||||
perror("[ld-wrapper] execv linuxdeploy");
|
||||
}
|
||||
char *old_ldpath = getenv("LD_LIBRARY_PATH");
|
||||
snprintf(new_ldpath, sizeof(new_ldpath), "%s/usr/lib:%s/usr/lib/x86_64-linux-gnu:%s",
|
||||
appdir, appdir, old_ldpath ? old_ldpath : "");
|
||||
setenv("LD_LIBRARY_PATH", new_ldpath, 1);
|
||||
|
||||
fprintf(stderr, "[ld-wrapper] fallback exec %s\n", apprun);
|
||||
fflush(stderr);
|
||||
execv(apprun, argv);
|
||||
perror("[ld-wrapper] execv AppRun");
|
||||
if (stat(ldbin, &st) == 0) {
|
||||
execv(ldbin, new_argv);
|
||||
}
|
||||
execv(apprun, new_argv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user