blob: 5232b7e5e74e48268316d2bbb62310fbbe92a663 [file] [log] [blame]
Tom Cherryde6bd502018-02-13 16:50:08 -08001//
2// Copyright (C) 2018 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#include <pwd.h>
18
19#include <android-base/logging.h>
20
21#include "action.h"
22#include "action_manager.h"
23#include "action_parser.h"
24#include "parser.h"
25#include "result.h"
26#include "service.h"
27
28// The host passwd file won't have the Android entries, so we fake success here.
29passwd* getpwnam(const char* login) { // NOLINT: implementing bad function.
30 char dummy_buf[] = "dummy";
31 static passwd dummy_passwd = {
32 .pw_name = dummy_buf,
33 .pw_dir = dummy_buf,
34 .pw_shell = dummy_buf,
35 .pw_uid = 123,
36 .pw_gid = 123,
37 };
38 return &dummy_passwd;
39}
40
41namespace android {
42namespace init {
43
44static Result<Success> do_stub(const BuiltinArguments& args) {
45 return Success();
46}
47
48#include "generated_stub_builtin_function_map.h"
49
50int main(int argc, char** argv) {
51 android::base::InitLogging(argv, &android::base::StderrLogger);
52 if (argc != 2) {
53 LOG(ERROR) << "Usage: " << argv[0] << " <init file to parse>";
54 return -1;
55 }
56 const BuiltinFunctionMap function_map;
57 Action::set_function_map(&function_map);
58 ActionManager& am = ActionManager::GetInstance();
59 ServiceList& sl = ServiceList::GetInstance();
60 Parser parser;
61 parser.AddSectionParser("service", std::make_unique<ServiceParser>(&sl, nullptr));
62 parser.AddSectionParser("on", std::make_unique<ActionParser>(&am, nullptr));
63
64 size_t num_errors = 0;
65 if (!parser.ParseConfig(argv[1], &num_errors)) {
66 LOG(ERROR) << "Failed to find script";
67 return -1;
68 }
69 if (num_errors > 0) {
70 LOG(ERROR) << "Parse failed with " << num_errors << " errors";
71 return -1;
72 }
73 LOG(INFO) << "Parse success!";
74 return 0;
75}
76
77} // namespace init
78} // namespace android
79
80int main(int argc, char** argv) {
81 android::init::main(argc, argv);
82}