Add --purge_shm_base to aos_starter
This removes everything in /dev/shm/aos before doing anything. This
gives us options to use SUID on the roboRIO to become admin and then
clean up the old shm_base as admin. Otherwise, we were getting into a
crash loop.
Change-Id: Ia880af19a63cd30043fe92df3bdb2d13fd08dfb8
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/starter/starter.sh b/aos/starter/starter.sh
index d4281c5..face963 100755
--- a/aos/starter/starter.sh
+++ b/aos/starter/starter.sh
@@ -13,8 +13,7 @@
elif [[ "$(hostname)" == "pi-"* ]]; then
# We have systemd configured to handle restarting, so just exec.
export PATH="${PATH}:/home/pi/bin"
- rm -rf /dev/shm/aos
- exec starterd --user=pi
+ exec starterd --user=pi --purge_shm_base
else
ROBOT_CODE="${HOME}/bin"
fi
@@ -22,6 +21,5 @@
cd "${ROBOT_CODE}"
export PATH="${PATH}:${ROBOT_CODE}"
while true; do
- rm -rf /dev/shm/aos
- starterd 2>&1
+ starterd --purge_shm_base 2>&1
done
diff --git a/aos/starter/starterd.cc b/aos/starter/starterd.cc
index 54f1bb4..19117de 100644
--- a/aos/starter/starterd.cc
+++ b/aos/starter/starterd.cc
@@ -2,15 +2,25 @@
#include <sys/types.h>
#include "aos/init.h"
+#include "aos/starter/starterd_lib.h"
+#include "aos/util/file.h"
#include "gflags/gflags.h"
-#include "starterd_lib.h"
DEFINE_string(config, "aos_config.json", "File path of aos configuration");
DEFINE_string(user, "",
"Starter runs as though this user ran a SUID binary if set.");
+DECLARE_string(shm_base);
+DEFINE_bool(purge_shm_base, false,
+ "If true, delete everything in --shm_base before starting.");
+
int main(int argc, char **argv) {
aos::InitGoogle(&argc, &argv);
+
+ if (FLAGS_purge_shm_base) {
+ aos::util::UnlinkRecursive(FLAGS_shm_base);
+ }
+
if (!FLAGS_user.empty()) {
uid_t uid;
uid_t gid;