forked from hcorion/AppImageKit-checkrt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
AppRun.c.patch
84 lines (80 loc) · 3.24 KB
/
AppRun.c.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
--- a/AppRun.c
+++ b/AppRun.c
@@ -164,6 +164,9 @@
char *old_env;
size_t length;
const char *format;
+ checkrt(usr_in_appdir);
+ if (optional_ld_preload)
+ putenv(optional_ld_preload);
/* https://docs.python.org/2/using/cmdline.html#envvar-PYTHONHOME */
SET_NEW_ENV(new_pythonhome, appdir_s, "PYTHONHOME=%s/usr/", appdir);
@@ -171,8 +174,61 @@
old_env = getenv("PATH") ?: "";
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);
+ int doUseBuiltinSTDCPP = true;
+ // we don't want stdout, only stderr
+ FILE *fp = popen("./optional/checker 2>&1 >/dev/null", "r");
+ if (fp != NULL)
+ {
+ char errorStr[1035];
+ fgets(errorStr, sizeof(errorStr), fp);
+ const char* searchStr = "*libstdc++*version `*' not found (required by";
+ int searchStrI = 0;
+ int errorStrI = 0;
+ int lastWildcard = 0;
+ while (searchStrI < strlen(searchStr))
+ {
+ if (errorStrI >= strlen(errorStr))
+ {
+ doUseBuiltinSTDCPP = false;
+ break;
+ }
+ if (errorStr[errorStrI] == searchStr[searchStrI])
+ {
+ errorStrI++;
+ searchStrI++;
+ }
+ else if (searchStr[searchStrI] == '*')
+ {
+ if (errorStr[errorStrI] == searchStr[searchStrI+1])
+ {
+ if (lastWildcard == 0)
+ lastWildcard = searchStrI;
+ searchStrI++;
+ }
+ else
+ {
+ errorStrI++;
+ }
+ }
+ else
+ {
+ searchStrI = lastWildcard;
+ lastWildcard = 0;
+ }
+ }
+
+ }
+ else
+ {
+ doUseBuiltinSTDCPP = false;
+ }
+
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);
+ if (doUseBuiltinSTDCPP)
+ {
+ 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") ?: "";
SET_NEW_ENV(new_pythonpath, appdir_s + strlen(old_env), "PYTHONPATH=%s/usr/share/pyshared/:%s", appdir, old_env);
@@ -201,6 +257,9 @@
if (ret == -1)
die("Error executing '%s': %s\n", exe, strerror(error));
+ free(optional_ld_library_path);
+ if (optional_ld_preload)
+ free(optional_ld_preload);
free(line);
free(desktop_file);
free(usr_in_appdir);