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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
GENTOO_PYTHON_PROCESS_NAME environmental variable is set by python-wrapper and wrapper scripts generated by
python_generate_wrapper_scripts() and specifies process name.
GENTOO_PYTHON_WRAPPER_SCRIPT_PATH environmental variable is set by wrapper scripts generated by
python_generate_wrapper_scripts() and specifies sys.argv[0] in target executables.
GENTOO_PYTHON_TARGET_SCRIPT_PATH environmental variable is set by wrapper scripts generated by
python_generate_wrapper_scripts() and specifies paths to actually executed scripts.
GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION environmental variable is used by wrapper scripts generated by
python_generate_wrapper_scripts() to check if Python supports GENTOO_PYTHON_TARGET_SCRIPT_PATH environmental variable.
--- Modules/main.c
+++ Modules/main.c
@@ -252,6 +252,7 @@
int version = 0;
int saw_unbuffered_flag = 0;
PyCompilerFlags cf;
+ char *target_script_name = getenv("GENTOO_PYTHON_TARGET_SCRIPT_PATH");
cf.cf_flags = 0;
@@ -486,7 +487,10 @@
filename = argv[_PyOS_optind];
#else
- filename = argv[_PyOS_optind];
+ if (target_script_name != NULL && *target_script_name != '\0')
+ filename = target_script_name;
+ else
+ filename = argv[_PyOS_optind];
#endif
}
--- Modules/posixmodule.c
+++ Modules/posixmodule.c
@@ -604,6 +604,10 @@
char *p = strchr(*e, '=');
if (p == NULL)
continue;
+ if ((strlen("GENTOO_PYTHON_PROCESS_NAME") == (int)(p-*e) && strncmp("GENTOO_PYTHON_PROCESS_NAME", *e, (int)(p-*e)) == 0) ||
+ (strlen("GENTOO_PYTHON_TARGET_SCRIPT_PATH") == (int)(p-*e) && strncmp("GENTOO_PYTHON_TARGET_SCRIPT_PATH", *e, (int)(p-*e)) == 0) ||
+ (strlen("GENTOO_PYTHON_WRAPPER_SCRIPT_PATH") == (int)(p-*e) && strncmp("GENTOO_PYTHON_WRAPPER_SCRIPT_PATH", *e, (int)(p-*e)) == 0))
+ continue;
k = PyString_FromStringAndSize(*e, (int)(p-*e));
if (k == NULL) {
PyErr_Clear();
--- Modules/python.c
+++ Modules/python.c
@@ -6,9 +6,22 @@
#include <floatingpoint.h>
#endif
+#ifdef __linux__
+#include <linux/prctl.h>
+#include <sys/prctl.h>
+#ifndef PR_SET_NAME
+#define PR_SET_NAME 15
+#endif
+#endif
+
int
main(int argc, char **argv)
{
+ if (getenv("GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION")) {
+ printf("GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n");
+ return 0;
+ }
+
/* 754 requires that FP exceptions run in "no stop" mode by default,
* and until C vendors implement C99's ways to control FP exceptions,
* Python requires non-stop mode. Alas, some platforms enable FP
@@ -20,5 +33,15 @@
m = fpgetmask();
fpsetmask(m & ~FP_X_OFL);
#endif
+
+#ifdef __linux__
+ char *process_name = getenv("GENTOO_PYTHON_PROCESS_NAME");
+#ifdef HAVE_UNSETENV
+ unsetenv("GENTOO_PYTHON_PROCESS_NAME");
+#endif
+ if (process_name != NULL && *process_name != '\0')
+ prctl(PR_SET_NAME, process_name);
+#endif
+
return Py_Main(argc, argv);
}
--- Python/sysmodule.c
+++ Python/sysmodule.c
@@ -1578,6 +1578,10 @@
makeargvobject(int argc, char **argv)
{
PyObject *av;
+ char *wrapper_script_name = getenv("GENTOO_PYTHON_WRAPPER_SCRIPT_PATH");
+#ifdef HAVE_UNSETENV
+ unsetenv("GENTOO_PYTHON_WRAPPER_SCRIPT_PATH");
+#endif
if (argc <= 0 || argv == NULL) {
/* Ensure at least one (empty) argument is seen */
static char *empty_argv[1] = {""};
@@ -1602,7 +1606,11 @@
} else
v = PyString_FromString(argv[i]);
#else
- PyObject *v = PyString_FromString(argv[i]);
+ PyObject *v;
+ if (i == 0 && wrapper_script_name != NULL && *wrapper_script_name != '\0')
+ v = PyString_FromString(wrapper_script_name);
+ else
+ v = PyString_FromString(argv[i]);
#endif
if (v == NULL) {
Py_DECREF(av);
@@ -1630,7 +1638,15 @@
if (PySys_SetObject("argv", av) != 0)
Py_FatalError("can't assign sys.argv");
if (updatepath && path != NULL) {
- char *argv0 = argv[0];
+ char *target_script_name = getenv("GENTOO_PYTHON_TARGET_SCRIPT_PATH");
+#ifdef HAVE_UNSETENV
+ unsetenv("GENTOO_PYTHON_TARGET_SCRIPT_PATH");
+#endif
+ char *argv0;
+ if (target_script_name != NULL && *target_script_name != '\0')
+ argv0 = target_script_name;
+ else
+ argv0 = argv[0];
char *p = NULL;
Py_ssize_t n = 0;
PyObject *a;
|