diff --git a/init/README.md b/init/README.md index 13f1bac65..726c0cc94 100644 --- a/init/README.md +++ b/init/README.md @@ -322,6 +322,10 @@ runs the service. This is mutually exclusive with the console option, which additionally connects stdin to the given console. +`task_profiles [ \* ]` +> Set task profiles for the process when it forks. This is designed to replace the use of + writepid option for moving a process into a cgroup. + `timeout_period ` > Provide a timeout after which point the service will be killed. The oneshot keyword is respected here, so oneshot services do not automatically restart, however all other services will. @@ -356,6 +360,8 @@ runs the service. cgroup/cpuset usage. If no files under /dev/cpuset/ are specified, but the system property 'ro.cpuset.default' is set to a non-empty cpuset name (e.g. '/foreground'), then the pid is written to file /dev/cpuset/_cpuset\_name_/tasks. + The use of this option for moving a process into a cgroup is obsolete. Please + use task_profiles option instead. Triggers diff --git a/init/service.cpp b/init/service.cpp index b12d11aec..69f944eb2 100644 --- a/init/service.cpp +++ b/init/service.cpp @@ -511,6 +511,10 @@ Result Service::Start() { LOG(ERROR) << "failed to write pid to files: " << result.error(); } + if (task_profiles_.size() > 0 && !SetTaskProfiles(getpid(), task_profiles_)) { + LOG(ERROR) << "failed to set task profiles"; + } + // As requested, set our gid, supplemental gids, uid, context, and // priority. Aborts on failure. SetProcessAttributesAndCaps(); diff --git a/init/service.h b/init/service.h index 9f1d697f0..34ed5eff9 100644 --- a/init/service.h +++ b/init/service.h @@ -170,6 +170,8 @@ class Service { std::vector writepid_files_; + std::vector task_profiles_; + std::set interfaces_; // e.g. some.package.foo@1.0::IBaz/instance-name // keycodes for triggering this service via /dev/input/input* diff --git a/init/service_parser.cpp b/init/service_parser.cpp index c54ed71d4..bdac0777b 100644 --- a/init/service_parser.cpp +++ b/init/service_parser.cpp @@ -360,6 +360,12 @@ Result ServiceParser::ParseShutdown(std::vector&& args) { return Error() << "Invalid shutdown option"; } +Result ServiceParser::ParseTaskProfiles(std::vector&& args) { + args.erase(args.begin()); + service_->task_profiles_ = std::move(args); + return {}; +} + Result ServiceParser::ParseTimeoutPeriod(std::vector&& args) { int period; if (!ParseInt(args[1], &period, 1)) { @@ -529,6 +535,7 @@ const KeywordMap& ServiceParser::GetParserMap() con {"sigstop", {0, 0, &ServiceParser::ParseSigstop}}, {"socket", {3, 6, &ServiceParser::ParseSocket}}, {"stdio_to_kmsg", {0, 0, &ServiceParser::ParseStdioToKmsg}}, + {"task_profiles", {1, kMax, &ServiceParser::ParseTaskProfiles}}, {"timeout_period", {1, 1, &ServiceParser::ParseTimeoutPeriod}}, {"updatable", {0, 0, &ServiceParser::ParseUpdatable}}, {"user", {1, 1, &ServiceParser::ParseUser}}, diff --git a/init/service_parser.h b/init/service_parser.h index 7bb0cc085..0fd2da588 100644 --- a/init/service_parser.h +++ b/init/service_parser.h @@ -78,6 +78,7 @@ class ServiceParser : public SectionParser { Result ParseSigstop(std::vector&& args); Result ParseSocket(std::vector&& args); Result ParseStdioToKmsg(std::vector&& args); + Result ParseTaskProfiles(std::vector&& args); Result ParseTimeoutPeriod(std::vector&& args); Result ParseFile(std::vector&& args); Result ParseUser(std::vector&& args);