mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 19:33:34 +08:00
posix shell: use /bin/sh instead of bash
This uses the systems default shell: - Ubuntu: dash - Fedora: bash Since bash is invoked via /bin/sh, it operates in POSIX mode: https://tiswww.case.edu/php/chet/bash/POSIX - remove '# Ignore the expand_aliases command in zshell.' Not needed because the shell operates in POSIX mode - [[ is bashism -> use [ - autostart_files=( $autostart_file_match ) is not supported in dash, so use 'ls' - shellcheck runs the dash flavor, since dash is a minimalistic shell. Tested on dash & bash.
This commit is contained in:
@@ -99,8 +99,7 @@ static void register_sig_handler();
|
||||
static void set_cpu_scaling();
|
||||
static int create_symlinks_if_needed(std::string &data_path);
|
||||
static int create_dirs();
|
||||
static int run_startup_bash_script(const std::string &commands_file, const std::string &absolute_binary_path,
|
||||
int instance);
|
||||
static int run_startup_script(const std::string &commands_file, const std::string &absolute_binary_path, int instance);
|
||||
static std::string get_absolute_binary_path(const std::string &argv0);
|
||||
static void wait_to_exit();
|
||||
static bool is_already_running(int instance);
|
||||
@@ -123,7 +122,7 @@ int main(int argc, char **argv)
|
||||
bool pxh_off = false;
|
||||
|
||||
/* Symlinks point to all commands that can be used as a client with a prefix. */
|
||||
const char prefix[] = PX4_BASH_PREFIX;
|
||||
const char prefix[] = PX4_SHELL_COMMAND_PREFIX;
|
||||
int path_length = 0;
|
||||
|
||||
std::string absolute_binary_path; // full path to the px4 binary being executed
|
||||
@@ -275,7 +274,7 @@ int main(int argc, char **argv)
|
||||
px4::init_once();
|
||||
px4::init(argc, argv, "px4");
|
||||
|
||||
ret = run_startup_bash_script(commands_file, absolute_binary_path, instance);
|
||||
ret = run_startup_script(commands_file, absolute_binary_path, instance);
|
||||
|
||||
// We now block here until we need to exit.
|
||||
if (pxh_off) {
|
||||
@@ -479,16 +478,12 @@ std::string get_absolute_binary_path(const std::string &argv0)
|
||||
return pwd() + "/" + base;
|
||||
}
|
||||
|
||||
int run_startup_bash_script(const std::string &commands_file, const std::string &absolute_binary_path,
|
||||
int instance)
|
||||
int run_startup_script(const std::string &commands_file, const std::string &absolute_binary_path,
|
||||
int instance)
|
||||
{
|
||||
#ifdef __DF_BEBOP
|
||||
std::string bash_command("sh ");
|
||||
#else
|
||||
std::string bash_command("bash ");
|
||||
#endif
|
||||
std::string shell_command("/bin/sh ");
|
||||
|
||||
bash_command += commands_file + ' ' + std::to_string(instance);
|
||||
shell_command += commands_file + ' ' + std::to_string(instance);
|
||||
|
||||
// Update the PATH variable to include the absolute_binary_path
|
||||
// (required for the px4-alias.sh script and px4-* commands).
|
||||
@@ -526,12 +521,12 @@ int run_startup_bash_script(const std::string &commands_file, const std::string
|
||||
}
|
||||
|
||||
|
||||
PX4_INFO("Calling startup script: %s", bash_command.c_str());
|
||||
PX4_INFO("Calling startup script: %s", shell_command.c_str());
|
||||
|
||||
int ret = 0;
|
||||
|
||||
if (!bash_command.empty()) {
|
||||
ret = system(bash_command.c_str());
|
||||
if (!shell_command.empty()) {
|
||||
ret = system(shell_command.c_str());
|
||||
|
||||
if (ret == 0) {
|
||||
PX4_INFO("Startup script returned successfully");
|
||||
@@ -560,7 +555,7 @@ void print_usage()
|
||||
printf("\n");
|
||||
printf(" px4 [-h|-d] [-s <startup_file>] [-t <test_data_directory>] [<rootfs_directory>] [-i <instance>]\n");
|
||||
printf("\n");
|
||||
printf(" -s <startup_file> bash start script to be used as startup (default=etc/init.d/rcS)\n");
|
||||
printf(" -s <startup_file> shell script to be used as startup (default=etc/init.d/rcS)\n");
|
||||
printf(" <rootfs_directory> directory where startup files and mixers are located,\n");
|
||||
printf(" (if not given, CWD is used)\n");
|
||||
printf(" -i <instance> px4 instance id to run multiple instances [0...N], default=0\n");
|
||||
|
||||
Reference in New Issue
Block a user