summaryrefslogtreecommitdiffstats
path: root/init/ueventd.cpp
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2017-04-24 16:59:05 -0700
committerTom Cherry <tomcherry@google.com>2017-04-25 11:24:24 -0700
commitfe062055cb11fcb1a6178b046173fc0361ad5b96 (patch)
treeea784f3dd62a9a30b51a84878c636e57cb1ee18c /init/ueventd.cpp
parent35c5bcc89ce713aca02852dc10247a648187ea28 (diff)
downloadcore-fe062055cb11fcb1a6178b046173fc0361ad5b96.tar.gz
core-fe062055cb11fcb1a6178b046173fc0361ad5b96.tar.bz2
core-fe062055cb11fcb1a6178b046173fc0361ad5b96.zip
ueventd: replace ueventd_parser.cpp with init_parser.cpp
Previously init_parser.cpp was made generic and capable of parsing any number of differently named 'sections' or prefixed lines. We now use these capabilities to do the parsing for ueventd. Bug: 36250207 Bug: 33785894 Test: boot bullhead and ensure the right /dev nodes exist with the right permissions set Test: verify no boot time difference Change-Id: I698ca962d414f8135af32f6c9cd778841b2b8b53
Diffstat (limited to 'init/ueventd.cpp')
-rw-r--r--init/ueventd.cpp75
1 files changed, 12 insertions, 63 deletions
diff --git a/init/ueventd.cpp b/init/ueventd.cpp
index b6c6a01b1..963cc4df9 100644
--- a/init/ueventd.cpp
+++ b/init/ueventd.cpp
@@ -18,9 +18,7 @@
#include <ctype.h>
#include <fcntl.h>
-#include <grp.h>
#include <poll.h>
-#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -33,9 +31,11 @@
#include "devices.h"
#include "log.h"
-#include "ueventd_parser.h"
#include "util.h"
+template <bool sysfs>
+static bool ParseSingleLine(std::vector<std::string>&& line, std::string* err);
+
int ueventd_main(int argc, char **argv)
{
/*
@@ -60,9 +60,14 @@ int ueventd_main(int argc, char **argv)
cb.func_log = selinux_klog_callback;
selinux_set_callback(SELINUX_CB_LOG, cb);
- ueventd_parse_config_file("/ueventd.rc");
- ueventd_parse_config_file("/vendor/ueventd.rc");
- ueventd_parse_config_file("/odm/ueventd.rc");
+ Parser& parser = Parser::GetInstance();
+ parser.AddSectionParser("subsystem", std::make_unique<SubsystemParser>());
+ 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
@@ -72,7 +77,7 @@ int ueventd_main(int argc, char **argv)
* device node entries (b/34968103)
*/
std::string hardware = android::base::GetProperty("ro.hardware", "");
- ueventd_parse_config_file(android::base::StringPrintf("/ueventd.%s.rc", hardware.c_str()).c_str());
+ parser.ParseConfig("/ueventd." + hardware + ".rc");
device_init();
@@ -93,59 +98,3 @@ int ueventd_main(int argc, char **argv)
return 0;
}
-
-void set_device_permission(const char* fn, int line, int nargs, char **args)
-{
- char *name;
- char *attr = 0;
- mode_t perm;
- uid_t uid;
- gid_t gid;
- char *endptr;
-
- if (nargs == 0)
- return;
-
- if (args[0][0] == '#')
- return;
-
- name = args[0];
-
- if (!strncmp(name,"/sys/", 5) && (nargs == 5)) {
- LOG(INFO) << "/sys/ rule " << args[0] << " " << args[1];
- attr = args[1];
- args++;
- nargs--;
- }
-
- if (nargs != 4) {
- LOG(ERROR) << "invalid line (" << fn << ":" << line << ") line for '" << args[0] << "'";
- return;
- }
-
- perm = strtol(args[1], &endptr, 8);
- if (!endptr || *endptr != '\0') {
- LOG(ERROR) << "invalid mode (" << fn << ":" << line << ") '" << args[1] << "'";
- return;
- }
-
- struct passwd* pwd = getpwnam(args[2]);
- if (!pwd) {
- LOG(ERROR) << "invalid uid (" << fn << ":" << line << ") '" << args[2] << "'";
- return;
- }
- uid = pwd->pw_uid;
-
- struct group* grp = getgrnam(args[3]);
- if (!grp) {
- LOG(ERROR) << "invalid gid (" << fn << ":" << line << ") '" << args[3] << "'";
- return;
- }
- gid = grp->gr_gid;
-
- if (attr) {
- sysfs_permissions.emplace_back(name, attr, perm, uid, gid);
- } else {
- dev_permissions.emplace_back(name, perm, uid, gid);
- }
-}