Make $PATH search in SystemExec actually work
Make searching of $PATH work when a SystemExec is created from a command-line, by making sure that argv[0] is set to the discovered path.
This commit is contained in:
parent
5edca6c96e
commit
c03034b7d6
@ -195,10 +195,13 @@ SystemExec::SystemExec (std::string command, const std::map<char, std::string> s
|
|||||||
{
|
{
|
||||||
init ();
|
init ();
|
||||||
make_argp_escaped(command, subs);
|
make_argp_escaped(command, subs);
|
||||||
if (!find_file (Searchpath (Glib::getenv ("PATH")), argp[0], cmd)) {
|
|
||||||
// not found in path - use as-is
|
if (find_file (Searchpath (Glib::getenv ("PATH")), argp[0], cmd)) {
|
||||||
cmd = argp[0];
|
// argp[0] exists in $PATH` - set it to the actual path where it was found
|
||||||
|
free (argp[0]);
|
||||||
|
argp[0] = strdup(cmd.c_str ());
|
||||||
}
|
}
|
||||||
|
// else argp[0] not found in path - leave it as-is, it might be an absolute path
|
||||||
|
|
||||||
// Glib::find_program_in_path () is only available in Glib >= 2.28
|
// Glib::find_program_in_path () is only available in Glib >= 2.28
|
||||||
// cmd = Glib::find_program_in_path (argp[0]);
|
// cmd = Glib::find_program_in_path (argp[0]);
|
||||||
@ -281,13 +284,13 @@ SystemExec::~SystemExec ()
|
|||||||
terminate ();
|
terminate ();
|
||||||
if (envp) {
|
if (envp) {
|
||||||
for (int i=0;envp[i];++i) {
|
for (int i=0;envp[i];++i) {
|
||||||
free(envp[i]);
|
free(envp[i]);
|
||||||
}
|
}
|
||||||
free (envp);
|
free (envp);
|
||||||
}
|
}
|
||||||
if (argp) {
|
if (argp) {
|
||||||
for (int i=0;argp[i];++i) {
|
for (int i=0;argp[i];++i) {
|
||||||
free(argp[i]);
|
free(argp[i]);
|
||||||
}
|
}
|
||||||
free (argp);
|
free (argp);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user