Skip to content

Commit

Permalink
AP_HAL_SITL: work around bug in dash
Browse files Browse the repository at this point in the history
dash doesn't search the path for scripts, so allow user to specify path to ArduPilot scripts
  • Loading branch information
peterbarker authored and tridge committed Aug 7, 2024
1 parent 1f01f75 commit b642651
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libraries/AP_HAL_SITL/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,24 @@ static void run_command_on_ownpid(const char *commandname)
// find dumpstack command:
const char *command_filepath = commandname; // if we can't find it trust in PATH
struct stat statbuf;
const char *custom_scripts_dir_path = getenv("AP_SCRIPTS_DIR_PATH");
char *custom_scripts_dir_path_pattern = nullptr;
if (custom_scripts_dir_path != nullptr) {
if (asprintf(&custom_scripts_dir_path_pattern, "%s/%%s", custom_scripts_dir_path) == -1) {
custom_scripts_dir_path_pattern = nullptr;
}
}
const char *paths[] {
custom_scripts_dir_path_pattern,
"Tools/scripts/%s",
"APM/Tools/scripts/%s", // for autotest server
"../Tools/scripts/%s", // when run from e.g. ArduCopter subdirectory
};
char buffer[60];
for (uint8_t i=0; i<ARRAY_SIZE(paths); i++) {
if (paths[i] == nullptr) {
continue;
}
// form up a filepath from each path and commandname; if it
// exists, use it
snprintf(buffer, sizeof(buffer), paths[i], commandname);
Expand All @@ -80,6 +91,7 @@ static void run_command_on_ownpid(const char *commandname)
break;
}
}
free(custom_scripts_dir_path_pattern);

char progname[100];
int n = readlink("/proc/self/exe", progname, sizeof(progname)-1);
Expand Down

0 comments on commit b642651

Please sign in to comment.