mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-22 01:12:31 +00:00
Allow chrooting the application
This commit is contained in:
@@ -14,6 +14,15 @@ echo program: $program
|
|||||||
echo model: $model
|
echo model: $model
|
||||||
echo build_path: $build_path
|
echo build_path: $build_path
|
||||||
|
|
||||||
|
if [ "$chroot" == "1" ]
|
||||||
|
then
|
||||||
|
chroot_enabled=-c
|
||||||
|
sudo_enabled=sudo
|
||||||
|
else
|
||||||
|
chroot_enabled=""
|
||||||
|
sudo_enabled=""
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$model" == "" ] || [ "$model" == "none" ]
|
if [ "$model" == "" ] || [ "$model" == "none" ]
|
||||||
then
|
then
|
||||||
echo "empty model, setting iris as default"
|
echo "empty model, setting iris as default"
|
||||||
@@ -48,7 +57,7 @@ if [ "$program" == "jmavsim" ] && [ "$no_sim" == "" ]
|
|||||||
then
|
then
|
||||||
cd Tools/jMAVSim
|
cd Tools/jMAVSim
|
||||||
ant
|
ant
|
||||||
nice -n -10 java -Djava.ext.dirs= -cp lib/*:out/production/jmavsim.jar me.drton.jmavsim.Simulator -udp 127.0.0.1:14560 &
|
java -Djava.ext.dirs= -cp lib/*:out/production/jmavsim.jar me.drton.jmavsim.Simulator -udp 127.0.0.1:14560 &
|
||||||
SIM_PID=`echo $!`
|
SIM_PID=`echo $!`
|
||||||
elif [ "$program" == "gazebo" ] && [ "$no_sim" == "" ]
|
elif [ "$program" == "gazebo" ] && [ "$no_sim" == "" ]
|
||||||
then
|
then
|
||||||
@@ -65,7 +74,7 @@ then
|
|||||||
cd Tools/sitl_gazebo/Build
|
cd Tools/sitl_gazebo/Build
|
||||||
cmake -Wno-dev ..
|
cmake -Wno-dev ..
|
||||||
make -j4
|
make -j4
|
||||||
nice -n -10 gzserver --verbose ../worlds/${model}.world &
|
gzserver --verbose ../worlds/${model}.world &
|
||||||
SIM_PID=`echo $!`
|
SIM_PID=`echo $!`
|
||||||
gzclient --verbose &
|
gzclient --verbose &
|
||||||
GUI_PID=`echo $!`
|
GUI_PID=`echo $!`
|
||||||
@@ -96,7 +105,7 @@ elif [ "$debugger" == "valgrind" ]
|
|||||||
then
|
then
|
||||||
valgrind ./mainapp ../../../../${rc_script}_${program}_${model}
|
valgrind ./mainapp ../../../../${rc_script}_${program}_${model}
|
||||||
else
|
else
|
||||||
nice -n -10 ./mainapp ../../../../${rc_script}_${program}_${model}
|
$sudo_enabled ./mainapp $chroot_enabled ../../../../${rc_script}_${program}_${model}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$program" == "jmavsim" ]
|
if [ "$program" == "jmavsim" ]
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "apps.h"
|
#include "apps.h"
|
||||||
#include "px4_middleware.h"
|
#include "px4_middleware.h"
|
||||||
#include "DriverFramework.hpp"
|
#include "DriverFramework.hpp"
|
||||||
@@ -157,6 +158,7 @@ static void process_line(string &line, bool exit_on_fail)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
bool daemon_mode = false;
|
bool daemon_mode = false;
|
||||||
|
bool chroot_on = false;
|
||||||
signal(SIGINT, _SigIntHandler);
|
signal(SIGINT, _SigIntHandler);
|
||||||
signal(SIGFPE, _SigFpeHandler);
|
signal(SIGFPE, _SigFpeHandler);
|
||||||
|
|
||||||
@@ -174,6 +176,9 @@ int main(int argc, char **argv)
|
|||||||
usage();
|
usage();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
} else if (strcmp(argv[index], "-c") == 0) {
|
||||||
|
chroot_on = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
PX4_WARN("Unknown/unhandled parameter: %s", argv[index]);
|
PX4_WARN("Unknown/unhandled parameter: %s", argv[index]);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -203,7 +208,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
px4::init(argc, argv, "mainapp");
|
px4::init(argc, argv, "mainapp");
|
||||||
|
|
||||||
//if commandfile is present, process the commands from the file
|
// if commandfile is present, process the commands from the file
|
||||||
if (commands_file != nullptr) {
|
if (commands_file != nullptr) {
|
||||||
ifstream infile(commands_file);
|
ifstream infile(commands_file);
|
||||||
|
|
||||||
@@ -217,6 +222,34 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chroot_on) {
|
||||||
|
// Lock this application in the current working dir
|
||||||
|
// this is not an attempt to secure the environment,
|
||||||
|
// rather, to replicate a deployed file system.
|
||||||
|
char pwd_path[PATH_MAX];
|
||||||
|
const char *folderpath = "/rootfs/";
|
||||||
|
|
||||||
|
if (nullptr == getcwd(pwd_path, sizeof(pwd_path))) {
|
||||||
|
PX4_ERR("Failed aquiring working dir, abort.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nullptr == strcat(pwd_path, folderpath)) {
|
||||||
|
PX4_ERR("Failed completing path, abort.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chroot(pwd_path)) {
|
||||||
|
PX4_ERR("Failed chrooting application, path: %s, error: %s.", pwd_path, strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chdir("/")) {
|
||||||
|
PX4_ERR("Failed changing to root dir, path: %s, error: %s.", pwd_path, strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!daemon_mode) {
|
if (!daemon_mode) {
|
||||||
string mystr = "";
|
string mystr = "";
|
||||||
string string_buffer[CMD_BUFF_SIZE];
|
string string_buffer[CMD_BUFF_SIZE];
|
||||||
|
|||||||
Reference in New Issue
Block a user