Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/python-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <libgen.h>

#ifdef HAVE_READLINK
# include <limits.h>
Expand Down Expand Up @@ -548,7 +549,28 @@ static void load_configuration(const char* scriptname)
*/
static void execute(char* script, char** argv)
{
char *env_path, *path, *script_path, *updated_path;

/* dirname requires copy of path as it may modify it */
path = calloc(strlen(script) + 1, sizeof(char));
strcpy(path, script);
script_path = dirname(path);

env_path = getenv("PATH");
/* + 1 for ':' */
updated_path = calloc(strlen(env_path) + strlen(script_path) + 1 + 1, sizeof(char));

strcat(updated_path, env_path);
strncat(updated_path, ":", 1);
strcat(updated_path, script_path);
free(path);

setenv("PATH", updated_path, 1);
free(updated_path);

execv(script, argv);
/* reset PATH to initial value */
setenv("PATH", env_path, 1);

/* warn about other errors but try hard to run something */
if (errno != ENOENT && isatty(fileno(stderr)))
Expand Down
1 change: 1 addition & 0 deletions src/python-exec.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ while data is None:
raise

sys.argv[0] = target
os.environ["PATH"] += os.pathsep + os.path.join('/usr/lib/python-exec', EPYTHON)
# in python3.9+, __file__ paths are absolute
if sys.version_info >= (3, 9):
target = os.path.abspath(target)
Expand Down