Index: python-wrapper.c =================================================================== --- python-wrapper.c (revision 254) +++ python-wrapper.c (working copy) @@ -156,7 +156,7 @@ { return NULL; } - /* walk backwards through the list */ + /* Walk backwards through the list. */ while (n--) { if (! ret) @@ -167,7 +167,7 @@ return ret; } -int main(__attribute__((unused)) int argc, char** argv) +int main(int argc, char** argv) { if (strlen(program_description) == 0) abort(); @@ -199,20 +199,24 @@ if (strchr(EPYTHON, '/')) { - argv[0] = (char*) EPYTHON; - execv(EPYTHON, argv); + fprintf(stderr, "Invalid value of EPYTHON variable or invalid configuration of Python wrapper\n"); return EXIT_ERROR; } + /* Update argv[0], 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] == '/') + argv[0] = argv[1]; + else if (argc >= 3 && argv[0][0] == '/' && argv[1][0] == '-' && argv[2][0] == '/') + argv[0] = argv[2]; + const char* path = find_path(argv[0]); - if (*path) + if (path) { - argv[0] = dir_cat(path, EPYTHON); - execv(argv[0], argv); + execv(dir_cat(path, EPYTHON), argv); /* If this failed, then just search the PATH. */ } - argv[0] = (char*) EPYTHON; execvp(EPYTHON, argv); return EXIT_ERROR; }