mirror of
https://github.com/yuzu-emu/AppImageKit-checkrt.git
synced 2025-01-12 06:45:40 +00:00
Fork when starting application and wait for process to complete
This allows parent don't be lost when, e.g., application restarts
This commit is contained in:
parent
a2866fd043
commit
07e851fcc8
|
@ -1,32 +1,81 @@
|
||||||
--- a/AppRun.c
|
--- a/AppRun.c
|
||||||
+++ b/AppRun.c
|
+++ b/AppRun.c
|
||||||
@@ -164,6 +164,10 @@
|
@@ -32,6 +32,7 @@
|
||||||
char *old_env;
|
#include <dirent.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
+#include <wait.h>
|
||||||
|
|
||||||
|
#define die(...) \
|
||||||
|
do { \
|
||||||
|
@@ -102,6 +103,11 @@
|
||||||
|
line[n] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
+ int pid;
|
||||||
|
+ if ((pid = fork()) == -1) {
|
||||||
|
+ int error = errno;
|
||||||
|
+ die("fork() failed: %s\n", strerror(error));
|
||||||
|
+ } else if (pid == 0) {
|
||||||
|
// count arguments
|
||||||
|
char* arg = exe;
|
||||||
|
int argcount = 0;
|
||||||
|
@@ -165,6 +171,11 @@
|
||||||
size_t length;
|
size_t length;
|
||||||
const char *format;
|
const char *format;
|
||||||
|
|
||||||
+ checkrt(usr_in_appdir);
|
+ checkrt(usr_in_appdir);
|
||||||
+
|
+
|
||||||
+ if (optional_ld_preload)
|
+ if (optional_ld_preload)
|
||||||
+ putenv(optional_ld_preload);
|
+ putenv(optional_ld_preload);
|
||||||
|
+
|
||||||
/* https://docs.python.org/2/using/cmdline.html#envvar-PYTHONHOME */
|
/* https://docs.python.org/2/using/cmdline.html#envvar-PYTHONHOME */
|
||||||
SET_NEW_ENV(new_pythonhome, appdir_s, "PYTHONHOME=%s/usr/", appdir);
|
SET_NEW_ENV(new_pythonhome, appdir_s, "PYTHONHOME=%s/usr/", appdir);
|
||||||
@@ -172,7 +176,7 @@
|
|
||||||
|
@@ -172,7 +183,7 @@
|
||||||
SET_NEW_ENV(new_path, appdir_s*5 + strlen(old_env), "PATH=%s/usr/bin/:%s/usr/sbin/:%s/usr/games/:%s/bin/:%s/sbin/:%s", appdir, appdir, appdir, appdir, appdir, old_env);
|
SET_NEW_ENV(new_path, appdir_s*5 + strlen(old_env), "PATH=%s/usr/bin/:%s/usr/sbin/:%s/usr/games/:%s/bin/:%s/sbin/:%s", appdir, appdir, appdir, appdir, appdir, old_env);
|
||||||
|
|
||||||
old_env = getenv("LD_LIBRARY_PATH") ?: "";
|
old_env = getenv("LD_LIBRARY_PATH") ?: "";
|
||||||
- SET_NEW_ENV(new_ld_library_path, appdir_s*10 + strlen(old_env), "LD_LIBRARY_PATH=%s/usr/lib/:%s/usr/lib/i386-linux-gnu/:%s/usr/lib/x86_64-linux-gnu/:%s/usr/lib32/:%s/usr/lib64/:%s/lib/:%s/lib/i386-linux-gnu/:%s/lib/x86_64-linux-gnu/:%s/lib32/:%s/lib64/:%s", appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, old_env);
|
- SET_NEW_ENV(new_ld_library_path, appdir_s*10 + strlen(old_env), "LD_LIBRARY_PATH=%s/usr/lib/:%s/usr/lib/i386-linux-gnu/:%s/usr/lib/x86_64-linux-gnu/:%s/usr/lib32/:%s/usr/lib64/:%s/lib/:%s/lib/i386-linux-gnu/:%s/lib/x86_64-linux-gnu/:%s/lib32/:%s/lib64/:%s", appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, old_env);
|
||||||
+ SET_NEW_ENV(new_ld_library_path, strlen(optional_ld_library_path) + appdir_s*10 + strlen(old_env), "LD_LIBRARY_PATH=%s%s/usr/lib/:%s/usr/lib/i386-linux-gnu/:%s/usr/lib/x86_64-linux-gnu/:%s/usr/lib32/:%s/usr/lib64/:%s/lib/:%s/lib/i386-linux-gnu/:%s/lib/x86_64-linux-gnu/:%s/lib32/:%s/lib64/:%s", optional_ld_library_path, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, old_env);
|
+ SET_NEW_ENV(new_ld_library_path, strlen(optional_ld_library_path) + appdir_s*10 + strlen(old_env), "LD_LIBRARY_PATH=%s%s/usr/lib/:%s/usr/lib/i386-linux-gnu/:%s/usr/lib/x86_64-linux-gnu/:%s/usr/lib32/:%s/usr/lib64/:%s/lib/:%s/lib/i386-linux-gnu/:%s/lib/x86_64-linux-gnu/:%s/lib32/:%s/lib64/:%s", optional_ld_library_path, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, appdir, old_env);
|
||||||
|
|
||||||
old_env = getenv("PYTHONPATH") ?: "";
|
old_env = getenv("PYTHONPATH") ?: "";
|
||||||
SET_NEW_ENV(new_pythonpath, appdir_s + strlen(old_env), "PYTHONPATH=%s/usr/share/pyshared/:%s", appdir, old_env);
|
SET_NEW_ENV(new_pythonpath, appdir_s + strlen(old_env), "PYTHONPATH=%s/usr/share/pyshared/:%s", appdir, old_env);
|
||||||
@@ -201,6 +205,9 @@
|
@@ -197,15 +208,12 @@
|
||||||
if (ret == -1)
|
putenv("PYTHONDONTWRITEBYTECODE=1");
|
||||||
die("Error executing '%s': %s\n", exe, strerror(error));
|
|
||||||
|
/* Run */
|
||||||
|
- ret = execvp(exe, outargptrs);
|
||||||
|
-
|
||||||
|
- int error = errno;
|
||||||
|
+ execvp(exe, outargptrs);
|
||||||
|
|
||||||
|
- if (ret == -1)
|
||||||
|
- die("Error executing '%s': %s\n", exe, strerror(error));
|
||||||
+ free(optional_ld_library_path);
|
+ free(optional_ld_library_path);
|
||||||
+ if (optional_ld_preload)
|
+ if (optional_ld_preload)
|
||||||
+ free(optional_ld_preload);
|
+ free(optional_ld_preload);
|
||||||
free(line);
|
|
||||||
free(desktop_file);
|
- free(line);
|
||||||
|
- free(desktop_file);
|
||||||
free(usr_in_appdir);
|
free(usr_in_appdir);
|
||||||
|
free(new_pythonhome);
|
||||||
|
free(new_path);
|
||||||
|
@@ -215,5 +223,16 @@
|
||||||
|
free(new_perllib);
|
||||||
|
free(new_gsettings_schema_dir);
|
||||||
|
free(new_qt_plugin_path);
|
||||||
|
- return 0;
|
||||||
|
+
|
||||||
|
+ int error = errno;
|
||||||
|
+ die("Error executing '%s': %s\n", exe, strerror(error));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ int status = 0;
|
||||||
|
+ int rv = waitpid(pid, &status, 0);
|
||||||
|
+ status = rv > 0 && WIFEXITED (status) ? WEXITSTATUS (status) : 1;
|
||||||
|
+
|
||||||
|
+ free(line);
|
||||||
|
+ free(desktop_file);
|
||||||
|
+ return status;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue