2015-07-31 21:45:25 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 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.
|
|
|
|
*/
|
|
|
|
|
2019-06-26 20:22:52 +02:00
|
|
|
#pragma once
|
2015-07-31 21:45:25 +02:00
|
|
|
|
2018-04-13 19:38:57 +02:00
|
|
|
#include <signal.h>
|
2015-07-31 21:45:25 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
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
|
|
|
#include <algorithm>
|
2018-09-28 01:10:46 +02:00
|
|
|
#include <chrono>
|
2015-07-31 21:45:25 +02:00
|
|
|
#include <memory>
|
2018-09-28 01:10:46 +02:00
|
|
|
#include <optional>
|
2017-03-27 19:59:11 +02:00
|
|
|
#include <set>
|
2015-07-31 21:45:25 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-03-24 19:43:02 +01:00
|
|
|
#include <android-base/chrono_utils.h>
|
2017-04-07 01:30:22 +02:00
|
|
|
#include <cutils/iosched_policy.h>
|
2017-03-24 19:43:02 +01:00
|
|
|
|
2015-07-31 21:45:25 +02:00
|
|
|
#include "action.h"
|
init: Add support for ambient capabilities.
Ambient capabilities are inherited in a straightforward way across
execve(2):
"
If you are nonroot but you have a capability, you can add it to pA.
If you do so, your children get that capability in pA, pP, and pE.
For example, you can set pA = CAP_NET_BIND_SERVICE, and your
children can automatically bind low-numbered ports.
"
This will allow us to get rid of the special meaning for AID_NET_ADMIN
and AID_NET_RAW, and if desired, to reduce the use of file capabilities
(which grant capabilities to any process that can execute the file). An
additional benefit of the latter is that a single .rc file can specify
all properties for a service, without having to rely on a separate file
for file capabilities.
Ambient capabilities are supported starting with kernel 4.3 and have
been backported to all Android common kernels back to 3.10.
I chose to not use Minijail here (though I'm still using libcap) for
two reasons:
1-The Minijail code is designed to work in situations where the process
is holding any set of capabilities, so it's more complex. The situation
when forking from init allows for simpler code.
2-The way Minijail is structured right now, we would not be able to
make the required SELinux calls between UID/GID dropping and other priv
dropping code. In the future, it will make sense to add some sort of
"hook" to Minijail so that it can be used in situations where we want
to do other operations between some of the privilege-dropping
operations carried out by Minijail.
Bug: 32438163
Test: Use sample service.
Change-Id: I3226cc95769d1beacbae619cb6c6e6a5425890fb
2016-10-27 16:33:03 +02:00
|
|
|
#include "capabilities.h"
|
2022-10-20 01:30:15 +02:00
|
|
|
#include "interprocess_fifo.h"
|
2015-08-26 20:43:36 +02:00
|
|
|
#include "keyword_map.h"
|
2022-07-14 04:23:59 +02:00
|
|
|
#include "mount_namespace.h"
|
2017-07-27 21:54:48 +02:00
|
|
|
#include "parser.h"
|
2019-05-30 00:58:32 +02:00
|
|
|
#include "service_utils.h"
|
2017-09-13 00:58:47 +02:00
|
|
|
#include "subcontext.h"
|
2015-07-31 21:45:25 +02:00
|
|
|
|
2017-03-13 19:54:47 +01:00
|
|
|
#define SVC_DISABLED 0x001 // do not autostart with class
|
|
|
|
#define SVC_ONESHOT 0x002 // do not restart on exit
|
|
|
|
#define SVC_RUNNING 0x004 // currently active
|
|
|
|
#define SVC_RESTARTING 0x008 // waiting to restart
|
|
|
|
#define SVC_CONSOLE 0x010 // requires console
|
2018-10-16 02:21:48 +02:00
|
|
|
#define SVC_CRITICAL 0x020 // will reboot into bootloader if keeps crashing
|
2017-03-13 19:54:47 +01:00
|
|
|
#define SVC_RESET 0x040 // Use when stopping a process,
|
2015-07-31 21:45:25 +02:00
|
|
|
// but not disabling so it can be restarted with its class.
|
2017-03-13 19:54:47 +01:00
|
|
|
#define SVC_RC_DISABLED 0x080 // Remember if the disabled flag was set in the rc script.
|
|
|
|
#define SVC_RESTART 0x100 // Use to safely restart (stop, wait, start) a service.
|
2015-07-31 21:45:25 +02:00
|
|
|
#define SVC_DISABLED_START 0x200 // A start was requested but it was disabled at the time.
|
2017-03-28 01:27:30 +02:00
|
|
|
#define SVC_EXEC 0x400 // This service was started by either 'exec' or 'exec_start' and stops
|
|
|
|
// init from processing more commands until it completes
|
2017-03-13 19:54:47 +01:00
|
|
|
|
|
|
|
#define SVC_SHUTDOWN_CRITICAL 0x800 // This service is critical for shutdown and
|
|
|
|
// should not be killed during shutdown
|
2017-03-28 01:27:30 +02:00
|
|
|
#define SVC_TEMPORARY 0x1000 // This service was started by 'exec' and should be removed from the
|
|
|
|
// service list once it is reaped.
|
2022-12-02 00:44:31 +01:00
|
|
|
#define SVC_GENTLE_KILL 0x2000 // This service should be stopped with SIGTERM instead of SIGKILL
|
|
|
|
// Will still be SIGKILLed after timeout period of 200 ms
|
2015-07-31 21:45:25 +02:00
|
|
|
|
2023-08-25 06:22:06 +02:00
|
|
|
#define NR_SVC_SUPP_GIDS 32 // thirty two supplementary groups
|
2015-07-31 21:45:25 +02:00
|
|
|
|
2017-06-22 21:53:17 +02:00
|
|
|
namespace android {
|
|
|
|
namespace init {
|
2015-07-31 21:45:25 +02:00
|
|
|
|
|
|
|
class Service {
|
2019-06-26 20:22:52 +02:00
|
|
|
friend class ServiceParser;
|
|
|
|
|
2017-03-27 19:59:11 +02:00
|
|
|
public:
|
2017-09-13 00:58:47 +02:00
|
|
|
Service(const std::string& name, Subcontext* subcontext_for_restart_commands,
|
2022-07-15 00:51:10 +02:00
|
|
|
const std::string& filename, const std::vector<std::string>& args);
|
2015-07-31 21:45:25 +02:00
|
|
|
|
2023-04-04 01:29:22 +02:00
|
|
|
Service(const std::string& name, unsigned flags, std::optional<uid_t> uid, gid_t gid,
|
2019-07-09 00:09:36 +02:00
|
|
|
const std::vector<gid_t>& supp_gids, int namespace_flags, const std::string& seclabel,
|
2022-07-15 00:51:10 +02:00
|
|
|
Subcontext* subcontext_for_restart_commands, const std::string& filename,
|
|
|
|
const std::vector<std::string>& args);
|
2022-12-05 19:43:00 +01:00
|
|
|
Service(const Service&) = delete;
|
|
|
|
void operator=(const Service&) = delete;
|
2015-07-31 21:45:25 +02:00
|
|
|
|
2019-07-30 18:34:41 +02:00
|
|
|
static Result<std::unique_ptr<Service>> MakeTemporaryOneshotService(
|
|
|
|
const std::vector<std::string>& args);
|
2017-07-28 23:48:41 +02:00
|
|
|
|
2017-03-13 19:54:47 +01:00
|
|
|
bool IsRunning() { return (flags_ & SVC_RUNNING) != 0; }
|
2019-10-09 16:23:02 +02:00
|
|
|
bool IsEnabled() { return (flags_ & SVC_DISABLED) == 0; }
|
2020-03-10 19:47:24 +01:00
|
|
|
Result<void> ExecStart();
|
|
|
|
Result<void> Start();
|
|
|
|
Result<void> StartIfNotDisabled();
|
|
|
|
Result<void> Enable();
|
2015-07-31 21:45:25 +02:00
|
|
|
void Reset();
|
|
|
|
void Stop();
|
2015-12-18 20:39:59 +01:00
|
|
|
void Terminate();
|
2018-09-28 01:10:46 +02:00
|
|
|
void Timeout();
|
2020-03-10 19:47:24 +01:00
|
|
|
void Restart();
|
2018-04-13 19:38:57 +02:00
|
|
|
void Reap(const siginfo_t& siginfo);
|
2015-07-31 21:45:25 +02:00
|
|
|
void DumpState() const;
|
2017-03-13 19:54:47 +01:00
|
|
|
void SetShutdownCritical() { flags_ |= SVC_SHUTDOWN_CRITICAL; }
|
2017-03-27 19:59:11 +02:00
|
|
|
bool IsShutdownCritical() const { return (flags_ & SVC_SHUTDOWN_CRITICAL) != 0; }
|
2017-07-28 23:48:41 +02:00
|
|
|
void UnSetExec() {
|
|
|
|
is_exec_service_running_ = false;
|
|
|
|
flags_ &= ~SVC_EXEC;
|
|
|
|
}
|
2018-04-13 19:38:57 +02:00
|
|
|
void AddReapCallback(std::function<void(const siginfo_t& siginfo)> callback) {
|
|
|
|
reap_callbacks_.emplace_back(std::move(callback));
|
|
|
|
}
|
2021-07-22 06:53:28 +02:00
|
|
|
void SetStartedInFirstStage(pid_t pid);
|
|
|
|
bool MarkSocketPersistent(const std::string& socket_name);
|
2019-08-06 00:03:58 +02:00
|
|
|
size_t CheckAllCommands() const { return onrestart_.CheckAllCommands(); }
|
2017-07-28 23:48:41 +02:00
|
|
|
|
|
|
|
static bool is_exec_service_running() { return is_exec_service_running_; }
|
2015-07-31 21:45:25 +02:00
|
|
|
|
|
|
|
const std::string& name() const { return name_; }
|
2017-03-27 19:59:11 +02:00
|
|
|
const std::set<std::string>& classnames() const { return classnames_; }
|
2015-07-31 21:45:25 +02:00
|
|
|
unsigned flags() const { return flags_; }
|
|
|
|
pid_t pid() const { return pid_; }
|
2017-07-31 22:23:18 +02:00
|
|
|
android::base::boot_clock::time_point time_started() const { return time_started_; }
|
2017-05-01 23:16:41 +02:00
|
|
|
int crash_count() const { return crash_count_; }
|
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
|
|
|
int was_last_exit_ok() const { return was_last_exit_ok_; }
|
2023-04-04 01:29:22 +02:00
|
|
|
uid_t uid() const { return proc_attr_.uid(); }
|
2019-05-30 00:58:32 +02:00
|
|
|
gid_t gid() const { return proc_attr_.gid; }
|
2019-07-09 00:09:36 +02:00
|
|
|
int namespace_flags() const { return namespaces_.flags; }
|
2019-05-30 00:58:32 +02:00
|
|
|
const std::vector<gid_t>& supp_gids() const { return proc_attr_.supp_gids; }
|
2015-07-31 21:45:25 +02:00
|
|
|
const std::string& seclabel() const { return seclabel_; }
|
|
|
|
const std::vector<int>& keycodes() const { return keycodes_; }
|
2019-05-30 00:58:32 +02:00
|
|
|
IoSchedClass ioprio_class() const { return proc_attr_.ioprio_class; }
|
|
|
|
int ioprio_pri() const { return proc_attr_.ioprio_pri; }
|
2017-10-06 03:50:22 +02:00
|
|
|
const std::set<std::string>& interfaces() const { return interfaces_; }
|
2019-05-30 00:58:32 +02:00
|
|
|
int priority() const { return proc_attr_.priority; }
|
2017-05-01 23:16:41 +02:00
|
|
|
int oom_score_adjust() const { return oom_score_adjust_; }
|
2017-11-14 00:31:54 +01:00
|
|
|
bool is_override() const { return override_; }
|
2017-05-04 20:32:36 +02:00
|
|
|
bool process_cgroup_empty() const { return process_cgroup_empty_; }
|
2017-07-27 01:09:09 +02:00
|
|
|
unsigned long start_order() const { return start_order_; }
|
2018-04-17 23:48:44 +02:00
|
|
|
void set_sigstop(bool value) { sigstop_ = value; }
|
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
|
|
|
std::chrono::seconds restart_period() const {
|
|
|
|
// If the service exited abnormally or due to timeout, late limit the restart even if
|
|
|
|
// restart_period is set to a very short value.
|
|
|
|
// If not, i.e. restart after a deliberate and successful exit, respect the period.
|
|
|
|
if (!was_last_exit_ok_) {
|
|
|
|
return std::max(restart_period_, default_restart_period_);
|
|
|
|
}
|
|
|
|
return restart_period_;
|
|
|
|
}
|
2018-09-28 01:10:46 +02:00
|
|
|
std::optional<std::chrono::seconds> timeout_period() const { return timeout_period_; }
|
2015-07-31 21:45:25 +02:00
|
|
|
const std::vector<std::string>& args() const { return args_; }
|
2018-11-12 04:08:41 +01:00
|
|
|
bool is_updatable() const { return updatable_; }
|
Support for stopping/starting post-data-mount class subsets.
On devices that use FDE and APEX at the same time, we need to bring up a
minimal framework to be able to mount the /data partition. During this
period, a tmpfs /data filesystem is created, which doesn't contain any
of the updated APEXEs. As a consequence, all those processes will be
using the APEXes from the /system partition.
This is obviously not desired, as APEXes in /system may be old and/or
contain security issues. Additionally, it would create a difference
between FBE and FDE devices at runtime.
Ideally, we restart all processes that have started after we created the
tmpfs /data. We can't (re)start based on class names alone, because some
classes (eg 'hal') contain services that are required to start apexd
itself and that shouldn't be killed (eg the graphics HAL).
To address this, keep track of which processes are started after /data
is mounted, with a new 'mark_post_data' keyword. Additionally, create
'class_reset_post_data', which resets all services in the class that
were created after the initial /data mount, and 'class_start_post_data',
which starts all services in the class that were started after /data was
mounted.
On a device with FBE, these keywords wouldn't be used; on a device with
FDE, we'd use them to bring down the right processes after the user has
entered the correct secret, and restart them.
Bug: 118485723
Test: manually verified process list
Change-Id: I16adb776dacf1dd1feeaff9e60639b99899905eb
2019-04-23 16:26:01 +02:00
|
|
|
bool is_post_data() const { return post_data_; }
|
2022-07-15 00:51:10 +02:00
|
|
|
bool is_from_apex() const { return base::StartsWith(filename_, "/apex/"); }
|
2020-03-04 19:52:08 +01:00
|
|
|
void set_oneshot(bool value) {
|
|
|
|
if (value) {
|
|
|
|
flags_ |= SVC_ONESHOT;
|
|
|
|
} else {
|
|
|
|
flags_ &= ~SVC_ONESHOT;
|
|
|
|
}
|
|
|
|
}
|
2022-11-14 20:24:12 +01:00
|
|
|
const Subcontext* subcontext() const { return subcontext_; }
|
2022-07-16 00:02:14 +02:00
|
|
|
const std::string& filename() const { return filename_; }
|
|
|
|
void set_filename(const std::string& name) { filename_ = name; }
|
2023-11-16 21:42:35 +01:00
|
|
|
static int GetSigchldFd() {
|
|
|
|
static int sigchld_fd = CreateSigchldFd().release();
|
|
|
|
return sigchld_fd;
|
|
|
|
}
|
2015-07-31 21:45:25 +02:00
|
|
|
|
2017-03-27 19:59:11 +02:00
|
|
|
private:
|
2015-07-31 21:45:25 +02:00
|
|
|
void NotifyStateChange(const std::string& new_state) const;
|
|
|
|
void StopOrReset(int how);
|
2023-10-26 22:46:21 +02:00
|
|
|
void KillProcessGroup(int signal);
|
2022-11-15 01:45:47 +01:00
|
|
|
void SetProcessAttributesAndCaps(InterprocessFifo setsid_finished);
|
2021-07-22 06:53:28 +02:00
|
|
|
void ResetFlagsForStart();
|
2022-02-26 00:28:59 +01:00
|
|
|
Result<void> CheckConsole();
|
2022-02-25 23:44:40 +01:00
|
|
|
void ConfigureMemcg();
|
2022-11-15 01:45:47 +01:00
|
|
|
void RunService(const std::vector<Descriptor>& descriptors, InterprocessFifo cgroups_activated,
|
|
|
|
InterprocessFifo setsid_finished);
|
2022-07-14 04:23:59 +02:00
|
|
|
void SetMountNamespace();
|
2023-11-16 21:42:35 +01:00
|
|
|
static ::android::base::unique_fd CreateSigchldFd();
|
2023-11-03 18:33:17 +01:00
|
|
|
|
2017-07-27 01:09:09 +02:00
|
|
|
static unsigned long next_start_order_;
|
2017-07-28 23:48:41 +02:00
|
|
|
static bool is_exec_service_running_;
|
2017-07-27 01:09:09 +02:00
|
|
|
|
2022-11-14 20:24:12 +01:00
|
|
|
const std::string name_;
|
2017-03-27 19:59:11 +02:00
|
|
|
std::set<std::string> classnames_;
|
2015-07-31 21:45:25 +02:00
|
|
|
|
|
|
|
unsigned flags_;
|
|
|
|
pid_t pid_;
|
2017-03-24 19:43:02 +01:00
|
|
|
android::base::boot_clock::time_point time_started_; // time of last start
|
|
|
|
android::base::boot_clock::time_point time_crashed_; // first crash within inspection window
|
2016-11-11 02:43:47 +01:00
|
|
|
int crash_count_; // number of times crashed within window
|
2022-05-11 02:55:08 +02:00
|
|
|
bool upgraded_mte_ = false; // whether we upgraded async MTE -> sync MTE before
|
2019-12-26 15:22:28 +01:00
|
|
|
std::chrono::minutes fatal_crash_window_ = 4min; // fatal() when more than 4 crashes in it
|
|
|
|
std::optional<std::string> fatal_reboot_target_; // reboot target of fatal handler
|
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
|
|
|
bool was_last_exit_ok_ =
|
|
|
|
true; // true if the service never exited, or exited with status code 0
|
2015-07-31 21:45:25 +02:00
|
|
|
|
2019-02-06 19:45:56 +01:00
|
|
|
std::optional<CapSet> capabilities_;
|
2019-05-30 00:58:32 +02:00
|
|
|
ProcessAttributes proc_attr_;
|
|
|
|
NamespaceInfo namespaces_;
|
2015-07-31 21:45:25 +02:00
|
|
|
|
|
|
|
std::string seclabel_;
|
|
|
|
|
2019-07-09 22:33:36 +02:00
|
|
|
std::vector<SocketDescriptor> sockets_;
|
|
|
|
std::vector<FileDescriptor> files_;
|
2017-08-23 00:41:03 +02:00
|
|
|
std::vector<std::pair<std::string, std::string>> environment_vars_;
|
2022-05-11 02:55:08 +02:00
|
|
|
// Environment variables that only get applied to the next run.
|
|
|
|
std::vector<std::pair<std::string, std::string>> once_environment_vars_;
|
2015-07-31 21:45:25 +02:00
|
|
|
|
2022-11-14 20:24:12 +01:00
|
|
|
const Subcontext* const subcontext_;
|
2015-07-31 21:45:25 +02:00
|
|
|
Action onrestart_; // Commands to execute on restart.
|
|
|
|
|
|
|
|
std::vector<std::string> writepid_files_;
|
|
|
|
|
2020-04-30 20:58:39 +02:00
|
|
|
std::vector<std::string> task_profiles_;
|
|
|
|
|
2017-10-06 03:50:22 +02:00
|
|
|
std::set<std::string> interfaces_; // e.g. some.package.foo@1.0::IBaz/instance-name
|
|
|
|
|
2018-05-19 00:25:15 +02:00
|
|
|
// keycodes for triggering this service via /dev/input/input*
|
2015-07-31 21:45:25 +02:00
|
|
|
std::vector<int> keycodes_;
|
|
|
|
|
2016-07-22 21:07:06 +02:00
|
|
|
int oom_score_adjust_;
|
|
|
|
|
2018-10-30 23:49:33 +01:00
|
|
|
int swappiness_ = -1;
|
|
|
|
int soft_limit_in_bytes_ = -1;
|
|
|
|
|
|
|
|
int limit_in_bytes_ = -1;
|
|
|
|
int limit_percent_ = -1;
|
|
|
|
std::string limit_property_;
|
2017-07-17 04:38:11 +02:00
|
|
|
|
2017-05-04 20:32:36 +02:00
|
|
|
bool process_cgroup_empty_ = false;
|
|
|
|
|
2017-11-14 00:31:54 +01:00
|
|
|
bool override_ = false;
|
|
|
|
|
2017-07-27 01:09:09 +02:00
|
|
|
unsigned long start_order_;
|
|
|
|
|
2018-04-17 23:48:44 +02:00
|
|
|
bool sigstop_ = false;
|
|
|
|
|
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
|
|
|
const std::chrono::seconds default_restart_period_ = 5s;
|
|
|
|
std::chrono::seconds restart_period_ = default_restart_period_;
|
2018-09-28 01:10:46 +02:00
|
|
|
std::optional<std::chrono::seconds> timeout_period_;
|
|
|
|
|
2018-11-12 04:08:41 +01:00
|
|
|
bool updatable_ = false;
|
|
|
|
|
2022-11-14 20:24:12 +01:00
|
|
|
const std::vector<std::string> args_;
|
2018-04-13 19:38:57 +02:00
|
|
|
|
|
|
|
std::vector<std::function<void(const siginfo_t& siginfo)>> reap_callbacks_;
|
Proper mount namespace configuration for bionic
This CL fixes the design problem of the previous mechanism for providing
the bootstrap bionic and the runtime bionic to the same path.
Previously, bootstrap bionic was self-bind-mounted; i.e.
/system/bin/libc.so is bind-mounted to itself. And the runtime bionic
was bind-mounted on top of the bootstrap bionic. This has not only caused
problems like `adb sync` not working(b/122737045), but also is quite
difficult to understand due to the double-and-self mounting.
This is the new design:
Most importantly, these four are all distinct:
1) bootstrap bionic (/system/lib/bootstrap/libc.so)
2) runtime bionic (/apex/com.android.runtime/lib/bionic/libc.so)
3) mount point for 1) and 2) (/bionic/lib/libc.so)
4) symlink for 3) (/system/lib/libc.so -> /bionic/lib/libc.so)
Inside the mount namespace of the pre-apexd processes, 1) is
bind-mounted to 3). Likewise, inside the mount namespace of the
post-apexd processes, 2) is bind-mounted to 3). In other words, there is
no self-mount, and no double-mount.
Another change is that mount points are under /bionic and the legacy
paths become symlinks to the mount points. This is to make sure that
there is no bind mounts under /system, which is breaking some apps.
Finally, code for creating mount namespaces, mounting bionic, etc are
refactored to mount_namespace.cpp
Bug: 120266448
Bug: 123275379
Test: m, device boots, adb sync/push/pull works,
especially with following paths:
/bionic/lib64/libc.so
/bionic/bin/linker64
/system/lib64/bootstrap/libc.so
/system/bin/bootstrap/linker64
Change-Id: Icdfbdcc1efca540ac854d4df79e07ee61fca559f
2019-01-16 15:00:59 +01:00
|
|
|
|
2022-07-14 04:23:59 +02:00
|
|
|
std::optional<MountNamespace> mount_namespace_;
|
Support for stopping/starting post-data-mount class subsets.
On devices that use FDE and APEX at the same time, we need to bring up a
minimal framework to be able to mount the /data partition. During this
period, a tmpfs /data filesystem is created, which doesn't contain any
of the updated APEXEs. As a consequence, all those processes will be
using the APEXes from the /system partition.
This is obviously not desired, as APEXes in /system may be old and/or
contain security issues. Additionally, it would create a difference
between FBE and FDE devices at runtime.
Ideally, we restart all processes that have started after we created the
tmpfs /data. We can't (re)start based on class names alone, because some
classes (eg 'hal') contain services that are required to start apexd
itself and that shouldn't be killed (eg the graphics HAL).
To address this, keep track of which processes are started after /data
is mounted, with a new 'mark_post_data' keyword. Additionally, create
'class_reset_post_data', which resets all services in the class that
were created after the initial /data mount, and 'class_start_post_data',
which starts all services in the class that were started after /data was
mounted.
On a device with FBE, these keywords wouldn't be used; on a device with
FDE, we'd use them to bring down the right processes after the user has
entered the correct secret, and restart them.
Bug: 118485723
Test: manually verified process list
Change-Id: I16adb776dacf1dd1feeaff9e60639b99899905eb
2019-04-23 16:26:01 +02:00
|
|
|
|
|
|
|
bool post_data_ = false;
|
2019-05-15 22:04:13 +02:00
|
|
|
|
2019-09-10 19:40:47 +02:00
|
|
|
std::optional<std::string> on_failure_reboot_target_;
|
2019-12-05 13:35:19 +01:00
|
|
|
|
2022-07-15 00:51:10 +02:00
|
|
|
std::string filename_;
|
2015-07-31 21:45:25 +02:00
|
|
|
};
|
|
|
|
|
2017-06-22 21:53:17 +02:00
|
|
|
} // namespace init
|
|
|
|
} // namespace android
|