2010-04-21 21:04:20 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 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.
|
|
|
|
*/
|
|
|
|
|
2017-04-07 01:30:22 +02:00
|
|
|
#include "ueventd.h"
|
|
|
|
|
2020-12-11 18:26:55 +01:00
|
|
|
#include <android/api-level.h>
|
2010-04-20 23:32:50 +02:00
|
|
|
#include <ctype.h>
|
2019-01-30 11:59:53 +01:00
|
|
|
#include <dirent.h>
|
2015-03-28 07:20:44 +01:00
|
|
|
#include <fcntl.h>
|
2011-03-24 23:45:30 +01:00
|
|
|
#include <signal.h>
|
2015-03-28 07:20:44 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2019-01-30 11:59:53 +01:00
|
|
|
#include <sys/stat.h>
|
2017-05-17 00:35:41 +02:00
|
|
|
#include <sys/wait.h>
|
2019-01-30 11:59:53 +01:00
|
|
|
#include <unistd.h>
|
2017-05-17 00:35:41 +02:00
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <thread>
|
2011-03-24 23:45:30 +01:00
|
|
|
|
2017-07-06 23:20:11 +02:00
|
|
|
#include <android-base/chrono_utils.h>
|
2017-04-07 01:30:22 +02:00
|
|
|
#include <android-base/logging.h>
|
2017-03-29 01:40:41 +02:00
|
|
|
#include <android-base/properties.h>
|
Adds /dev/block/by-name/<partition> symlinks
During uevent processing, some "by-name" symlinks will be created.
/dev/block/<type>/<device>/by-name/<partition>
<type> can be: platform, pci or vbd.
<device> might be: soc.0/f9824900.sdhci, soc.0/f9824900.sdhci, etc.
<partition> might be: system, vendor, system_a, system_b, etc.
e.g., on a non-A/B device:
/dev/block/platform/soc.0/f9824900.sdhci/by-name/system
/dev/block/platform/soc.0/f9824900.sdhci/by-name/vendor
On a A/B device:
/dev/block/platform/soc/1da4000.ufshc/by-name/system_a
/dev/block/platform/soc/1da4000.ufshc/by-name/system_b
/dev/block/platform/soc/1da4000.ufshc/by-name/vendor_a
/dev/block/platform/soc/1da4000.ufshc/by-name/vendor_b
However, those symlinks are "device-specific".
This change adds the "generic" symlinks in ueventd, in addition to
the existing symlinks, when the possible "boot devices" are specified
in device tree. e.g.,
&firmware_android {
compatible = "android,firmware";
boot_devices ="soc/1da4000.ufshc,soc.0/f9824900.sdhci";
}
The following symlinks will then be created on the aforementioned non-A/B
and A/B devices, respectively.
/dev/block/by-name/system
/dev/block/by-name/vendor
/dev/block/by-name/system_a
/dev/block/by-name/system_b
/dev/block/by-name/vendor_a
/dev/block/by-name/vendor_b
Note that both <type> and <device> are skipped in the newly create symlinks.
It assumes there is no more than one devices with the same <partition>,
which is the assumption of current first stage mount flow.
Finally, when 'boot_devices' in DT is absent, it fallbacks to extract
'boot_devices' from fstab settings. e.g., using 'soc/1da4000.ufshc',
'soc.0/f9824900.sdhci' for a fstab with the following content:
/dev/block/platform/soc/1da4000.ufshc/by-name/system
/dev/block/platform/soc.0/f9824900.sdhci/by-name/vendor
Bug: 78613232
Test: adb shell ls /dev/block/by-name
Change-Id: Iec920b5a72409b6a2bdbeeb290f0a3acd2046b5d
2018-05-16 12:33:44 +02:00
|
|
|
#include <fstab/fstab.h>
|
2017-05-17 00:35:41 +02:00
|
|
|
#include <selinux/android.h>
|
2015-03-28 07:20:44 +01:00
|
|
|
#include <selinux/selinux.h>
|
2010-04-21 21:04:20 +02:00
|
|
|
|
|
|
|
#include "devices.h"
|
2017-05-26 00:58:59 +02:00
|
|
|
#include "firmware_handler.h"
|
2018-07-09 20:12:00 +02:00
|
|
|
#include "modalias_handler.h"
|
2019-05-29 00:58:35 +02:00
|
|
|
#include "selabel.h"
|
2017-08-10 21:22:44 +02:00
|
|
|
#include "selinux.h"
|
2018-08-01 22:12:20 +02:00
|
|
|
#include "uevent_handler.h"
|
2017-05-26 00:58:59 +02:00
|
|
|
#include "uevent_listener.h"
|
|
|
|
#include "ueventd_parser.h"
|
2017-04-07 01:30:22 +02:00
|
|
|
#include "util.h"
|
2011-09-28 18:55:31 +02:00
|
|
|
|
2017-05-17 00:35:41 +02:00
|
|
|
// At a high level, ueventd listens for uevent messages generated by the kernel through a netlink
|
|
|
|
// socket. When ueventd receives such a message it handles it by taking appropriate actions,
|
|
|
|
// which can typically be creating a device node in /dev, setting file permissions, setting selinux
|
|
|
|
// labels, etc.
|
|
|
|
// Ueventd also handles loading of firmware that the kernel requests, and creates symlinks for block
|
|
|
|
// and character devices.
|
|
|
|
|
|
|
|
// When ueventd starts, it regenerates uevents for all currently registered devices by traversing
|
|
|
|
// /sys and writing 'add' to each 'uevent' file that it finds. This causes the kernel to generate
|
|
|
|
// and resend uevent messages for all of the currently registered devices. This is done, because
|
|
|
|
// ueventd would not have been running when these devices were registered and therefore was unable
|
|
|
|
// to receive their uevent messages and handle them appropriately. This process is known as
|
|
|
|
// 'cold boot'.
|
|
|
|
|
|
|
|
// 'init' currently waits synchronously on the cold boot process of ueventd before it continues
|
|
|
|
// its boot process. For this reason, cold boot should be as quick as possible. One way to achieve
|
|
|
|
// a speed up here is to parallelize the handling of ueventd messages, which consume the bulk of the
|
|
|
|
// time during cold boot.
|
|
|
|
|
|
|
|
// Handling of uevent messages has two unique properties:
|
|
|
|
// 1) It can be done in isolation; it doesn't need to read or write any status once it is started.
|
|
|
|
// 2) It uses setegid() and setfscreatecon() so either care (aka locking) must be taken to ensure
|
|
|
|
// that no file system operations are done while the uevent process has an abnormal egid or
|
|
|
|
// fscreatecon or this handling must happen in a separate process.
|
|
|
|
// Given the above two properties, it is best to fork() subprocesses to handle the uevents. This
|
|
|
|
// reduces the overhead and complexity that would be required in a solution with threads and locks.
|
|
|
|
// In testing, a racy multithreaded solution has the same performance as the fork() solution, so
|
|
|
|
// there is no reason to deal with the complexity of the former.
|
|
|
|
|
|
|
|
// One other important caveat during the boot process is the handling of SELinux restorecon.
|
|
|
|
// Since many devices have child devices, calling selinux_android_restorecon() recursively for each
|
|
|
|
// device when its uevent is handled, results in multiple restorecon operations being done on a
|
|
|
|
// given file. It is more efficient to simply do restorecon recursively on /sys during cold boot,
|
|
|
|
// than to do restorecon on each device as its uevent is handled. This only applies to cold boot;
|
|
|
|
// once that has completed, restorecon is done for each device as its uevent is handled.
|
|
|
|
|
|
|
|
// With all of the above considered, the cold boot process has the below steps:
|
|
|
|
// 1) ueventd regenerates uevents by doing the /sys traversal and listens to the netlink socket for
|
|
|
|
// the generated uevents. It writes these uevents into a queue represented by a vector.
|
|
|
|
//
|
|
|
|
// 2) ueventd forks 'n' separate uevent handler subprocesses and has each of them to handle the
|
|
|
|
// uevents in the queue based on a starting offset (their process number) and a stride (the total
|
|
|
|
// number of processes). Note that no IPC happens at this point and only const functions from
|
|
|
|
// DeviceHandler should be called from this context.
|
|
|
|
//
|
|
|
|
// 3) In parallel to the subprocesses handling the uevents, the main thread of ueventd calls
|
|
|
|
// selinux_android_restorecon() recursively on /sys/class, /sys/block, and /sys/devices.
|
|
|
|
//
|
|
|
|
// 4) Once the restorecon operation finishes, the main thread calls waitpid() to wait for all
|
|
|
|
// subprocess handlers to complete and exit. Once this happens, it marks coldboot as having
|
|
|
|
// completed.
|
|
|
|
//
|
|
|
|
// At this point, ueventd is single threaded, poll()'s and then handles any future uevents.
|
|
|
|
|
|
|
|
// Lastly, it should be noted that uevents that occur during the coldboot process are handled
|
|
|
|
// without issue after the coldboot process completes. This is because the uevent listener is
|
|
|
|
// paused while the uevent handler and restorecon actions take place. Once coldboot completes,
|
|
|
|
// the uevent listener resumes in polling mode and will handle the uevents that occurred during
|
|
|
|
// coldboot.
|
|
|
|
|
2017-06-22 21:53:17 +02:00
|
|
|
namespace android {
|
|
|
|
namespace init {
|
|
|
|
|
2017-05-17 00:35:41 +02:00
|
|
|
class ColdBoot {
|
|
|
|
public:
|
2018-08-01 22:12:20 +02:00
|
|
|
ColdBoot(UeventListener& uevent_listener,
|
2019-09-06 19:52:31 +02:00
|
|
|
std::vector<std::unique_ptr<UeventHandler>>& uevent_handlers,
|
2021-05-01 08:36:58 +02:00
|
|
|
bool enable_parallel_restorecon,
|
|
|
|
std::vector<std::string> parallel_restorecon_queue)
|
2017-05-17 00:35:41 +02:00
|
|
|
: uevent_listener_(uevent_listener),
|
2018-08-01 22:12:20 +02:00
|
|
|
uevent_handlers_(uevent_handlers),
|
2019-09-06 19:52:31 +02:00
|
|
|
num_handler_subprocesses_(std::thread::hardware_concurrency() ?: 4),
|
2021-05-01 08:36:58 +02:00
|
|
|
enable_parallel_restorecon_(enable_parallel_restorecon),
|
|
|
|
parallel_restorecon_queue_(parallel_restorecon_queue) {}
|
2017-05-17 00:35:41 +02:00
|
|
|
|
|
|
|
void Run();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void UeventHandlerMain(unsigned int process_num, unsigned int total_processes);
|
|
|
|
void RegenerateUevents();
|
|
|
|
void ForkSubProcesses();
|
|
|
|
void WaitForSubProcesses();
|
2019-01-30 11:59:53 +01:00
|
|
|
void RestoreConHandler(unsigned int process_num, unsigned int total_processes);
|
|
|
|
void GenerateRestoreCon(const std::string& directory);
|
2017-05-17 00:35:41 +02:00
|
|
|
|
|
|
|
UeventListener& uevent_listener_;
|
2018-08-01 22:12:20 +02:00
|
|
|
std::vector<std::unique_ptr<UeventHandler>>& uevent_handlers_;
|
2017-05-17 00:35:41 +02:00
|
|
|
|
|
|
|
unsigned int num_handler_subprocesses_;
|
2019-09-06 19:52:31 +02:00
|
|
|
bool enable_parallel_restorecon_;
|
|
|
|
|
2017-05-17 00:35:41 +02:00
|
|
|
std::vector<Uevent> uevent_queue_;
|
|
|
|
|
|
|
|
std::set<pid_t> subprocess_pids_;
|
2019-01-30 11:59:53 +01:00
|
|
|
|
|
|
|
std::vector<std::string> restorecon_queue_;
|
2021-05-01 08:36:58 +02:00
|
|
|
|
|
|
|
std::vector<std::string> parallel_restorecon_queue_;
|
2017-05-17 00:35:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
void ColdBoot::UeventHandlerMain(unsigned int process_num, unsigned int total_processes) {
|
|
|
|
for (unsigned int i = process_num; i < uevent_queue_.size(); i += total_processes) {
|
|
|
|
auto& uevent = uevent_queue_[i];
|
2018-08-01 22:12:20 +02:00
|
|
|
|
|
|
|
for (auto& uevent_handler : uevent_handlers_) {
|
|
|
|
uevent_handler->HandleUevent(uevent);
|
|
|
|
}
|
2017-05-17 00:35:41 +02:00
|
|
|
}
|
2019-01-30 11:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ColdBoot::RestoreConHandler(unsigned int process_num, unsigned int total_processes) {
|
2021-05-01 08:36:58 +02:00
|
|
|
android::base::Timer t_process;
|
|
|
|
|
2019-01-30 11:59:53 +01:00
|
|
|
for (unsigned int i = process_num; i < restorecon_queue_.size(); i += total_processes) {
|
2021-05-01 08:36:58 +02:00
|
|
|
android::base::Timer t;
|
2019-01-30 11:59:53 +01:00
|
|
|
auto& dir = restorecon_queue_[i];
|
|
|
|
|
|
|
|
selinux_android_restorecon(dir.c_str(), SELINUX_ANDROID_RESTORECON_RECURSE);
|
2021-05-01 08:36:58 +02:00
|
|
|
|
|
|
|
//Mark a dir restorecon operation for 50ms,
|
|
|
|
//Maybe you can add this dir to the ueventd.rc script to parallel processing
|
|
|
|
if (t.duration() > 50ms) {
|
|
|
|
LOG(INFO) << "took " << t.duration().count() <<"ms restorecon '"
|
|
|
|
<< dir.c_str() << "' on process '" << process_num <<"'";
|
|
|
|
}
|
2019-01-30 11:59:53 +01:00
|
|
|
}
|
2021-05-01 08:36:58 +02:00
|
|
|
|
|
|
|
//Calculate process restorecon time
|
|
|
|
LOG(VERBOSE) << "took " << t_process.duration().count() << "ms on process '"
|
|
|
|
<< process_num << "'";
|
2017-05-17 00:35:41 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 11:59:53 +01:00
|
|
|
void ColdBoot::GenerateRestoreCon(const std::string& directory) {
|
|
|
|
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(directory.c_str()), &closedir);
|
|
|
|
|
2021-05-01 08:36:58 +02:00
|
|
|
if (!dir) {
|
|
|
|
PLOG(WARNING) << "opendir " << directory.c_str();
|
|
|
|
return;
|
|
|
|
}
|
2019-01-30 11:59:53 +01:00
|
|
|
|
|
|
|
struct dirent* dent;
|
|
|
|
while ((dent = readdir(dir.get())) != NULL) {
|
|
|
|
if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0) continue;
|
|
|
|
|
|
|
|
struct stat st;
|
|
|
|
if (fstatat(dirfd(dir.get()), dent->d_name, &st, 0) == -1) continue;
|
|
|
|
|
|
|
|
if (S_ISDIR(st.st_mode)) {
|
|
|
|
std::string fullpath = directory + "/" + dent->d_name;
|
2021-05-01 08:36:58 +02:00
|
|
|
auto parallel_restorecon =
|
|
|
|
std::find(parallel_restorecon_queue_.begin(),
|
|
|
|
parallel_restorecon_queue_.end(), fullpath);
|
|
|
|
if (parallel_restorecon == parallel_restorecon_queue_.end()) {
|
2019-01-30 11:59:53 +01:00
|
|
|
restorecon_queue_.emplace_back(fullpath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 00:35:41 +02:00
|
|
|
void ColdBoot::RegenerateUevents() {
|
|
|
|
uevent_listener_.RegenerateUevents([this](const Uevent& uevent) {
|
2019-07-10 20:18:24 +02:00
|
|
|
uevent_queue_.emplace_back(uevent);
|
2017-06-21 22:02:57 +02:00
|
|
|
return ListenerAction::kContinue;
|
2017-05-17 00:35:41 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColdBoot::ForkSubProcesses() {
|
|
|
|
for (unsigned int i = 0; i < num_handler_subprocesses_; ++i) {
|
|
|
|
auto pid = fork();
|
|
|
|
if (pid < 0) {
|
|
|
|
PLOG(FATAL) << "fork() failed!";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pid == 0) {
|
|
|
|
UeventHandlerMain(i, num_handler_subprocesses_);
|
2019-09-06 19:52:31 +02:00
|
|
|
if (enable_parallel_restorecon_) {
|
|
|
|
RestoreConHandler(i, num_handler_subprocesses_);
|
|
|
|
}
|
|
|
|
_exit(EXIT_SUCCESS);
|
2017-05-17 00:35:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
subprocess_pids_.emplace(pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColdBoot::WaitForSubProcesses() {
|
|
|
|
// Treat subprocesses that crash or get stuck the same as if ueventd itself has crashed or gets
|
|
|
|
// stuck.
|
|
|
|
//
|
|
|
|
// When a subprocess crashes, we fatally abort from ueventd. init will restart ueventd when
|
|
|
|
// init reaps it, and the cold boot process will start again. If this continues to fail, then
|
2018-10-16 02:21:48 +02:00
|
|
|
// since ueventd is marked as a critical service, init will reboot to bootloader.
|
2017-05-17 00:35:41 +02:00
|
|
|
//
|
|
|
|
// When a subprocess gets stuck, keep ueventd spinning waiting for it. init has a timeout for
|
|
|
|
// cold boot and will reboot to the bootloader if ueventd does not complete in time.
|
|
|
|
while (!subprocess_pids_.empty()) {
|
|
|
|
int status;
|
|
|
|
pid_t pid = TEMP_FAILURE_RETRY(waitpid(-1, &status, 0));
|
|
|
|
if (pid == -1) {
|
|
|
|
PLOG(ERROR) << "waitpid() failed";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto it = std::find(subprocess_pids_.begin(), subprocess_pids_.end(), pid);
|
|
|
|
if (it == subprocess_pids_.end()) continue;
|
|
|
|
|
|
|
|
if (WIFEXITED(status)) {
|
|
|
|
if (WEXITSTATUS(status) == EXIT_SUCCESS) {
|
|
|
|
subprocess_pids_.erase(it);
|
|
|
|
} else {
|
|
|
|
LOG(FATAL) << "subprocess exited with status " << WEXITSTATUS(status);
|
|
|
|
}
|
|
|
|
} else if (WIFSIGNALED(status)) {
|
|
|
|
LOG(FATAL) << "subprocess killed by signal " << WTERMSIG(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColdBoot::Run() {
|
2017-07-06 23:20:11 +02:00
|
|
|
android::base::Timer cold_boot_timer;
|
2017-05-17 00:35:41 +02:00
|
|
|
|
|
|
|
RegenerateUevents();
|
|
|
|
|
2019-09-06 19:52:31 +02:00
|
|
|
if (enable_parallel_restorecon_) {
|
2021-05-01 08:36:58 +02:00
|
|
|
if (parallel_restorecon_queue_.empty()) {
|
|
|
|
parallel_restorecon_queue_.emplace_back("/sys");
|
|
|
|
// takes long time for /sys/devices, parallelize it
|
|
|
|
parallel_restorecon_queue_.emplace_back("/sys/devices");
|
|
|
|
LOG(INFO) << "Parallel processing directory is not set, set the default";
|
|
|
|
}
|
|
|
|
for (const auto& dir : parallel_restorecon_queue_) {
|
|
|
|
selinux_android_restorecon(dir.c_str(), 0);
|
|
|
|
GenerateRestoreCon(dir);
|
|
|
|
}
|
2019-09-06 19:52:31 +02:00
|
|
|
}
|
2017-05-17 00:35:41 +02:00
|
|
|
|
2019-01-30 11:59:53 +01:00
|
|
|
ForkSubProcesses();
|
2017-05-17 00:35:41 +02:00
|
|
|
|
2019-09-06 19:52:31 +02:00
|
|
|
if (!enable_parallel_restorecon_) {
|
|
|
|
selinux_android_restorecon("/sys", SELINUX_ANDROID_RESTORECON_RECURSE);
|
|
|
|
}
|
|
|
|
|
2017-05-17 00:35:41 +02:00
|
|
|
WaitForSubProcesses();
|
|
|
|
|
2019-06-11 02:49:59 +02:00
|
|
|
android::base::SetProperty(kColdBootDoneProp, "true");
|
2017-07-06 23:20:11 +02:00
|
|
|
LOG(INFO) << "Coldboot took " << cold_boot_timer.duration().count() / 1000.0f << " seconds";
|
2017-05-17 00:35:41 +02:00
|
|
|
}
|
|
|
|
|
2020-12-11 18:26:55 +01:00
|
|
|
static UeventdConfiguration GetConfiguration() {
|
2021-06-03 03:21:07 +02:00
|
|
|
auto hardware = android::base::GetProperty("ro.hardware", "");
|
|
|
|
std::vector<std::string> legacy_paths{"/vendor/ueventd.rc", "/odm/ueventd.rc",
|
|
|
|
"/ueventd." + hardware + ".rc"};
|
|
|
|
|
|
|
|
std::vector<std::string> canonical{"/system/etc/ueventd.rc"};
|
|
|
|
|
2020-12-11 18:26:55 +01:00
|
|
|
if (android::base::GetIntProperty("ro.product.first_api_level", 10000) <= __ANDROID_API_S__) {
|
2021-06-03 03:21:07 +02:00
|
|
|
// TODO: Remove these legacy paths once Android S is no longer supported.
|
|
|
|
canonical.insert(canonical.end(), legacy_paths.begin(), legacy_paths.end());
|
|
|
|
} else {
|
|
|
|
// Warn if newer device is using legacy paths.
|
|
|
|
for (const auto& path : legacy_paths) {
|
|
|
|
if (access(path.c_str(), F_OK) == 0) {
|
|
|
|
LOG(FATAL_WITHOUT_ABORT)
|
|
|
|
<< "Legacy ueventd configuration file detected and will not be parsed: "
|
|
|
|
<< path;
|
|
|
|
}
|
|
|
|
}
|
2020-12-11 18:26:55 +01:00
|
|
|
}
|
|
|
|
|
2021-06-03 03:21:07 +02:00
|
|
|
return ParseConfig(canonical);
|
2020-12-11 18:26:55 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 00:35:41 +02:00
|
|
|
int ueventd_main(int argc, char** argv) {
|
2012-03-26 18:09:11 +02:00
|
|
|
/*
|
|
|
|
* init sets the umask to 077 for forked processes. We need to
|
|
|
|
* create files with exact permissions, without modification by
|
|
|
|
* the umask.
|
|
|
|
*/
|
|
|
|
umask(000);
|
|
|
|
|
2018-07-21 00:26:25 +02:00
|
|
|
android::base::InitLogging(argv, &android::base::KernelLogger);
|
2010-04-21 21:04:20 +02:00
|
|
|
|
2016-06-25 00:12:21 +02:00
|
|
|
LOG(INFO) << "ueventd started!";
|
2014-06-24 19:45:43 +02:00
|
|
|
|
2017-08-10 21:22:44 +02:00
|
|
|
SelinuxSetupKernelLogging();
|
|
|
|
SelabelInitialize();
|
2010-04-21 21:04:20 +02:00
|
|
|
|
2018-08-01 22:12:20 +02:00
|
|
|
std::vector<std::unique_ptr<UeventHandler>> uevent_handlers;
|
2018-12-06 22:29:30 +01:00
|
|
|
|
2020-12-11 18:26:55 +01:00
|
|
|
auto ueventd_configuration = GetConfiguration();
|
2018-12-06 22:29:30 +01:00
|
|
|
|
|
|
|
uevent_handlers.emplace_back(std::make_unique<DeviceHandler>(
|
|
|
|
std::move(ueventd_configuration.dev_permissions),
|
|
|
|
std::move(ueventd_configuration.sysfs_permissions),
|
2019-01-30 22:25:35 +01:00
|
|
|
std::move(ueventd_configuration.subsystems), android::fs_mgr::GetBootDevices(), true));
|
2018-12-06 22:29:30 +01:00
|
|
|
uevent_handlers.emplace_back(std::make_unique<FirmwareHandler>(
|
2019-08-08 01:02:28 +02:00
|
|
|
std::move(ueventd_configuration.firmware_directories),
|
|
|
|
std::move(ueventd_configuration.external_firmware_handlers)));
|
2018-12-06 22:29:30 +01:00
|
|
|
|
|
|
|
if (ueventd_configuration.enable_modalias_handling) {
|
2019-04-16 02:43:02 +02:00
|
|
|
std::vector<std::string> base_paths = {"/odm/lib/modules", "/vendor/lib/modules"};
|
|
|
|
uevent_handlers.emplace_back(std::make_unique<ModaliasHandler>(base_paths));
|
2018-07-14 00:32:02 +02:00
|
|
|
}
|
2018-12-06 22:29:30 +01:00
|
|
|
UeventListener uevent_listener(ueventd_configuration.uevent_socket_rcvbuf_size);
|
2018-07-14 00:32:02 +02:00
|
|
|
|
2019-06-11 02:49:59 +02:00
|
|
|
if (!android::base::GetBoolProperty(kColdBootDoneProp, false)) {
|
2019-09-06 19:52:31 +02:00
|
|
|
ColdBoot cold_boot(uevent_listener, uevent_handlers,
|
2021-05-01 08:36:58 +02:00
|
|
|
ueventd_configuration.enable_parallel_restorecon,
|
|
|
|
ueventd_configuration.parallel_restorecon_dirs);
|
2017-05-17 00:35:41 +02:00
|
|
|
cold_boot.Run();
|
2010-04-21 21:04:20 +02:00
|
|
|
}
|
2015-02-04 19:19:50 +01:00
|
|
|
|
2018-08-01 22:12:20 +02:00
|
|
|
for (auto& uevent_handler : uevent_handlers) {
|
|
|
|
uevent_handler->ColdbootDone();
|
|
|
|
}
|
|
|
|
|
2017-06-30 21:58:39 +02:00
|
|
|
// We use waitpid() in ColdBoot, so we can't ignore SIGCHLD until now.
|
|
|
|
signal(SIGCHLD, SIG_IGN);
|
|
|
|
// Reap and pending children that exited between the last call to waitpid() and setting SIG_IGN
|
|
|
|
// for SIGCHLD above.
|
|
|
|
while (waitpid(-1, nullptr, WNOHANG) > 0) {
|
|
|
|
}
|
|
|
|
|
2020-07-07 00:26:49 +02:00
|
|
|
// Restore prio before main loop
|
|
|
|
setpriority(PRIO_PROCESS, 0, 0);
|
2018-08-01 22:12:20 +02:00
|
|
|
uevent_listener.Poll([&uevent_handlers](const Uevent& uevent) {
|
|
|
|
for (auto& uevent_handler : uevent_handlers) {
|
|
|
|
uevent_handler->HandleUevent(uevent);
|
|
|
|
}
|
2017-06-21 22:02:57 +02:00
|
|
|
return ListenerAction::kContinue;
|
2017-05-26 00:58:59 +02:00
|
|
|
});
|
|
|
|
|
2015-02-04 19:19:50 +01:00
|
|
|
return 0;
|
2010-04-21 21:04:20 +02:00
|
|
|
}
|
2017-06-22 21:53:17 +02:00
|
|
|
|
|
|
|
} // namespace init
|
|
|
|
} // namespace android
|