--- Modules/main.c +++ Modules/main.c @@ -452,7 +452,11 @@ filename = argv[_PyOS_optind]; #else - filename = argv[_PyOS_optind]; + char *target_script_name = getenv("GENTOO_PYTHON_TARGET_SCRIPT_PATH"); + if (target_script_name) + filename = target_script_name; + else + filename = argv[_PyOS_optind]; #endif } --- Modules/python.c +++ Modules/python.c @@ -6,9 +6,19 @@ #include #endif +#ifdef __linux__ +#include +#include +#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 +30,12 @@ m = fpgetmask(); fpsetmask(m & ~FP_X_OFL); #endif + +#ifdef __linux__ + char *process_name = getenv("GENTOO_PYTHON_PROCESS_NAME"); + if (process_name) + prctl(PR_SET_NAME, process_name); +#endif + return Py_Main(argc, argv); } --- Python/sysmodule.c +++ Python/sysmodule.c @@ -1490,6 +1490,7 @@ makeargvobject(int argc, char **argv) { PyObject *av; + char *wrapper_script_name = getenv("GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"); if (argc <= 0 || argv == NULL) { /* Ensure at least one (empty) argument is seen */ static char *empty_argv[1] = {""}; @@ -1514,7 +1515,11 @@ } else v = PyString_FromString(argv[i]); #else - PyObject *v = PyString_FromString(argv[i]); + PyObject *v; + if (i == 0 && wrapper_script_name != NULL) + v = PyString_FromString(wrapper_script_name); + else + v = PyString_FromString(argv[i]); #endif if (v == NULL) { Py_DECREF(av);