Add option in aos::starter::Application to run as sudo
Previously, the user needed to instantiate the class object with "sudo"
and pass in the name of the actual application as an argument. This was
not very intuitive to readers and maintainers.
Change-Id: I98cd60017babcf345fc66a7a46d9329e96ae00ab
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/starter/subprocess.cc b/aos/starter/subprocess.cc
index 2886c98..23705cc 100644
--- a/aos/starter/subprocess.cc
+++ b/aos/starter/subprocess.cc
@@ -272,9 +272,13 @@
// argv[0] should be the program name
args_.insert(args_.begin(), path_);
+ if (run_as_sudo_) {
+ args_.insert(args_.begin(), kSudo);
+ }
std::vector<char *> cargs = CArgs();
- execvp(path_.c_str(), cargs.data());
+ const char* path = run_as_sudo_ ? kSudo : path_.c_str();
+ execvp(path, cargs.data());
// If we got here, something went wrong
status_pipes_.write->Write(