summaryrefslogtreecommitdiffstats
path: root/init/service.cpp
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2018-04-18 13:51:15 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-04-18 13:51:15 +0000
commitb41879111db50b66894b0285a61f6869cfc76fc1 (patch)
treeb03c0e11b55b80ac888ee9698ea541bf53a31395 /init/service.cpp
parent01ce44b734d8eeb6f29d6038857bcefe4854b7cd (diff)
parent8f38048f7d23686a6f008e24cefb45972299d309 (diff)
downloadsystem_core-b41879111db50b66894b0285a61f6869cfc76fc1.tar.gz
system_core-b41879111db50b66894b0285a61f6869cfc76fc1.tar.bz2
system_core-b41879111db50b66894b0285a61f6869cfc76fc1.zip
Merge "init: add sigstop option for debugging services from their start"
Diffstat (limited to 'init/service.cpp')
-rw-r--r--init/service.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/init/service.cpp b/init/service.cpp
index f9986c5f5..03c2ceec8 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -155,7 +155,7 @@ static void SetUpPidNamespace(const std::string& service_name) {
}
}
-static bool ExpandArgsAndExecv(const std::vector<std::string>& args) {
+static bool ExpandArgsAndExecv(const std::vector<std::string>& args, bool sigstop) {
std::vector<std::string> expanded_args;
std::vector<char*> c_strings;
@@ -169,6 +169,10 @@ static bool ExpandArgsAndExecv(const std::vector<std::string>& args) {
}
c_strings.push_back(nullptr);
+ if (sigstop) {
+ kill(getpid(), SIGSTOP);
+ }
+
return execv(c_strings[0], c_strings.data()) == 0;
}
@@ -582,6 +586,11 @@ Result<Success> Service::ParseSeclabel(const std::vector<std::string>& args) {
return Success();
}
+Result<Success> Service::ParseSigstop(const std::vector<std::string>& args) {
+ sigstop_ = true;
+ return Success();
+}
+
Result<Success> Service::ParseSetenv(const std::vector<std::string>& args) {
environment_vars_.emplace_back(args[1], args[2]);
return Success();
@@ -704,6 +713,7 @@ const Service::OptionParserMap::Map& Service::OptionParserMap::map() const {
{"seclabel", {1, 1, &Service::ParseSeclabel}},
{"setenv", {2, 2, &Service::ParseSetenv}},
{"shutdown", {1, 1, &Service::ParseShutdown}},
+ {"sigstop", {0, 0, &Service::ParseSigstop}},
{"socket", {3, 6, &Service::ParseSocket}},
{"user", {1, 1, &Service::ParseUser}},
{"writepid", {1, kMax, &Service::ParseWritepid}},
@@ -862,7 +872,7 @@ Result<Success> Service::Start() {
// priority. Aborts on failure.
SetProcessAttributes();
- if (!ExpandArgsAndExecv(args_)) {
+ if (!ExpandArgsAndExecv(args_, sigstop_)) {
PLOG(ERROR) << "cannot execve('" << args_[0] << "')";
}