forked from Archive/PX4-Autopilot
px4_daemon: fixes for clang-tidy
Also ignore the warning: error: calling 'system' uses a command processor [cert-env33-c,-warnings-as-errors]
This commit is contained in:
parent
efb202106f
commit
ec09379813
|
@ -1,5 +1,6 @@
|
||||||
Checks: '*
|
Checks: '*
|
||||||
,-cert-dcl50-cpp
|
,-cert-dcl50-cpp
|
||||||
|
,-cert-env33-c
|
||||||
,-cert-err34-c
|
,-cert-err34-c
|
||||||
,-cert-err58-cpp
|
,-cert-err58-cpp
|
||||||
,-cert-msc30-c
|
,-cert-msc30-c
|
||||||
|
|
|
@ -88,7 +88,7 @@ static volatile bool _exit_requested = false;
|
||||||
|
|
||||||
namespace px4
|
namespace px4
|
||||||
{
|
{
|
||||||
void init_once(void);
|
void init_once();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sig_int_handler(int sig_num);
|
static void sig_int_handler(int sig_num);
|
||||||
|
@ -174,9 +174,9 @@ int main(int argc, char **argv)
|
||||||
} else {
|
} else {
|
||||||
/* Server/daemon apps need to parse the command line arguments. */
|
/* Server/daemon apps need to parse the command line arguments. */
|
||||||
|
|
||||||
std::string data_path = "";
|
std::string data_path;
|
||||||
std::string commands_file = "etc/init.d/rcS";
|
std::string commands_file = "etc/init.d/rcS";
|
||||||
std::string test_data_path = "";
|
std::string test_data_path;
|
||||||
int instance = 0;
|
int instance = 0;
|
||||||
|
|
||||||
int myoptind = 1;
|
int myoptind = 1;
|
||||||
|
@ -234,8 +234,12 @@ int main(int argc, char **argv)
|
||||||
if (test_data_path != "") {
|
if (test_data_path != "") {
|
||||||
const std::string required_test_data_path = "./test_data";
|
const std::string required_test_data_path = "./test_data";
|
||||||
|
|
||||||
if (!dir_exists(required_test_data_path.c_str())) {
|
if (!dir_exists(required_test_data_path)) {
|
||||||
symlink(test_data_path.c_str(), required_test_data_path.c_str());
|
ret = symlink(test_data_path.c_str(), required_test_data_path.c_str());
|
||||||
|
|
||||||
|
if (ret != PX4_OK) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,14 +297,14 @@ int create_symlinks_if_needed(std::string &data_path)
|
||||||
{
|
{
|
||||||
std::string current_path = pwd();
|
std::string current_path = pwd();
|
||||||
|
|
||||||
if (data_path.size() == 0) {
|
if (data_path.empty()) {
|
||||||
// No data path given, we'll just try to use the current working dir.
|
// No data path given, we'll just try to use the current working dir.
|
||||||
data_path = current_path;
|
data_path = current_path;
|
||||||
PX4_INFO("assuming working directory is rootfs, no symlinks needed.");
|
PX4_INFO("assuming working directory is rootfs, no symlinks needed.");
|
||||||
return PX4_OK;
|
return PX4_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data_path.compare(current_path) == 0) {
|
if (data_path == current_path) {
|
||||||
// We are already running in the data path, so no need to symlink
|
// We are already running in the data path, so no need to symlink
|
||||||
PX4_INFO("working directory seems to be rootfs, no symlinks needed");
|
PX4_INFO("working directory seems to be rootfs, no symlinks needed");
|
||||||
return PX4_OK;
|
return PX4_OK;
|
||||||
|
@ -313,7 +317,7 @@ int create_symlinks_if_needed(std::string &data_path)
|
||||||
std::string src_path = data_path;
|
std::string src_path = data_path;
|
||||||
std::string dest_path = current_path + "/" + path_sym_link;
|
std::string dest_path = current_path + "/" + path_sym_link;
|
||||||
|
|
||||||
if (dir_exists(dest_path.c_str())) {
|
if (dir_exists(dest_path)) {
|
||||||
return PX4_OK;
|
return PX4_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,10 +389,10 @@ void register_sig_handler()
|
||||||
sig_segv.sa_handler = sig_segv_handler;
|
sig_segv.sa_handler = sig_segv_handler;
|
||||||
sig_segv.sa_flags = SA_RESTART | SA_SIGINFO;
|
sig_segv.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||||
|
|
||||||
sigaction(SIGINT, &sig_int, NULL);
|
sigaction(SIGINT, &sig_int, nullptr);
|
||||||
//sigaction(SIGTERM, &sig_int, NULL);
|
//sigaction(SIGTERM, &sig_int, nullptr);
|
||||||
sigaction(SIGFPE, &sig_fpe, NULL);
|
sigaction(SIGFPE, &sig_fpe, nullptr);
|
||||||
sigaction(SIGPIPE, &sig_pipe, NULL);
|
sigaction(SIGPIPE, &sig_pipe, nullptr);
|
||||||
sigaction(SIGSEGV, &sig_segv, nullptr);
|
sigaction(SIGSEGV, &sig_segv, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,7 +442,7 @@ std::string get_absolute_binary_path(const std::string &argv0)
|
||||||
{
|
{
|
||||||
// On Linux we could also use readlink("/proc/self/exe", buf, bufsize) to get the absolute path
|
// On Linux we could also use readlink("/proc/self/exe", buf, bufsize) to get the absolute path
|
||||||
|
|
||||||
std::size_t last_slash = argv0.find_last_of("/");
|
std::size_t last_slash = argv0.find_last_of('/');
|
||||||
|
|
||||||
if (last_slash == std::string::npos) {
|
if (last_slash == std::string::npos) {
|
||||||
// either relative path or in PATH (PATH is ignored here)
|
// either relative path or in PATH (PATH is ignored here)
|
||||||
|
|
|
@ -309,8 +309,8 @@ Client::register_sig_handler()
|
||||||
// been pressed, and we can't wait for the return value from the
|
// been pressed, and we can't wait for the return value from the
|
||||||
// cancelled command.
|
// cancelled command.
|
||||||
sig_int.sa_flags = SA_RESTART;
|
sig_int.sa_flags = SA_RESTART;
|
||||||
sigaction(SIGINT, &sig_int, NULL);
|
sigaction(SIGINT, &sig_int, nullptr);
|
||||||
sigaction(SIGTERM, &sig_int, NULL);
|
sigaction(SIGTERM, &sig_int, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -52,7 +52,7 @@ void History::try_to_add(const std::string &line)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't add duplicate entries.
|
// Don't add duplicate entries.
|
||||||
if (!_history.empty() && line.compare(_history.back()) == 0) {
|
if (!_history.empty() && line == _history.back()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ int Pxh::process_line(const std::string &line, bool silently_fail)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_apps.size() == 0) {
|
if (_apps.empty()) {
|
||||||
init_app_map(_apps);
|
init_app_map(_apps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ int Pxh::process_line(const std::string &line, bool silently_fail)
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
} else if (command.compare("help") == 0) {
|
} else if (command == "help") {
|
||||||
list_builtins(_apps);
|
list_builtins(_apps);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ void Pxh::run_pxh()
|
||||||
|
|
||||||
_setup_term();
|
_setup_term();
|
||||||
|
|
||||||
std::string mystr = "";
|
std::string mystr;
|
||||||
int cursor_position = 0; // position of the cursor from right to left
|
int cursor_position = 0; // position of the cursor from right to left
|
||||||
// (0: all the way to the right, mystr.length: all the way to the left)
|
// (0: all the way to the right, mystr.length: all the way to the left)
|
||||||
|
|
||||||
|
@ -262,10 +262,10 @@ void Pxh::_setup_term()
|
||||||
term.c_lflag &= ~ICANON;
|
term.c_lflag &= ~ICANON;
|
||||||
term.c_lflag &= ~ECHO;
|
term.c_lflag &= ~ECHO;
|
||||||
tcsetattr(0, TCSANOW, &term);
|
tcsetattr(0, TCSANOW, &term);
|
||||||
setbuf(stdin, NULL);
|
setbuf(stdin, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pxh::_restore_term(void)
|
void Pxh::_restore_term()
|
||||||
{
|
{
|
||||||
if (_instance) {
|
if (_instance) {
|
||||||
tcsetattr(0, TCSANOW, &_instance->_orig_term);
|
tcsetattr(0, TCSANOW, &_instance->_orig_term);
|
||||||
|
|
|
@ -73,9 +73,9 @@ int
|
||||||
Server::start()
|
Server::start()
|
||||||
{
|
{
|
||||||
if (0 != pthread_create(&_server_main_pthread,
|
if (0 != pthread_create(&_server_main_pthread,
|
||||||
NULL,
|
nullptr,
|
||||||
_server_main_trampoline,
|
_server_main_trampoline,
|
||||||
NULL)) {
|
nullptr)) {
|
||||||
|
|
||||||
PX4_ERR("error creating client handler thread");
|
PX4_ERR("error creating client handler thread");
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ Server::_server_main_trampoline(void *arg)
|
||||||
_instance->_server_main(arg);
|
_instance->_server_main(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::_pthread_key_destructor(void *arg)
|
void Server::_pthread_key_destructor(void *arg)
|
||||||
|
@ -156,7 +156,6 @@ Server::_server_main(void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
close(client_send_pipe_fd);
|
close(client_send_pipe_fd);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -214,7 +213,7 @@ Server::_execute_cmd_packet(const client_send_packet_s &packet)
|
||||||
args->is_atty = packet.payload.execute_msg.is_atty;
|
args->is_atty = packet.payload.execute_msg.is_atty;
|
||||||
|
|
||||||
_lock(); // need to lock, otherwise the thread could already exit before we insert into the map
|
_lock(); // need to lock, otherwise the thread could already exit before we insert into the map
|
||||||
ret = pthread_create(&new_pthread, NULL, Server::_run_cmd, (void *)args);
|
ret = pthread_create(&new_pthread, nullptr, Server::_run_cmd, (void *)args);
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
PX4_ERR("could not start pthread (%i)", ret);
|
PX4_ERR("could not start pthread (%i)", ret);
|
||||||
|
@ -284,7 +283,7 @@ void
|
||||||
// We register thread specific data. This is used for PX4_INFO (etc.) log calls.
|
// We register thread specific data. This is used for PX4_INFO (etc.) log calls.
|
||||||
CmdThreadSpecificData *thread_data_ptr;
|
CmdThreadSpecificData *thread_data_ptr;
|
||||||
|
|
||||||
if ((thread_data_ptr = (CmdThreadSpecificData *)pthread_getspecific(_instance->_key)) == NULL) {
|
if ((thread_data_ptr = (CmdThreadSpecificData *)pthread_getspecific(_instance->_key)) == nullptr) {
|
||||||
thread_data_ptr = new CmdThreadSpecificData;
|
thread_data_ptr = new CmdThreadSpecificData;
|
||||||
thread_data_ptr->pipe_fd = pipe_fd;
|
thread_data_ptr->pipe_fd = pipe_fd;
|
||||||
thread_data_ptr->is_atty = is_atty;
|
thread_data_ptr->is_atty = is_atty;
|
||||||
|
@ -302,7 +301,7 @@ void
|
||||||
// Clean up before returning.
|
// Clean up before returning.
|
||||||
_instance->_cleanup_thread(client_uuid);
|
_instance->_cleanup_thread(client_uuid);
|
||||||
|
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ int get_stdout_pipe_buffer(char **buffer, unsigned *max_length, bool *is_atty)
|
||||||
// have any thread specific data set and we won't have a pipe to write
|
// have any thread specific data set and we won't have a pipe to write
|
||||||
// stdout to.
|
// stdout to.
|
||||||
if ((thread_data_ptr = (Server::CmdThreadSpecificData *)pthread_getspecific(
|
if ((thread_data_ptr = (Server::CmdThreadSpecificData *)pthread_getspecific(
|
||||||
Server::get_pthread_key())) == NULL) {
|
Server::get_pthread_key())) == nullptr) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ int send_stdout_pipe_buffer(unsigned buffer_length)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((thread_data_ptr = (Server::CmdThreadSpecificData *)pthread_getspecific(
|
if ((thread_data_ptr = (Server::CmdThreadSpecificData *)pthread_getspecific(
|
||||||
Server::get_pthread_key())) == NULL) {
|
Server::get_pthread_key())) == nullptr) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,11 +117,11 @@ int send_stdout_pipe_buffer(unsigned buffer_length)
|
||||||
// Check if we can write first by writing 0 bytes.
|
// Check if we can write first by writing 0 bytes.
|
||||||
// If we don't do this, we'll get SIGPIPE and be very unhappy
|
// If we don't do this, we'll get SIGPIPE and be very unhappy
|
||||||
// because the whole process will go down.
|
// because the whole process will go down.
|
||||||
int ret = write(pipe_fd, NULL, 0);
|
int ret = write(pipe_fd, nullptr, 0);
|
||||||
|
|
||||||
if (ret == 0 && errno == EPIPE) {
|
if (ret == 0 && errno == EPIPE) {
|
||||||
printf("Error: can't write to closed pipe, giving up.\n");
|
printf("Error: can't write to closed pipe, giving up.\n");
|
||||||
pthread_exit(NULL);
|
pthread_exit(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bytes_sent = write(pipe_fd, packet, bytes_to_send);
|
int bytes_sent = write(pipe_fd, packet, bytes_to_send);
|
||||||
|
|
Loading…
Reference in New Issue