2010-04-22 03:04:20 +08: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 07:30:22 +08:00
|
|
|
#include "ueventd.h"
|
|
|
|
|
2010-04-21 05:32:50 +08:00
|
|
|
#include <ctype.h>
|
2015-03-28 14:20:44 +08:00
|
|
|
#include <fcntl.h>
|
2011-03-25 06:45:30 +08:00
|
|
|
#include <signal.h>
|
2015-03-28 14:20:44 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2011-03-25 06:45:30 +08:00
|
|
|
|
2017-04-07 07:30:22 +08:00
|
|
|
#include <android-base/logging.h>
|
2017-03-29 07:40:41 +08:00
|
|
|
#include <android-base/properties.h>
|
2015-12-05 14:00:26 +08:00
|
|
|
#include <android-base/stringprintf.h>
|
2015-03-28 14:20:44 +08:00
|
|
|
#include <selinux/selinux.h>
|
2010-04-22 03:04:20 +08:00
|
|
|
|
|
|
|
#include "devices.h"
|
2017-05-26 06:58:59 +08:00
|
|
|
#include "firmware_handler.h"
|
2017-04-07 07:30:22 +08:00
|
|
|
#include "log.h"
|
2017-05-26 06:58:59 +08:00
|
|
|
#include "uevent_listener.h"
|
|
|
|
#include "ueventd_parser.h"
|
2017-04-07 07:30:22 +08:00
|
|
|
#include "util.h"
|
2011-09-29 00:55:31 +08:00
|
|
|
|
2017-05-26 06:58:59 +08:00
|
|
|
DeviceHandler CreateDeviceHandler() {
|
|
|
|
Parser parser;
|
|
|
|
|
|
|
|
std::vector<Subsystem> subsystems;
|
|
|
|
parser.AddSectionParser("subsystem", std::make_unique<SubsystemParser>(&subsystems));
|
|
|
|
|
|
|
|
using namespace std::placeholders;
|
|
|
|
std::vector<SysfsPermissions> sysfs_permissions;
|
|
|
|
std::vector<Permissions> dev_permissions;
|
|
|
|
parser.AddSingleLineParser(
|
|
|
|
"/sys/", std::bind(ParsePermissionsLine, _1, _2, &sysfs_permissions, nullptr));
|
|
|
|
parser.AddSingleLineParser("/dev/",
|
|
|
|
std::bind(ParsePermissionsLine, _1, _2, nullptr, &dev_permissions));
|
|
|
|
|
|
|
|
parser.ParseConfig("/ueventd.rc");
|
|
|
|
parser.ParseConfig("/vendor/ueventd.rc");
|
|
|
|
parser.ParseConfig("/odm/ueventd.rc");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* keep the current product name base configuration so
|
|
|
|
* we remain backwards compatible and allow it to override
|
|
|
|
* everything
|
|
|
|
* TODO: cleanup platform ueventd.rc to remove vendor specific
|
|
|
|
* device node entries (b/34968103)
|
|
|
|
*/
|
|
|
|
std::string hardware = android::base::GetProperty("ro.hardware", "");
|
|
|
|
parser.ParseConfig("/ueventd." + hardware + ".rc");
|
|
|
|
|
|
|
|
return DeviceHandler(std::move(dev_permissions), std::move(sysfs_permissions),
|
|
|
|
std::move(subsystems));
|
|
|
|
}
|
|
|
|
|
2010-04-22 03:04:20 +08:00
|
|
|
int ueventd_main(int argc, char **argv)
|
|
|
|
{
|
2012-03-27 00:09:11 +08: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);
|
|
|
|
|
|
|
|
/* Prevent fire-and-forget children from becoming zombies.
|
|
|
|
* If we should need to wait() for some children in the future
|
|
|
|
* (as opposed to none right now), double-forking here instead
|
|
|
|
* of ignoring SIGCHLD may be the better solution.
|
|
|
|
*/
|
2011-03-25 06:45:30 +08:00
|
|
|
signal(SIGCHLD, SIG_IGN);
|
|
|
|
|
2016-06-25 06:12:21 +08:00
|
|
|
InitKernelLogging(argv);
|
2010-04-22 03:04:20 +08:00
|
|
|
|
2016-06-25 06:12:21 +08:00
|
|
|
LOG(INFO) << "ueventd started!";
|
2014-06-25 01:45:43 +08:00
|
|
|
|
2015-03-28 14:20:44 +08:00
|
|
|
selinux_callback cb;
|
|
|
|
cb.func_log = selinux_klog_callback;
|
|
|
|
selinux_set_callback(SELINUX_CB_LOG, cb);
|
2010-04-22 03:04:20 +08:00
|
|
|
|
2017-05-26 06:58:59 +08:00
|
|
|
DeviceHandler device_handler = CreateDeviceHandler();
|
|
|
|
UeventListener uevent_listener;
|
2017-02-03 23:18:36 +08:00
|
|
|
|
2017-05-26 06:58:59 +08:00
|
|
|
if (access(COLDBOOT_DONE, F_OK) != 0) {
|
|
|
|
Timer t;
|
2010-04-21 05:32:50 +08:00
|
|
|
|
2017-05-26 06:58:59 +08:00
|
|
|
uevent_listener.RegenerateUevents([&device_handler](const Uevent& uevent) {
|
|
|
|
HandleFirmwareEvent(uevent);
|
|
|
|
device_handler.HandleDeviceEvent(uevent);
|
|
|
|
return RegenerationAction::kContinue;
|
|
|
|
});
|
|
|
|
|
|
|
|
close(open(COLDBOOT_DONE, O_WRONLY | O_CREAT | O_CLOEXEC, 0000));
|
|
|
|
LOG(INFO) << "Coldboot took " << t;
|
2010-04-22 03:04:20 +08:00
|
|
|
}
|
2015-02-05 02:19:50 +08:00
|
|
|
|
2017-05-26 06:58:59 +08:00
|
|
|
uevent_listener.DoPolling([&device_handler](const Uevent& uevent) {
|
|
|
|
HandleFirmwareEvent(uevent);
|
|
|
|
device_handler.HandleDeviceEvent(uevent);
|
|
|
|
});
|
|
|
|
|
2015-02-05 02:19:50 +08:00
|
|
|
return 0;
|
2010-04-22 03:04:20 +08:00
|
|
|
}
|