Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 286191 | Differences between
and this patch

Collapse All | Expand All

(-)python-wrapper.c (-2 / +17 lines)
Lines 1-4 Link Here
1
/* Copyright 1999-2009 Gentoo Foundation
1
/* Copyright 1999-2010 Gentoo Foundation
2
 * Distributed under the terms of the GNU General Public License v2
2
 * Distributed under the terms of the GNU General Public License v2
3
 */
3
 */
4
#include <dirent.h>
4
#include <dirent.h>
Lines 165-173 Link Here
165
	return ret;
165
	return ret;
166
}
166
}
167
167
168
int main(__attribute__((unused)) int argc, char** argv)
168
int main(int argc, char** argv)
169
{
169
{
170
	const char* EPYTHON = getenv("EPYTHON");
170
	const char* EPYTHON = getenv("EPYTHON");
171
	int script_name_index = -1;
171
	if (! valid_interpreter(EPYTHON))
172
	if (! valid_interpreter(EPYTHON))
172
	{
173
	{
173
		FILE* f = fopen(ENVD_CONFIG, "r");
174
		FILE* f = fopen(ENVD_CONFIG, "r");
Lines 198-203 Link Here
198
		return EXIT_ERROR;
199
		return EXIT_ERROR;
199
	}
200
	}
200
201
202
	/* Set PYTHON_PROCESS_NAME environment variable, if a script with a Python shebang is probably being executed.
203
	 * argv[0] can be "python", when "#!/usr/bin/env python" shebang is used. */
204
	if (argc >= 2 && (argv[0][0] == '/' || strcmp(argv[0], "python") == 0) && (argv[1][0] == '/' || strncmp(argv[1], "./", 2) == 0))
205
		script_name_index = 1;
206
	else if (argc >= 3 && argv[0][0] == '/' && argv[1][0] == '-' && (argv[2][0] == '/' || strncmp(argv[2], "./", 2) == 0))
207
		script_name_index = 2;
208
	if (script_name_index > 0)
209
	{
210
		char* script_name = strrchr(argv[script_name_index], '/') + 1;
211
		char* script_name_variable = malloc(sizeof(char) * (strlen("PYTHON_PROCESS_NAME=") + strlen(script_name)));
212
		sprintf(script_name_variable, "PYTHON_PROCESS_NAME=%s", script_name);
213
		putenv(script_name_variable);
214
	}
215
201
	const char* path = find_path(argv[0]);
216
	const char* path = find_path(argv[0]);
202
	if (path)
217
	if (path)
203
	{
218
	{

Return to bug 286191