posix main.cpp: better reporting e.g. when there are permission problems

- if somebody tries to use the shell with insufficient permissions he will be told so

Signed-off-by: Roman <bapstroman@gmail.com>
This commit is contained in:
Roman
2018-09-13 15:51:00 +02:00
committed by Roman Bapst
parent 2d59ead1bf
commit 5847ab4607

View File

@@ -159,7 +159,13 @@ int main(int argc, char **argv)
PX4_DEBUG("instance: %i", instance);
if (!is_already_running(instance)) {
PX4_ERR("PX4 daemon not running yet");
if (errno) {
PX4_ERR("Failed to communicate with daemon: %s", strerror(errno));
} else {
PX4_ERR("PX4 daemon not running yet");
}
return -1;
}
@@ -224,7 +230,7 @@ int main(int argc, char **argv)
if (is_already_running(instance)) {
// allow running multiple instances, but the server is only started for the first
PX4_INFO("PX4 daemon already running for instance %i", instance);
PX4_INFO("PX4 daemon already running for instance %i (%s)", instance, strerror(errno));
return -1;
}
@@ -581,12 +587,14 @@ bool is_already_running(int instance)
if (fcntl(fd, F_SETLK, &fl) == -1) {
// We failed to create a file lock, must be already locked.
if (errno == EACCES || errno == EAGAIN) {
return true;
}
return false;
}
errno = 0;
return false;
}