2019-06-26 19:46:20 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "service_parser.h"
|
|
|
|
|
2019-06-26 20:22:52 +02:00
|
|
|
#include <linux/input.h>
|
2019-07-09 22:33:36 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/socket.h>
|
2019-06-26 20:22:52 +02:00
|
|
|
|
2019-07-09 20:00:53 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <sstream>
|
|
|
|
|
2019-06-26 20:22:52 +02:00
|
|
|
#include <android-base/logging.h>
|
|
|
|
#include <android-base/parseint.h>
|
2023-04-25 01:54:59 +02:00
|
|
|
#include <android-base/properties.h>
|
2019-06-26 19:46:20 +02:00
|
|
|
#include <android-base/strings.h>
|
2019-06-26 20:22:52 +02:00
|
|
|
#include <hidl-util/FQName.h>
|
2022-03-31 23:15:11 +02:00
|
|
|
#include <processgroup/processgroup.h>
|
2019-06-26 20:22:52 +02:00
|
|
|
#include <system/thread_defs.h>
|
2019-06-26 19:46:20 +02:00
|
|
|
|
2019-10-23 02:18:42 +02:00
|
|
|
#include "lmkd_service.h"
|
2019-06-26 20:22:52 +02:00
|
|
|
#include "rlimit_parser.h"
|
2019-07-09 22:33:36 +02:00
|
|
|
#include "service_utils.h"
|
2019-06-26 19:46:20 +02:00
|
|
|
#include "util.h"
|
|
|
|
|
2020-02-20 19:50:00 +01:00
|
|
|
#ifdef INIT_FULL_SOURCES
|
2019-06-26 20:22:52 +02:00
|
|
|
#include <android/api-level.h>
|
2019-06-26 19:46:20 +02:00
|
|
|
#include <sys/system_properties.h>
|
|
|
|
|
|
|
|
#include "selinux.h"
|
|
|
|
#else
|
|
|
|
#include "host_init_stubs.h"
|
|
|
|
#endif
|
|
|
|
|
2019-06-26 20:22:52 +02:00
|
|
|
using android::base::ParseInt;
|
|
|
|
using android::base::Split;
|
2019-06-26 19:46:20 +02:00
|
|
|
using android::base::StartsWith;
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace init {
|
|
|
|
|
2019-06-26 20:22:52 +02:00
|
|
|
Result<void> ServiceParser::ParseCapabilities(std::vector<std::string>&& args) {
|
|
|
|
service_->capabilities_ = 0;
|
|
|
|
|
|
|
|
if (!CapAmbientSupported()) {
|
|
|
|
return Error()
|
|
|
|
<< "capabilities requested but the kernel does not support ambient capabilities";
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int last_valid_cap = GetLastValidCap();
|
|
|
|
if (last_valid_cap >= service_->capabilities_->size()) {
|
|
|
|
LOG(WARNING) << "last valid run-time capability is larger than CAP_LAST_CAP";
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 1; i < args.size(); i++) {
|
|
|
|
const std::string& arg = args[i];
|
|
|
|
int res = LookupCap(arg);
|
|
|
|
if (res < 0) {
|
|
|
|
return Errorf("invalid capability '{}'", arg);
|
|
|
|
}
|
|
|
|
unsigned int cap = static_cast<unsigned int>(res); // |res| is >= 0.
|
|
|
|
if (cap > last_valid_cap) {
|
|
|
|
return Errorf("capability '{}' not supported by the kernel", arg);
|
|
|
|
}
|
|
|
|
(*service_->capabilities_)[cap] = true;
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseClass(std::vector<std::string>&& args) {
|
|
|
|
service_->classnames_ = std::set<std::string>(args.begin() + 1, args.end());
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseConsole(std::vector<std::string>&& args) {
|
2019-09-24 01:16:54 +02:00
|
|
|
if (service_->proc_attr_.stdio_to_kmsg) {
|
|
|
|
return Error() << "'console' and 'stdio_to_kmsg' are mutually exclusive";
|
|
|
|
}
|
2019-06-26 20:22:52 +02:00
|
|
|
service_->flags_ |= SVC_CONSOLE;
|
|
|
|
service_->proc_attr_.console = args.size() > 1 ? "/dev/" + args[1] : "";
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseCritical(std::vector<std::string>&& args) {
|
2019-12-26 15:22:28 +01:00
|
|
|
std::optional<std::string> fatal_reboot_target;
|
|
|
|
std::optional<std::chrono::minutes> fatal_crash_window;
|
|
|
|
|
|
|
|
for (auto it = args.begin() + 1; it != args.end(); ++it) {
|
|
|
|
auto arg = android::base::Split(*it, "=");
|
|
|
|
if (arg.size() != 2) {
|
|
|
|
return Error() << "critical: Argument '" << *it << "' is not supported";
|
|
|
|
} else if (arg[0] == "target") {
|
|
|
|
fatal_reboot_target = arg[1];
|
|
|
|
} else if (arg[0] == "window") {
|
|
|
|
int minutes;
|
|
|
|
auto window = ExpandProps(arg[1]);
|
|
|
|
if (!window.ok()) {
|
|
|
|
return Error() << "critical: Could not expand argument ': " << arg[1];
|
|
|
|
}
|
|
|
|
if (*window == "off") {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
if (!ParseInt(*window, &minutes, 0)) {
|
|
|
|
return Error() << "critical: 'fatal_crash_window' must be an integer > 0";
|
|
|
|
}
|
|
|
|
fatal_crash_window = std::chrono::minutes(minutes);
|
|
|
|
} else {
|
|
|
|
return Error() << "critical: Argument '" << *it << "' is not supported";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fatal_reboot_target) {
|
|
|
|
service_->fatal_reboot_target_ = *fatal_reboot_target;
|
|
|
|
}
|
|
|
|
if (fatal_crash_window) {
|
|
|
|
service_->fatal_crash_window_ = *fatal_crash_window;
|
|
|
|
}
|
2019-06-26 20:22:52 +02:00
|
|
|
service_->flags_ |= SVC_CRITICAL;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseDisabled(std::vector<std::string>&& args) {
|
|
|
|
service_->flags_ |= SVC_DISABLED;
|
|
|
|
service_->flags_ |= SVC_RC_DISABLED;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseEnterNamespace(std::vector<std::string>&& args) {
|
|
|
|
if (args[1] != "net") {
|
|
|
|
return Error() << "Init only supports entering network namespaces";
|
|
|
|
}
|
|
|
|
if (!service_->namespaces_.namespaces_to_enter.empty()) {
|
|
|
|
return Error() << "Only one network namespace may be entered";
|
|
|
|
}
|
|
|
|
// Network namespaces require that /sys is remounted, otherwise the old adapters will still be
|
|
|
|
// present. Therefore, they also require mount namespaces.
|
|
|
|
service_->namespaces_.flags |= CLONE_NEWNS;
|
|
|
|
service_->namespaces_.namespaces_to_enter.emplace_back(CLONE_NEWNET, std::move(args[2]));
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-12-02 00:44:31 +01:00
|
|
|
Result<void> ServiceParser::ParseGentleKill(std::vector<std::string>&& args) {
|
|
|
|
service_->flags_ |= SVC_GENTLE_KILL;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-06-26 20:22:52 +02:00
|
|
|
Result<void> ServiceParser::ParseGroup(std::vector<std::string>&& args) {
|
|
|
|
auto gid = DecodeUid(args[1]);
|
2020-02-05 19:49:33 +01:00
|
|
|
if (!gid.ok()) {
|
2019-06-26 20:22:52 +02:00
|
|
|
return Error() << "Unable to decode GID for '" << args[1] << "': " << gid.error();
|
|
|
|
}
|
|
|
|
service_->proc_attr_.gid = *gid;
|
|
|
|
|
|
|
|
for (std::size_t n = 2; n < args.size(); n++) {
|
|
|
|
gid = DecodeUid(args[n]);
|
2020-02-05 19:49:33 +01:00
|
|
|
if (!gid.ok()) {
|
2019-06-26 20:22:52 +02:00
|
|
|
return Error() << "Unable to decode GID for '" << args[n] << "': " << gid.error();
|
|
|
|
}
|
|
|
|
service_->proc_attr_.supp_gids.emplace_back(*gid);
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParsePriority(std::vector<std::string>&& args) {
|
|
|
|
service_->proc_attr_.priority = 0;
|
|
|
|
if (!ParseInt(args[1], &service_->proc_attr_.priority,
|
|
|
|
static_cast<int>(ANDROID_PRIORITY_HIGHEST), // highest is negative
|
|
|
|
static_cast<int>(ANDROID_PRIORITY_LOWEST))) {
|
|
|
|
return Errorf("process priority value must be range {} - {}", ANDROID_PRIORITY_HIGHEST,
|
|
|
|
ANDROID_PRIORITY_LOWEST);
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseInterface(std::vector<std::string>&& args) {
|
|
|
|
const std::string& interface_name = args[1];
|
|
|
|
const std::string& instance_name = args[2];
|
|
|
|
|
2019-07-26 22:14:42 +02:00
|
|
|
// AIDL services don't use fully qualified names and instead just use "interface aidl <name>"
|
|
|
|
if (interface_name != "aidl") {
|
|
|
|
FQName fq_name;
|
|
|
|
if (!FQName::parse(interface_name, &fq_name)) {
|
|
|
|
return Error() << "Invalid fully-qualified name for interface '" << interface_name
|
|
|
|
<< "'";
|
|
|
|
}
|
2019-06-26 20:22:52 +02:00
|
|
|
|
2019-07-26 22:14:42 +02:00
|
|
|
if (!fq_name.isFullyQualified()) {
|
|
|
|
return Error() << "Interface name not fully-qualified '" << interface_name << "'";
|
|
|
|
}
|
2019-06-26 20:22:52 +02:00
|
|
|
|
2019-07-26 22:14:42 +02:00
|
|
|
if (fq_name.isValidValueName()) {
|
|
|
|
return Error() << "Interface name must not be a value name '" << interface_name << "'";
|
|
|
|
}
|
2019-06-26 20:22:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::string fullname = interface_name + "/" + instance_name;
|
|
|
|
|
|
|
|
for (const auto& svc : *service_list_) {
|
2022-03-06 23:51:51 +01:00
|
|
|
if (svc->interfaces().count(fullname) > 0 && !service_->is_override()) {
|
2019-06-26 20:22:52 +02:00
|
|
|
return Error() << "Interface '" << fullname << "' redefined in " << service_->name()
|
|
|
|
<< " but is already defined by " << svc->name();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
service_->interfaces_.insert(fullname);
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseIoprio(std::vector<std::string>&& args) {
|
|
|
|
if (!ParseInt(args[2], &service_->proc_attr_.ioprio_pri, 0, 7)) {
|
|
|
|
return Error() << "priority value must be range 0 - 7";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[1] == "rt") {
|
|
|
|
service_->proc_attr_.ioprio_class = IoSchedClass_RT;
|
|
|
|
} else if (args[1] == "be") {
|
|
|
|
service_->proc_attr_.ioprio_class = IoSchedClass_BE;
|
|
|
|
} else if (args[1] == "idle") {
|
|
|
|
service_->proc_attr_.ioprio_class = IoSchedClass_IDLE;
|
|
|
|
} else {
|
|
|
|
return Error() << "ioprio option usage: ioprio <rt|be|idle> <0-7>";
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseKeycodes(std::vector<std::string>&& args) {
|
|
|
|
auto it = args.begin() + 1;
|
|
|
|
if (args.size() == 2 && StartsWith(args[1], "$")) {
|
2019-07-31 22:59:15 +02:00
|
|
|
auto expanded = ExpandProps(args[1]);
|
2020-02-05 19:49:33 +01:00
|
|
|
if (!expanded.ok()) {
|
2019-07-31 22:59:15 +02:00
|
|
|
return expanded.error();
|
2019-06-26 20:22:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the property is not set, it defaults to none, in which case there are no keycodes
|
|
|
|
// for this service.
|
2020-02-03 15:54:02 +01:00
|
|
|
if (*expanded == "none") {
|
2019-06-26 20:22:52 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:59:15 +02:00
|
|
|
args = Split(*expanded, ",");
|
2019-06-26 20:22:52 +02:00
|
|
|
it = args.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; it != args.end(); ++it) {
|
|
|
|
int code;
|
|
|
|
if (ParseInt(*it, &code, 0, KEY_MAX)) {
|
|
|
|
for (auto& key : service_->keycodes_) {
|
|
|
|
if (key == code) return Error() << "duplicate keycode: " << *it;
|
|
|
|
}
|
|
|
|
service_->keycodes_.insert(
|
|
|
|
std::upper_bound(service_->keycodes_.begin(), service_->keycodes_.end(), code),
|
|
|
|
code);
|
|
|
|
} else {
|
|
|
|
return Error() << "invalid keycode: " << *it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseOneshot(std::vector<std::string>&& args) {
|
|
|
|
service_->flags_ |= SVC_ONESHOT;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseOnrestart(std::vector<std::string>&& args) {
|
|
|
|
args.erase(args.begin());
|
|
|
|
int line = service_->onrestart_.NumCommands() + 1;
|
2020-02-05 19:49:33 +01:00
|
|
|
if (auto result = service_->onrestart_.AddCommand(std::move(args), line); !result.ok()) {
|
2019-06-26 20:22:52 +02:00
|
|
|
return Error() << "cannot add Onrestart command: " << result.error();
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseNamespace(std::vector<std::string>&& args) {
|
|
|
|
for (size_t i = 1; i < args.size(); i++) {
|
|
|
|
if (args[i] == "pid") {
|
|
|
|
service_->namespaces_.flags |= CLONE_NEWPID;
|
|
|
|
// PID namespaces require mount namespaces.
|
|
|
|
service_->namespaces_.flags |= CLONE_NEWNS;
|
|
|
|
} else if (args[i] == "mnt") {
|
|
|
|
service_->namespaces_.flags |= CLONE_NEWNS;
|
|
|
|
} else {
|
|
|
|
return Error() << "namespace must be 'pid' or 'mnt'";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseOomScoreAdjust(std::vector<std::string>&& args) {
|
2019-10-23 02:18:42 +02:00
|
|
|
if (!ParseInt(args[1], &service_->oom_score_adjust_, MIN_OOM_SCORE_ADJUST,
|
|
|
|
MAX_OOM_SCORE_ADJUST)) {
|
|
|
|
return Error() << "oom_score_adjust value must be in range " << MIN_OOM_SCORE_ADJUST
|
|
|
|
<< " - +" << MAX_OOM_SCORE_ADJUST;
|
2019-06-26 20:22:52 +02:00
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseOverride(std::vector<std::string>&& args) {
|
|
|
|
service_->override_ = true;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseMemcgSwappiness(std::vector<std::string>&& args) {
|
|
|
|
if (!ParseInt(args[1], &service_->swappiness_, 0)) {
|
|
|
|
return Error() << "swappiness value must be equal or greater than 0";
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseMemcgLimitInBytes(std::vector<std::string>&& args) {
|
|
|
|
if (!ParseInt(args[1], &service_->limit_in_bytes_, 0)) {
|
|
|
|
return Error() << "limit_in_bytes value must be equal or greater than 0";
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseMemcgLimitPercent(std::vector<std::string>&& args) {
|
|
|
|
if (!ParseInt(args[1], &service_->limit_percent_, 0)) {
|
|
|
|
return Error() << "limit_percent value must be equal or greater than 0";
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseMemcgLimitProperty(std::vector<std::string>&& args) {
|
|
|
|
service_->limit_property_ = std::move(args[1]);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseMemcgSoftLimitInBytes(std::vector<std::string>&& args) {
|
|
|
|
if (!ParseInt(args[1], &service_->soft_limit_in_bytes_, 0)) {
|
|
|
|
return Error() << "soft_limit_in_bytes value must be equal or greater than 0";
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseProcessRlimit(std::vector<std::string>&& args) {
|
|
|
|
auto rlimit = ParseRlimit(args);
|
2020-02-05 19:49:33 +01:00
|
|
|
if (!rlimit.ok()) return rlimit.error();
|
2019-06-26 20:22:52 +02:00
|
|
|
|
|
|
|
service_->proc_attr_.rlimits.emplace_back(*rlimit);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-09-10 19:40:47 +02:00
|
|
|
Result<void> ServiceParser::ParseRebootOnFailure(std::vector<std::string>&& args) {
|
|
|
|
if (service_->on_failure_reboot_target_) {
|
|
|
|
return Error() << "Only one reboot_on_failure command may be specified";
|
|
|
|
}
|
|
|
|
if (!StartsWith(args[1], "shutdown") && !StartsWith(args[1], "reboot")) {
|
|
|
|
return Error()
|
|
|
|
<< "reboot_on_failure commands must begin with either 'shutdown' or 'reboot'";
|
|
|
|
}
|
|
|
|
service_->on_failure_reboot_target_ = std::move(args[1]);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-06-26 20:22:52 +02:00
|
|
|
Result<void> ServiceParser::ParseRestartPeriod(std::vector<std::string>&& args) {
|
|
|
|
int period;
|
init: non-crashing service can restart immediately
This CL allows restart_period to be set to a value shorter than 5s.
Previously this was prohibited to rate limit crashing services. That
behavior is considered to be a bit too conservative because some
services don't crash, but exit deliverately.
adbd is the motivating example. When adb root or adb unroot is
requested, it changes its mode of operation (via sysprop), exits itself,
and restarts (by init) to enter into the mode. However, due to the 5s
delay, the mode change can complete no earlier than 5 seconds after adbd
was started last time. This can slow the mode change when it is
requested right after the boot.
With this CL, restart_period can be set to a value smaller than 5. And
services like adbd can make use of it. However, in ordef to rate limit
crashing service, the default is enforced if the service was crashed
last time. In addition, such intended restart is not counted as crashes
when monitoring successive crashes during booting.
Bug: 286061817
Test: /packages/modules/Virtualization/vm/vm_shell.sh start-microdroid \
--auto-connect -- --protected
* with this change: within 2s
* without this change: over 6s
Change-Id: I1b3f0c92d349e8c8760821cf50fb69997b67b242
2023-06-09 02:52:49 +02:00
|
|
|
if (!ParseInt(args[1], &period, 0)) {
|
|
|
|
return Error() << "restart_period value must be an integer >= 0";
|
2019-06-26 20:22:52 +02:00
|
|
|
}
|
|
|
|
service_->restart_period_ = std::chrono::seconds(period);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseSeclabel(std::vector<std::string>&& args) {
|
|
|
|
service_->seclabel_ = std::move(args[1]);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseSigstop(std::vector<std::string>&& args) {
|
|
|
|
service_->sigstop_ = true;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseSetenv(std::vector<std::string>&& args) {
|
|
|
|
service_->environment_vars_.emplace_back(std::move(args[1]), std::move(args[2]));
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseShutdown(std::vector<std::string>&& args) {
|
|
|
|
if (args[1] == "critical") {
|
|
|
|
service_->flags_ |= SVC_SHUTDOWN_CRITICAL;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
return Error() << "Invalid shutdown option";
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:58:39 +02:00
|
|
|
Result<void> ServiceParser::ParseTaskProfiles(std::vector<std::string>&& args) {
|
|
|
|
args.erase(args.begin());
|
2022-03-31 23:15:11 +02:00
|
|
|
if (service_->task_profiles_.empty()) {
|
|
|
|
service_->task_profiles_ = std::move(args);
|
|
|
|
} else {
|
|
|
|
// Some task profiles might have been added during writepid conversions
|
|
|
|
service_->task_profiles_.insert(service_->task_profiles_.end(),
|
|
|
|
std::make_move_iterator(args.begin()),
|
|
|
|
std::make_move_iterator(args.end()));
|
|
|
|
args.clear();
|
|
|
|
}
|
2020-04-30 20:58:39 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-06-26 20:22:52 +02:00
|
|
|
Result<void> ServiceParser::ParseTimeoutPeriod(std::vector<std::string>&& args) {
|
|
|
|
int period;
|
|
|
|
if (!ParseInt(args[1], &period, 1)) {
|
|
|
|
return Error() << "timeout_period value must be an integer >= 1";
|
|
|
|
}
|
|
|
|
service_->timeout_period_ = std::chrono::seconds(period);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-07-09 22:33:36 +02:00
|
|
|
// name type perm [ uid gid context ]
|
|
|
|
Result<void> ServiceParser::ParseSocket(std::vector<std::string>&& args) {
|
|
|
|
SocketDescriptor socket;
|
|
|
|
socket.name = std::move(args[1]);
|
|
|
|
|
|
|
|
auto types = Split(args[2], "+");
|
|
|
|
if (types[0] == "stream") {
|
|
|
|
socket.type = SOCK_STREAM;
|
|
|
|
} else if (types[0] == "dgram") {
|
|
|
|
socket.type = SOCK_DGRAM;
|
|
|
|
} else if (types[0] == "seqpacket") {
|
|
|
|
socket.type = SOCK_SEQPACKET;
|
|
|
|
} else {
|
|
|
|
return Error() << "socket type must be 'dgram', 'stream' or 'seqpacket', got '" << types[0]
|
|
|
|
<< "' instead.";
|
|
|
|
}
|
|
|
|
|
init: Add option to listen on sockets before starting service.
Review note: Original change was a p-o-c by agl in
https://r.android.com/2094350 which I think is actually
production quality. I'm just taking it over so that he doesn't
get spammed by any review comments as that's not a good use
of his time.
Needed for the hardware entropy daemon (see bug).
Original commit message:
If one needs to create a service that synchronously starts listening on
a socket then there are currently no good options.
The traditional UNIX solution is to have the service create the socket
and then daemonise. In this situation, init could start the service with
`exec_start` and yet not block forever because the service forks and
exits. However, when the initial child process exits, init kills the
daemon process:
> init: Killed 1 additional processes from a oneshot process group for
> service 'foo'. This is new behavior, previously child processes
> would not be killed in this case.
Next, there is a `socket` option for services and (although the
documentation didn't nail this down), the socket is created
synchronously by `start`. However, init doesn't call `listen` on the
socket so, until the service starts listening on the socket itself,
clients will get ECONNREFUSED.
This this change adds a `+listen` option, similar to `+passcred` which
allows a socket service to reliably handle connections.
Bug: 243933553
Test: Started prng_seeder from init using the new listen flag
Change-Id: I91b3b2b1fd38cc3d96e19e92b76c8e95788191d5
2022-05-12 00:32:47 +02:00
|
|
|
for (size_t i = 1; i < types.size(); i++) {
|
|
|
|
if (types[i] == "passcred") {
|
2019-07-09 22:33:36 +02:00
|
|
|
socket.passcred = true;
|
init: Add option to listen on sockets before starting service.
Review note: Original change was a p-o-c by agl in
https://r.android.com/2094350 which I think is actually
production quality. I'm just taking it over so that he doesn't
get spammed by any review comments as that's not a good use
of his time.
Needed for the hardware entropy daemon (see bug).
Original commit message:
If one needs to create a service that synchronously starts listening on
a socket then there are currently no good options.
The traditional UNIX solution is to have the service create the socket
and then daemonise. In this situation, init could start the service with
`exec_start` and yet not block forever because the service forks and
exits. However, when the initial child process exits, init kills the
daemon process:
> init: Killed 1 additional processes from a oneshot process group for
> service 'foo'. This is new behavior, previously child processes
> would not be killed in this case.
Next, there is a `socket` option for services and (although the
documentation didn't nail this down), the socket is created
synchronously by `start`. However, init doesn't call `listen` on the
socket so, until the service starts listening on the socket itself,
clients will get ECONNREFUSED.
This this change adds a `+listen` option, similar to `+passcred` which
allows a socket service to reliably handle connections.
Bug: 243933553
Test: Started prng_seeder from init using the new listen flag
Change-Id: I91b3b2b1fd38cc3d96e19e92b76c8e95788191d5
2022-05-12 00:32:47 +02:00
|
|
|
} else if (types[i] == "listen") {
|
|
|
|
socket.listen = true;
|
2019-07-09 22:33:36 +02:00
|
|
|
} else {
|
init: Add option to listen on sockets before starting service.
Review note: Original change was a p-o-c by agl in
https://r.android.com/2094350 which I think is actually
production quality. I'm just taking it over so that he doesn't
get spammed by any review comments as that's not a good use
of his time.
Needed for the hardware entropy daemon (see bug).
Original commit message:
If one needs to create a service that synchronously starts listening on
a socket then there are currently no good options.
The traditional UNIX solution is to have the service create the socket
and then daemonise. In this situation, init could start the service with
`exec_start` and yet not block forever because the service forks and
exits. However, when the initial child process exits, init kills the
daemon process:
> init: Killed 1 additional processes from a oneshot process group for
> service 'foo'. This is new behavior, previously child processes
> would not be killed in this case.
Next, there is a `socket` option for services and (although the
documentation didn't nail this down), the socket is created
synchronously by `start`. However, init doesn't call `listen` on the
socket so, until the service starts listening on the socket itself,
clients will get ECONNREFUSED.
This this change adds a `+listen` option, similar to `+passcred` which
allows a socket service to reliably handle connections.
Bug: 243933553
Test: Started prng_seeder from init using the new listen flag
Change-Id: I91b3b2b1fd38cc3d96e19e92b76c8e95788191d5
2022-05-12 00:32:47 +02:00
|
|
|
return Error() << "Unknown socket type decoration '" << types[i]
|
|
|
|
<< "'. Known values are ['passcred', 'listen']";
|
2019-07-09 22:33:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
char* end = nullptr;
|
|
|
|
socket.perm = strtol(args[3].c_str(), &end, 8);
|
|
|
|
if (errno != 0) {
|
|
|
|
return ErrnoError() << "Unable to parse permissions '" << args[3] << "'";
|
|
|
|
}
|
|
|
|
if (end == args[3].c_str() || *end != '\0') {
|
|
|
|
errno = EINVAL;
|
|
|
|
return ErrnoError() << "Unable to parse permissions '" << args[3] << "'";
|
|
|
|
}
|
2019-06-26 20:22:52 +02:00
|
|
|
|
|
|
|
if (args.size() > 4) {
|
2019-07-09 22:33:36 +02:00
|
|
|
auto uid = DecodeUid(args[4]);
|
2020-02-05 19:49:33 +01:00
|
|
|
if (!uid.ok()) {
|
2019-06-26 20:22:52 +02:00
|
|
|
return Error() << "Unable to find UID for '" << args[4] << "': " << uid.error();
|
|
|
|
}
|
2019-07-09 22:33:36 +02:00
|
|
|
socket.uid = *uid;
|
2019-06-26 20:22:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (args.size() > 5) {
|
2019-07-09 22:33:36 +02:00
|
|
|
auto gid = DecodeUid(args[5]);
|
2020-02-05 19:49:33 +01:00
|
|
|
if (!gid.ok()) {
|
2019-06-26 20:22:52 +02:00
|
|
|
return Error() << "Unable to find GID for '" << args[5] << "': " << gid.error();
|
|
|
|
}
|
2019-07-09 22:33:36 +02:00
|
|
|
socket.gid = *gid;
|
2019-06-26 20:22:52 +02:00
|
|
|
}
|
|
|
|
|
2019-07-09 22:33:36 +02:00
|
|
|
socket.context = args.size() > 6 ? args[6] : "";
|
2019-06-26 20:22:52 +02:00
|
|
|
|
2019-07-09 22:33:36 +02:00
|
|
|
auto old = std::find_if(service_->sockets_.begin(), service_->sockets_.end(),
|
|
|
|
[&socket](const auto& other) { return socket.name == other.name; });
|
2019-06-26 20:22:52 +02:00
|
|
|
|
2019-07-09 22:33:36 +02:00
|
|
|
if (old != service_->sockets_.end()) {
|
|
|
|
return Error() << "duplicate socket descriptor '" << socket.name << "'";
|
2019-06-26 20:22:52 +02:00
|
|
|
}
|
|
|
|
|
2019-07-09 22:33:36 +02:00
|
|
|
service_->sockets_.emplace_back(std::move(socket));
|
2019-06-26 20:22:52 +02:00
|
|
|
|
2019-07-09 22:33:36 +02:00
|
|
|
return {};
|
2019-06-26 20:22:52 +02:00
|
|
|
}
|
|
|
|
|
2019-09-24 01:16:54 +02:00
|
|
|
Result<void> ServiceParser::ParseStdioToKmsg(std::vector<std::string>&& args) {
|
|
|
|
if (service_->flags_ & SVC_CONSOLE) {
|
|
|
|
return Error() << "'stdio_to_kmsg' and 'console' are mutually exclusive";
|
|
|
|
}
|
|
|
|
service_->proc_attr_.stdio_to_kmsg = true;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-07-09 22:33:36 +02:00
|
|
|
// name type
|
2019-06-26 20:22:52 +02:00
|
|
|
Result<void> ServiceParser::ParseFile(std::vector<std::string>&& args) {
|
|
|
|
if (args[2] != "r" && args[2] != "w" && args[2] != "rw") {
|
|
|
|
return Error() << "file type must be 'r', 'w' or 'rw'";
|
|
|
|
}
|
2019-07-09 22:33:36 +02:00
|
|
|
|
|
|
|
FileDescriptor file;
|
|
|
|
file.type = args[2];
|
|
|
|
|
2019-07-31 22:59:15 +02:00
|
|
|
auto file_name = ExpandProps(args[1]);
|
2020-02-05 19:49:33 +01:00
|
|
|
if (!file_name.ok()) {
|
2019-07-31 22:59:15 +02:00
|
|
|
return Error() << "Could not expand file path ': " << file_name.error();
|
2019-06-26 20:22:52 +02:00
|
|
|
}
|
2019-07-31 22:59:15 +02:00
|
|
|
file.name = *file_name;
|
2019-07-09 22:33:36 +02:00
|
|
|
if (file.name[0] != '/' || file.name.find("../") != std::string::npos) {
|
2019-06-26 20:22:52 +02:00
|
|
|
return Error() << "file name must not be relative";
|
|
|
|
}
|
2019-07-09 22:33:36 +02:00
|
|
|
|
|
|
|
auto old = std::find_if(service_->files_.begin(), service_->files_.end(),
|
|
|
|
[&file](const auto& other) { return other.name == file.name; });
|
|
|
|
|
|
|
|
if (old != service_->files_.end()) {
|
|
|
|
return Error() << "duplicate file descriptor '" << file.name << "'";
|
|
|
|
}
|
|
|
|
|
|
|
|
service_->files_.emplace_back(std::move(file));
|
|
|
|
|
|
|
|
return {};
|
2019-06-26 20:22:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseUser(std::vector<std::string>&& args) {
|
|
|
|
auto uid = DecodeUid(args[1]);
|
2020-02-05 19:49:33 +01:00
|
|
|
if (!uid.ok()) {
|
2019-06-26 20:22:52 +02:00
|
|
|
return Error() << "Unable to find UID for '" << args[1] << "': " << uid.error();
|
|
|
|
}
|
2023-04-04 01:29:22 +02:00
|
|
|
service_->proc_attr_.parsed_uid = *uid;
|
2019-06-26 20:22:52 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-03-31 23:15:11 +02:00
|
|
|
// Convert legacy paths used to migrate processes between cgroups using writepid command.
|
|
|
|
// We can't get these paths from TaskProfiles because profile definitions are changing
|
|
|
|
// when we migrate to cgroups v2 while these hardcoded paths stay the same.
|
|
|
|
static std::optional<const std::string> ConvertTaskFileToProfile(const std::string& file) {
|
|
|
|
static const std::map<const std::string, const std::string> map = {
|
|
|
|
{"/dev/stune/top-app/tasks", "MaxPerformance"},
|
|
|
|
{"/dev/stune/foreground/tasks", "HighPerformance"},
|
|
|
|
{"/dev/cpuset/camera-daemon/tasks", "CameraServiceCapacity"},
|
|
|
|
{"/dev/cpuset/foreground/tasks", "ProcessCapacityHigh"},
|
|
|
|
{"/dev/cpuset/system-background/tasks", "ServiceCapacityLow"},
|
|
|
|
{"/dev/stune/nnapi-hal/tasks", "NNApiHALPerformance"},
|
|
|
|
{"/dev/blkio/background/tasks", "LowIoPriority"},
|
|
|
|
};
|
|
|
|
auto iter = map.find(file);
|
|
|
|
return iter == map.end() ? std::nullopt : std::make_optional<const std::string>(iter->second);
|
|
|
|
}
|
|
|
|
|
2019-06-26 20:22:52 +02:00
|
|
|
Result<void> ServiceParser::ParseWritepid(std::vector<std::string>&& args) {
|
|
|
|
args.erase(args.begin());
|
2022-03-31 23:15:11 +02:00
|
|
|
// Convert any cgroup writes into appropriate task_profiles
|
|
|
|
for (auto iter = args.begin(); iter != args.end();) {
|
|
|
|
auto task_profile = ConvertTaskFileToProfile(*iter);
|
|
|
|
if (task_profile) {
|
|
|
|
LOG(WARNING) << "'writepid " << *iter << "' is converted into 'task_profiles "
|
|
|
|
<< task_profile.value() << "' for service " << service_->name();
|
|
|
|
service_->task_profiles_.push_back(task_profile.value());
|
|
|
|
iter = args.erase(iter);
|
|
|
|
} else {
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
2019-06-26 20:22:52 +02:00
|
|
|
service_->writepid_files_ = std::move(args);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseUpdatable(std::vector<std::string>&& args) {
|
|
|
|
service_->updatable_ = true;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-07-23 01:05:36 +02:00
|
|
|
const KeywordMap<ServiceParser::OptionParser>& ServiceParser::GetParserMap() const {
|
2019-06-26 20:22:52 +02:00
|
|
|
constexpr std::size_t kMax = std::numeric_limits<std::size_t>::max();
|
|
|
|
// clang-format off
|
2019-07-23 01:05:36 +02:00
|
|
|
static const KeywordMap<ServiceParser::OptionParser> parser_map = {
|
2019-09-10 19:40:47 +02:00
|
|
|
{"capabilities", {0, kMax, &ServiceParser::ParseCapabilities}},
|
|
|
|
{"class", {1, kMax, &ServiceParser::ParseClass}},
|
|
|
|
{"console", {0, 1, &ServiceParser::ParseConsole}},
|
2019-12-26 15:22:28 +01:00
|
|
|
{"critical", {0, 2, &ServiceParser::ParseCritical}},
|
2019-09-10 19:40:47 +02:00
|
|
|
{"disabled", {0, 0, &ServiceParser::ParseDisabled}},
|
|
|
|
{"enter_namespace", {2, 2, &ServiceParser::ParseEnterNamespace}},
|
|
|
|
{"file", {2, 2, &ServiceParser::ParseFile}},
|
2022-12-02 00:44:31 +01:00
|
|
|
{"gentle_kill", {0, 0, &ServiceParser::ParseGentleKill}},
|
2019-09-10 19:40:47 +02:00
|
|
|
{"group", {1, NR_SVC_SUPP_GIDS + 1, &ServiceParser::ParseGroup}},
|
|
|
|
{"interface", {2, 2, &ServiceParser::ParseInterface}},
|
|
|
|
{"ioprio", {2, 2, &ServiceParser::ParseIoprio}},
|
|
|
|
{"keycodes", {1, kMax, &ServiceParser::ParseKeycodes}},
|
|
|
|
{"memcg.limit_in_bytes", {1, 1, &ServiceParser::ParseMemcgLimitInBytes}},
|
|
|
|
{"memcg.limit_percent", {1, 1, &ServiceParser::ParseMemcgLimitPercent}},
|
|
|
|
{"memcg.limit_property", {1, 1, &ServiceParser::ParseMemcgLimitProperty}},
|
2019-06-26 20:22:52 +02:00
|
|
|
{"memcg.soft_limit_in_bytes",
|
2019-09-10 19:40:47 +02:00
|
|
|
{1, 1, &ServiceParser::ParseMemcgSoftLimitInBytes}},
|
|
|
|
{"memcg.swappiness", {1, 1, &ServiceParser::ParseMemcgSwappiness}},
|
|
|
|
{"namespace", {1, 2, &ServiceParser::ParseNamespace}},
|
|
|
|
{"oneshot", {0, 0, &ServiceParser::ParseOneshot}},
|
|
|
|
{"onrestart", {1, kMax, &ServiceParser::ParseOnrestart}},
|
|
|
|
{"oom_score_adjust", {1, 1, &ServiceParser::ParseOomScoreAdjust}},
|
|
|
|
{"override", {0, 0, &ServiceParser::ParseOverride}},
|
|
|
|
{"priority", {1, 1, &ServiceParser::ParsePriority}},
|
|
|
|
{"reboot_on_failure", {1, 1, &ServiceParser::ParseRebootOnFailure}},
|
|
|
|
{"restart_period", {1, 1, &ServiceParser::ParseRestartPeriod}},
|
|
|
|
{"rlimit", {3, 3, &ServiceParser::ParseProcessRlimit}},
|
|
|
|
{"seclabel", {1, 1, &ServiceParser::ParseSeclabel}},
|
|
|
|
{"setenv", {2, 2, &ServiceParser::ParseSetenv}},
|
|
|
|
{"shutdown", {1, 1, &ServiceParser::ParseShutdown}},
|
|
|
|
{"sigstop", {0, 0, &ServiceParser::ParseSigstop}},
|
|
|
|
{"socket", {3, 6, &ServiceParser::ParseSocket}},
|
2019-09-24 01:16:54 +02:00
|
|
|
{"stdio_to_kmsg", {0, 0, &ServiceParser::ParseStdioToKmsg}},
|
2020-04-30 20:58:39 +02:00
|
|
|
{"task_profiles", {1, kMax, &ServiceParser::ParseTaskProfiles}},
|
2019-09-10 19:40:47 +02:00
|
|
|
{"timeout_period", {1, 1, &ServiceParser::ParseTimeoutPeriod}},
|
|
|
|
{"updatable", {0, 0, &ServiceParser::ParseUpdatable}},
|
|
|
|
{"user", {1, 1, &ServiceParser::ParseUser}},
|
|
|
|
{"writepid", {1, kMax, &ServiceParser::ParseWritepid}},
|
2019-06-26 20:22:52 +02:00
|
|
|
};
|
|
|
|
// clang-format on
|
2019-07-23 01:05:36 +02:00
|
|
|
return parser_map;
|
2019-06-26 20:22:52 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 19:46:20 +02:00
|
|
|
Result<void> ServiceParser::ParseSection(std::vector<std::string>&& args,
|
|
|
|
const std::string& filename, int line) {
|
|
|
|
if (args.size() < 3) {
|
|
|
|
return Error() << "services must have a name and a program";
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& name = args[1];
|
|
|
|
if (!IsValidName(name)) {
|
|
|
|
return Error() << "invalid service name '" << name << "'";
|
|
|
|
}
|
|
|
|
|
|
|
|
filename_ = filename;
|
|
|
|
|
|
|
|
Subcontext* restart_action_subcontext = nullptr;
|
2019-09-18 22:47:19 +02:00
|
|
|
if (subcontext_ && subcontext_->PathMatchesSubcontext(filename)) {
|
|
|
|
restart_action_subcontext = subcontext_;
|
2019-06-26 19:46:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> str_args(args.begin() + 2, args.end());
|
|
|
|
|
|
|
|
if (SelinuxGetVendorAndroidVersion() <= __ANDROID_API_P__) {
|
|
|
|
if (str_args[0] == "/sbin/watchdogd") {
|
|
|
|
str_args[0] = "/system/bin/watchdogd";
|
|
|
|
}
|
|
|
|
}
|
2019-10-16 23:22:12 +02:00
|
|
|
if (SelinuxGetVendorAndroidVersion() <= __ANDROID_API_Q__) {
|
|
|
|
if (str_args[0] == "/charger") {
|
|
|
|
str_args[0] = "/system/bin/charger";
|
|
|
|
}
|
|
|
|
}
|
2019-06-26 19:46:20 +02:00
|
|
|
|
2022-07-15 00:51:10 +02:00
|
|
|
service_ = std::make_unique<Service>(name, restart_action_subcontext, filename, str_args);
|
2019-06-26 19:46:20 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::ParseLineSection(std::vector<std::string>&& args, int line) {
|
2019-06-26 20:22:52 +02:00
|
|
|
if (!service_) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-07-23 01:05:36 +02:00
|
|
|
auto parser = GetParserMap().Find(args);
|
2019-06-26 20:22:52 +02:00
|
|
|
|
2020-02-05 19:49:33 +01:00
|
|
|
if (!parser.ok()) return parser.error();
|
2019-06-26 20:22:52 +02:00
|
|
|
|
|
|
|
return std::invoke(*parser, this, std::move(args));
|
2019-06-26 19:46:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> ServiceParser::EndSection() {
|
2019-06-26 20:22:52 +02:00
|
|
|
if (!service_) {
|
|
|
|
return {};
|
|
|
|
}
|
2019-06-26 19:46:20 +02:00
|
|
|
|
2023-04-04 01:29:22 +02:00
|
|
|
if (service_->proc_attr_.parsed_uid == std::nullopt) {
|
2023-04-25 01:54:59 +02:00
|
|
|
if (android::base::GetIntProperty("ro.vendor.api_level", 0) > __ANDROID_API_U__) {
|
|
|
|
return Error() << "No user specified for service '" << service_->name()
|
|
|
|
<< "'. Defaults to root.";
|
|
|
|
} else {
|
|
|
|
LOG(WARNING) << "No user specified for service '" << service_->name()
|
|
|
|
<< "'. Defaults to root.";
|
|
|
|
}
|
2023-04-04 01:29:22 +02:00
|
|
|
}
|
|
|
|
|
2019-07-09 20:00:53 +02:00
|
|
|
if (interface_inheritance_hierarchy_) {
|
2019-08-03 00:13:50 +02:00
|
|
|
if (const auto& check_hierarchy_result = CheckInterfaceInheritanceHierarchy(
|
|
|
|
service_->interfaces(), *interface_inheritance_hierarchy_);
|
2020-02-05 19:49:33 +01:00
|
|
|
!check_hierarchy_result.ok()) {
|
2019-08-03 00:13:50 +02:00
|
|
|
return Error() << check_hierarchy_result.error();
|
2019-07-09 20:00:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:40:39 +02:00
|
|
|
if (SelinuxGetVendorAndroidVersion() >= __ANDROID_API_R__) {
|
|
|
|
if ((service_->flags() & SVC_CRITICAL) != 0 && (service_->flags() & SVC_ONESHOT) != 0) {
|
|
|
|
return Error() << "service '" << service_->name()
|
|
|
|
<< "' can't be both critical and oneshot";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 20:22:52 +02:00
|
|
|
Service* old_service = service_list_->FindService(service_->name());
|
|
|
|
if (old_service) {
|
|
|
|
if (!service_->is_override()) {
|
|
|
|
return Error() << "ignored duplicate definition of service '" << service_->name()
|
|
|
|
<< "'";
|
|
|
|
}
|
2019-06-26 19:46:20 +02:00
|
|
|
|
2019-06-26 20:22:52 +02:00
|
|
|
if (StartsWith(filename_, "/apex/") && !old_service->is_updatable()) {
|
|
|
|
return Error() << "cannot update a non-updatable service '" << service_->name()
|
|
|
|
<< "' with a config in APEX";
|
2019-06-26 19:46:20 +02:00
|
|
|
}
|
|
|
|
|
2020-11-10 02:28:24 +01:00
|
|
|
std::string context = service_->subcontext() ? service_->subcontext()->context() : "";
|
|
|
|
std::string old_context =
|
|
|
|
old_service->subcontext() ? old_service->subcontext()->context() : "";
|
|
|
|
if (context != old_context) {
|
|
|
|
return Error() << "service '" << service_->name() << "' overrides another service "
|
|
|
|
<< "across the treble boundary.";
|
|
|
|
}
|
|
|
|
|
2019-06-26 20:22:52 +02:00
|
|
|
service_list_->RemoveService(*old_service);
|
|
|
|
old_service = nullptr;
|
2019-06-26 19:46:20 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 20:22:52 +02:00
|
|
|
service_list_->AddService(std::move(service_));
|
|
|
|
|
2019-06-26 19:46:20 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ServiceParser::IsValidName(const std::string& name) const {
|
|
|
|
// Property names can be any length, but may only contain certain characters.
|
|
|
|
// Property values can contain any characters, but may only be a certain length.
|
|
|
|
// (The latter restriction is needed because `start` and `stop` work by writing
|
|
|
|
// the service name to the "ctl.start" and "ctl.stop" properties.)
|
|
|
|
return IsLegalPropertyName("init.svc." + name) && name.size() <= PROP_VALUE_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace init
|
|
|
|
} // namespace android
|