diff options
author | Arfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org> | 2010-03-21 11:48:50 +0000 |
---|---|---|
committer | Arfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org> | 2010-03-21 11:48:50 +0000 |
commit | 46fc51dd969923d44e553732cfc17cb68c5e5cf0 (patch) | |
tree | 2229d6e51348440f2db3f4e00f581108ed892719 | |
parent | Avoid potential printing of empty line. (diff) | |
download | eselect-python-46fc51dd969923d44e553732cfc17cb68c5e5cf0.tar.gz eselect-python-46fc51dd969923d44e553732cfc17cb68c5e5cf0.tar.bz2 eselect-python-46fc51dd969923d44e553732cfc17cb68c5e5cf0.zip |
Set GENTOO_PYTHON_PROCESS_NAME environmental variable (bug #286424).
-rw-r--r-- | configure.ac | 7 | ||||
-rw-r--r-- | python-wrapper.c | 23 |
2 files changed, 26 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac index 662653a..46291cc 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([eselect-python], [20091230]) +AC_INIT([eselect-python], [20100321]) CFLAGS="${CFLAGS--march=native -O3 -pipe -fno-ident}" LDFLAGS="${LDFLAGS--Wl,-O1,--as-needed,--gc-sections,--hash-style=gnu}" @@ -9,7 +9,10 @@ MKDIR="${MKDIR:-${INSTALL} -d}" AC_USE_SYSTEM_EXTENSIONS -# strndup() was introduced in POSIX.1-2008. +# setenv() was introduced in POSIX.1-2008. +AC_CHECK_FUNCS([setenv]) + +# strndup() was introduced in POSIX.1-2008 and is also an implicitly declared built-in function in GCC. AC_MSG_CHECKING([for strndup]) old_CFLAGS="${CFLAGS}" CFLAGS="${CFLAGS} -Wall -Werror -Wextra" diff --git a/python-wrapper.c b/python-wrapper.c index e472c9b..ecc26bc 100644 --- a/python-wrapper.c +++ b/python-wrapper.c @@ -1,4 +1,4 @@ -/* Copyright 1999-2009 Gentoo Foundation +/* Copyright 1999-2010 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 */ #include <dirent.h> @@ -165,9 +165,10 @@ const char* find_latest(const char* exe) return ret; } -int main(__attribute__((unused)) int argc, char** argv) +int main(int argc, char** argv) { const char* EPYTHON = getenv("EPYTHON"); + int script_name_index = -1; if (! valid_interpreter(EPYTHON)) { FILE* f = fopen(ENVD_CONFIG, "r"); @@ -198,6 +199,24 @@ int main(__attribute__((unused)) int argc, char** argv) return EXIT_ERROR; } + /* Set GENTOO_PYTHON_PROCESS_NAME environmental variable, if a script with a Python shebang is probably being executed. + * argv[0] can be "python", when "#!/usr/bin/env python" shebang is used. */ + if (argc >= 2 && (argv[0][0] == '/' || strcmp(argv[0], "python") == 0) && (argv[1][0] == '/' || strncmp(argv[1], "./", 2) == 0)) + script_name_index = 1; + else if (argc >= 3 && argv[0][0] == '/' && argv[1][0] == '-' && (argv[2][0] == '/' || strncmp(argv[2], "./", 2) == 0)) + script_name_index = 2; + if (script_name_index > 0) + { + char* script_name = strrchr(argv[script_name_index], '/') + 1; +#ifdef HAVE_SETENV + setenv("GENTOO_PYTHON_PROCESS_NAME", script_name, 1); +#else + char* script_name_variable = malloc(sizeof(char) * (strlen("GENTOO_PYTHON_PROCESS_NAME=") + strlen(script_name))); + sprintf(script_name_variable, "GENTOO_PYTHON_PROCESS_NAME=%s", script_name); + putenv(script_name_variable); +#endif + } + const char* path = find_path(argv[0]); if (path) { |