/* * 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. */ #include "ueventd.h" #include #include #include #include #include #include #include #include #include #include #include #include "devices.h" #include "log.h" #include "util.h" int ueventd_main(int argc, char **argv) { /* * 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. */ signal(SIGCHLD, SIG_IGN); InitKernelLogging(argv); LOG(INFO) << "ueventd started!"; selinux_callback cb; cb.func_log = selinux_klog_callback; selinux_set_callback(SELINUX_CB_LOG, cb); Parser& parser = Parser::GetInstance(); parser.AddSectionParser("subsystem", std::make_unique()); using namespace std::placeholders; parser.AddSingleLineParser("/sys/", std::bind(ParsePermissionsLine, _1, _2, true)); parser.AddSingleLineParser("/dev/", std::bind(ParsePermissionsLine, _1, _2, false)); 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"); device_init(); pollfd ufd; ufd.events = POLLIN; ufd.fd = get_device_fd(); while (true) { ufd.revents = 0; int nr = poll(&ufd, 1, -1); if (nr <= 0) { continue; } if (ufd.revents & POLLIN) { handle_device_fd(); } } return 0; }