summaryrefslogtreecommitdiff
path: root/init/init_parser.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-02-06 12:19:48 -0800
committerElliott Hughes <enh@google.com>2015-02-06 14:20:30 -0800
commitf682b4786a4093efb23bf80d69bf80eb274b145b (patch)
tree8af209a035867fd30720e6e6da1b8b581aab871d /init/init_parser.cpp
parentd558530ba90cb6218fe8e255c71a034c3fe1ea58 (diff)
Clean up reading and writing in init.
This isn't particularly useful in and of itself, but it does introduce the first (trivial) unit test, improves the documentation (including details about how to debug init crashes), and made me aware of how unpleasant the existing parser is. I also fixed a bug in passing --- unless you thought the "peboot" and "pm" commands were features... Bug: 19217569 Change-Id: I6ab76129a543ce3ed3dab52ef2c638009874c3de
Diffstat (limited to 'init/init_parser.cpp')
-rw-r--r--init/init_parser.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/init/init_parser.cpp b/init/init_parser.cpp
index facb0cf22..65fc1a684 100644
--- a/init/init_parser.cpp
+++ b/init/init_parser.cpp
@@ -116,7 +116,7 @@ static int lookup_keyword(const char *s)
{
switch (*s++) {
case 'c':
- if (!strcmp(s, "opy")) return K_copy;
+ if (!strcmp(s, "opy")) return K_copy;
if (!strcmp(s, "apability")) return K_capability;
if (!strcmp(s, "hdir")) return K_chdir;
if (!strcmp(s, "hroot")) return K_chroot;
@@ -171,6 +171,7 @@ static int lookup_keyword(const char *s)
break;
case 'p':
if (!strcmp(s, "owerctl")) return K_powerctl;
+ break;
case 'r':
if (!strcmp(s, "estart")) return K_restart;
if (!strcmp(s, "estorecon")) return K_restorecon;
@@ -209,8 +210,7 @@ static int lookup_keyword(const char *s)
return K_UNKNOWN;
}
-static void parse_line_no_op(struct parse_state *state, int nargs, char **args)
-{
+static void parse_line_no_op(struct parse_state*, int, char**) {
}
static int push_chars(char **dst, int *len, const char *chars, int cnt)
@@ -378,7 +378,7 @@ static void parse_new_section(struct parse_state *state, int kw,
state->parse_line = parse_line_no_op;
}
-static void parse_config(const char *fn, char *s)
+static void parse_config(const char *fn, const std::string& data)
{
struct parse_state state;
struct listnode import_list;
@@ -389,7 +389,7 @@ static void parse_config(const char *fn, char *s)
nargs = 0;
state.filename = fn;
state.line = 0;
- state.ptr = s;
+ state.ptr = strdup(data.c_str()); // TODO: fix this code!
state.nexttoken = 0;
state.parse_line = parse_line_no_op;
@@ -427,7 +427,6 @@ parser_done:
struct import *import = node_to_item(node, struct import, list);
int ret;
- INFO("importing '%s'", import->filename);
ret = init_parse_config_file(import->filename);
if (ret)
ERROR("could not import file '%s' from '%s'\n",
@@ -435,13 +434,14 @@ parser_done:
}
}
-int init_parse_config_file(const char *fn)
-{
- char *data;
- data = read_file(fn, 0);
- if (!data) return -1;
+int init_parse_config_file(const char* path) {
+ INFO("Parsing %s...", path);
+ std::string data;
+ if (!read_file(path, &data)) {
+ return -1;
+ }
- parse_config(fn, data);
+ parse_config(path, data);
dump_parser_state();
return 0;
}