Loading tools/bit/adb.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -308,7 +308,7 @@ run_instrumentation_test(const string& packageName, const string& runner, const const char* prog = cmd.GetProg(); char* const* argv = cmd.GetArgv(); char* const* env = cmd.GetEnv(); execvpe(prog, argv, env); exec_with_path_search(prog, argv, env); print_error("Unable to run command: %s", prog); exit(1); } else { Loading tools/bit/command.cpp +37 −3 Original line number Diff line number Diff line Loading @@ -22,10 +22,13 @@ #include <errno.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <sys/wait.h> extern char **environ; Command::Command(const string& prog) :prog(prog) { Loading Loading @@ -118,7 +121,7 @@ get_command_output(const Command& command, int* err, bool quiet) const char* prog = command.GetProg(); char* const* argv = command.GetArgv(); char* const* env = command.GetEnv(); execvpe(prog, argv, env); exec_with_path_search(prog, argv, env); if (!quiet) { print_error("Unable to run command: %s", prog); } Loading Loading @@ -166,7 +169,7 @@ run_command(const Command& command) const char* prog = command.GetProg(); char* const* argv = command.GetArgv(); char* const* env = command.GetEnv(); execvpe(prog, argv, env); exec_with_path_search(prog, argv, env); print_error("Unable to run command: %s", prog); exit(1); } else { Loading @@ -181,3 +184,34 @@ run_command(const Command& command) } } int exec_with_path_search(const char* prog, char const* const* argv, char const* const* envp) { if (prog[0] == '/') { return execve(prog, (char*const*)argv, (char*const*)envp); } else { char* pathEnv = strdup(getenv("PATH")); if (pathEnv == NULL) { return 1; } char* dir = pathEnv; while (dir) { char* next = strchr(dir, ':'); if (next != NULL) { *next = '\0'; next++; } if (dir[0] == '/') { struct stat st; string executable = string(dir) + "/" + prog; if (stat(executable.c_str(), &st) == 0) { execve(executable.c_str(), (char*const*)argv, (char*const*)envp); } } dir = next; } free(pathEnv); return 1; } } tools/bit/command.h +3 −0 Original line number Diff line number Diff line Loading @@ -54,5 +54,8 @@ string get_command_output(const Command& command, int* err, bool quiet=false); */ int run_command(const Command& command); // Mac OS doesn't have execvpe. This is the same as execvpe. int exec_with_path_search(const char* prog, char const* const* argv, char const* const* envp); #endif // COMMAND_H Loading
tools/bit/adb.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -308,7 +308,7 @@ run_instrumentation_test(const string& packageName, const string& runner, const const char* prog = cmd.GetProg(); char* const* argv = cmd.GetArgv(); char* const* env = cmd.GetEnv(); execvpe(prog, argv, env); exec_with_path_search(prog, argv, env); print_error("Unable to run command: %s", prog); exit(1); } else { Loading
tools/bit/command.cpp +37 −3 Original line number Diff line number Diff line Loading @@ -22,10 +22,13 @@ #include <errno.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <sys/wait.h> extern char **environ; Command::Command(const string& prog) :prog(prog) { Loading Loading @@ -118,7 +121,7 @@ get_command_output(const Command& command, int* err, bool quiet) const char* prog = command.GetProg(); char* const* argv = command.GetArgv(); char* const* env = command.GetEnv(); execvpe(prog, argv, env); exec_with_path_search(prog, argv, env); if (!quiet) { print_error("Unable to run command: %s", prog); } Loading Loading @@ -166,7 +169,7 @@ run_command(const Command& command) const char* prog = command.GetProg(); char* const* argv = command.GetArgv(); char* const* env = command.GetEnv(); execvpe(prog, argv, env); exec_with_path_search(prog, argv, env); print_error("Unable to run command: %s", prog); exit(1); } else { Loading @@ -181,3 +184,34 @@ run_command(const Command& command) } } int exec_with_path_search(const char* prog, char const* const* argv, char const* const* envp) { if (prog[0] == '/') { return execve(prog, (char*const*)argv, (char*const*)envp); } else { char* pathEnv = strdup(getenv("PATH")); if (pathEnv == NULL) { return 1; } char* dir = pathEnv; while (dir) { char* next = strchr(dir, ':'); if (next != NULL) { *next = '\0'; next++; } if (dir[0] == '/') { struct stat st; string executable = string(dir) + "/" + prog; if (stat(executable.c_str(), &st) == 0) { execve(executable.c_str(), (char*const*)argv, (char*const*)envp); } } dir = next; } free(pathEnv); return 1; } }
tools/bit/command.h +3 −0 Original line number Diff line number Diff line Loading @@ -54,5 +54,8 @@ string get_command_output(const Command& command, int* err, bool quiet=false); */ int run_command(const Command& command); // Mac OS doesn't have execvpe. This is the same as execvpe. int exec_with_path_search(const char* prog, char const* const* argv, char const* const* envp); #endif // COMMAND_H