Tom Cherry | 2aeb1ad | 2019-06-26 10:46:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | #pragma once |
| 18 | |
| 19 | #include <vector> |
| 20 | |
Daniel Norman | d2533c3 | 2019-08-02 15:13:50 -0700 | [diff] [blame] | 21 | #include "interface_utils.h" |
Tom Cherry | 2aeb1ad | 2019-06-26 10:46:20 -0700 | [diff] [blame] | 22 | #include "parser.h" |
| 23 | #include "service.h" |
| 24 | #include "service_list.h" |
| 25 | #include "subcontext.h" |
| 26 | |
| 27 | namespace android { |
| 28 | namespace init { |
| 29 | |
| 30 | class ServiceParser : public SectionParser { |
| 31 | public: |
Daniel Norman | 3f42a76 | 2019-07-09 11:00:53 -0700 | [diff] [blame] | 32 | ServiceParser( |
Tom Cherry | 14c2472 | 2019-09-18 13:47:19 -0700 | [diff] [blame] | 33 | ServiceList* service_list, Subcontext* subcontext, |
Nikita Ioffe | 091c4d1 | 2019-12-05 12:35:19 +0000 | [diff] [blame] | 34 | const std::optional<InterfaceInheritanceHierarchyMap>& interface_inheritance_hierarchy, |
| 35 | bool from_apex = false) |
Daniel Norman | 3df8dc5 | 2019-06-27 12:18:08 -0700 | [diff] [blame] | 36 | : service_list_(service_list), |
Tom Cherry | 14c2472 | 2019-09-18 13:47:19 -0700 | [diff] [blame] | 37 | subcontext_(subcontext), |
Daniel Norman | 3f42a76 | 2019-07-09 11:00:53 -0700 | [diff] [blame] | 38 | interface_inheritance_hierarchy_(interface_inheritance_hierarchy), |
Nikita Ioffe | 091c4d1 | 2019-12-05 12:35:19 +0000 | [diff] [blame] | 39 | service_(nullptr), |
| 40 | from_apex_(from_apex) {} |
Tom Cherry | 2aeb1ad | 2019-06-26 10:46:20 -0700 | [diff] [blame] | 41 | Result<void> ParseSection(std::vector<std::string>&& args, const std::string& filename, |
| 42 | int line) override; |
| 43 | Result<void> ParseLineSection(std::vector<std::string>&& args, int line) override; |
| 44 | Result<void> EndSection() override; |
| 45 | void EndFile() override { filename_ = ""; } |
| 46 | |
| 47 | private: |
Tom Cherry | b1ffb1d | 2019-06-26 11:22:52 -0700 | [diff] [blame] | 48 | using OptionParser = Result<void> (ServiceParser::*)(std::vector<std::string>&& args); |
Tom Cherry | d52a5b3 | 2019-07-22 16:05:36 -0700 | [diff] [blame] | 49 | const KeywordMap<ServiceParser::OptionParser>& GetParserMap() const; |
Tom Cherry | b1ffb1d | 2019-06-26 11:22:52 -0700 | [diff] [blame] | 50 | |
| 51 | Result<void> ParseCapabilities(std::vector<std::string>&& args); |
| 52 | Result<void> ParseClass(std::vector<std::string>&& args); |
| 53 | Result<void> ParseConsole(std::vector<std::string>&& args); |
| 54 | Result<void> ParseCritical(std::vector<std::string>&& args); |
| 55 | Result<void> ParseDisabled(std::vector<std::string>&& args); |
| 56 | Result<void> ParseEnterNamespace(std::vector<std::string>&& args); |
| 57 | Result<void> ParseGroup(std::vector<std::string>&& args); |
| 58 | Result<void> ParsePriority(std::vector<std::string>&& args); |
| 59 | Result<void> ParseInterface(std::vector<std::string>&& args); |
| 60 | Result<void> ParseIoprio(std::vector<std::string>&& args); |
| 61 | Result<void> ParseKeycodes(std::vector<std::string>&& args); |
| 62 | Result<void> ParseOneshot(std::vector<std::string>&& args); |
| 63 | Result<void> ParseOnrestart(std::vector<std::string>&& args); |
| 64 | Result<void> ParseOomScoreAdjust(std::vector<std::string>&& args); |
| 65 | Result<void> ParseOverride(std::vector<std::string>&& args); |
| 66 | Result<void> ParseMemcgLimitInBytes(std::vector<std::string>&& args); |
| 67 | Result<void> ParseMemcgLimitPercent(std::vector<std::string>&& args); |
| 68 | Result<void> ParseMemcgLimitProperty(std::vector<std::string>&& args); |
| 69 | Result<void> ParseMemcgSoftLimitInBytes(std::vector<std::string>&& args); |
| 70 | Result<void> ParseMemcgSwappiness(std::vector<std::string>&& args); |
| 71 | Result<void> ParseNamespace(std::vector<std::string>&& args); |
| 72 | Result<void> ParseProcessRlimit(std::vector<std::string>&& args); |
Tom Cherry | 60971e6 | 2019-09-10 10:40:47 -0700 | [diff] [blame] | 73 | Result<void> ParseRebootOnFailure(std::vector<std::string>&& args); |
Tom Cherry | b1ffb1d | 2019-06-26 11:22:52 -0700 | [diff] [blame] | 74 | Result<void> ParseRestartPeriod(std::vector<std::string>&& args); |
| 75 | Result<void> ParseSeclabel(std::vector<std::string>&& args); |
| 76 | Result<void> ParseSetenv(std::vector<std::string>&& args); |
| 77 | Result<void> ParseShutdown(std::vector<std::string>&& args); |
| 78 | Result<void> ParseSigstop(std::vector<std::string>&& args); |
| 79 | Result<void> ParseSocket(std::vector<std::string>&& args); |
Tom Cherry | f74b7f5 | 2019-09-23 16:16:54 -0700 | [diff] [blame] | 80 | Result<void> ParseStdioToKmsg(std::vector<std::string>&& args); |
Suren Baghdasaryan | c9c0bba | 2020-04-30 11:58:39 -0700 | [diff] [blame] | 81 | Result<void> ParseTaskProfiles(std::vector<std::string>&& args); |
Tom Cherry | b1ffb1d | 2019-06-26 11:22:52 -0700 | [diff] [blame] | 82 | Result<void> ParseTimeoutPeriod(std::vector<std::string>&& args); |
| 83 | Result<void> ParseFile(std::vector<std::string>&& args); |
| 84 | Result<void> ParseUser(std::vector<std::string>&& args); |
| 85 | Result<void> ParseWritepid(std::vector<std::string>&& args); |
| 86 | Result<void> ParseUpdatable(std::vector<std::string>&& args); |
| 87 | |
Tom Cherry | 2aeb1ad | 2019-06-26 10:46:20 -0700 | [diff] [blame] | 88 | bool IsValidName(const std::string& name) const; |
| 89 | |
| 90 | ServiceList* service_list_; |
Tom Cherry | 14c2472 | 2019-09-18 13:47:19 -0700 | [diff] [blame] | 91 | Subcontext* subcontext_; |
Daniel Norman | 3f42a76 | 2019-07-09 11:00:53 -0700 | [diff] [blame] | 92 | std::optional<InterfaceInheritanceHierarchyMap> interface_inheritance_hierarchy_; |
Tom Cherry | 2aeb1ad | 2019-06-26 10:46:20 -0700 | [diff] [blame] | 93 | std::unique_ptr<Service> service_; |
| 94 | std::string filename_; |
Nikita Ioffe | 091c4d1 | 2019-12-05 12:35:19 +0000 | [diff] [blame] | 95 | bool from_apex_ = false; |
Tom Cherry | 2aeb1ad | 2019-06-26 10:46:20 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | } // namespace init |
| 99 | } // namespace android |