blob: f06cfc47d9f5f12e7e8c68423b570bdf695f8034 [file] [log] [blame]
Tom Cherry2aeb1ad2019-06-26 10:46:20 -07001/*
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
21#include "parser.h"
22#include "service.h"
23#include "service_list.h"
24#include "subcontext.h"
25
26namespace android {
27namespace init {
28
29class ServiceParser : public SectionParser {
30 public:
Jooyung Hand51fb542024-08-21 16:25:10 +090031 ServiceParser(ServiceList* service_list, Subcontext* subcontext)
32 : service_list_(service_list), subcontext_(subcontext), service_(nullptr) {}
Tom Cherry2aeb1ad2019-06-26 10:46:20 -070033 Result<void> ParseSection(std::vector<std::string>&& args, const std::string& filename,
34 int line) override;
35 Result<void> ParseLineSection(std::vector<std::string>&& args, int line) override;
36 Result<void> EndSection() override;
37 void EndFile() override { filename_ = ""; }
38
39 private:
Tom Cherryb1ffb1d2019-06-26 11:22:52 -070040 using OptionParser = Result<void> (ServiceParser::*)(std::vector<std::string>&& args);
Tom Cherryd52a5b32019-07-22 16:05:36 -070041 const KeywordMap<ServiceParser::OptionParser>& GetParserMap() const;
Tom Cherryb1ffb1d2019-06-26 11:22:52 -070042
43 Result<void> ParseCapabilities(std::vector<std::string>&& args);
44 Result<void> ParseClass(std::vector<std::string>&& args);
45 Result<void> ParseConsole(std::vector<std::string>&& args);
46 Result<void> ParseCritical(std::vector<std::string>&& args);
47 Result<void> ParseDisabled(std::vector<std::string>&& args);
48 Result<void> ParseEnterNamespace(std::vector<std::string>&& args);
49 Result<void> ParseGroup(std::vector<std::string>&& args);
Daniel Rosenbergde766882022-12-01 15:44:31 -080050 Result<void> ParseGentleKill(std::vector<std::string>&& args);
Tom Cherryb1ffb1d2019-06-26 11:22:52 -070051 Result<void> ParsePriority(std::vector<std::string>&& args);
52 Result<void> ParseInterface(std::vector<std::string>&& args);
53 Result<void> ParseIoprio(std::vector<std::string>&& args);
54 Result<void> ParseKeycodes(std::vector<std::string>&& args);
55 Result<void> ParseOneshot(std::vector<std::string>&& args);
56 Result<void> ParseOnrestart(std::vector<std::string>&& args);
57 Result<void> ParseOomScoreAdjust(std::vector<std::string>&& args);
58 Result<void> ParseOverride(std::vector<std::string>&& args);
59 Result<void> ParseMemcgLimitInBytes(std::vector<std::string>&& args);
60 Result<void> ParseMemcgLimitPercent(std::vector<std::string>&& args);
61 Result<void> ParseMemcgLimitProperty(std::vector<std::string>&& args);
62 Result<void> ParseMemcgSoftLimitInBytes(std::vector<std::string>&& args);
63 Result<void> ParseMemcgSwappiness(std::vector<std::string>&& args);
64 Result<void> ParseNamespace(std::vector<std::string>&& args);
65 Result<void> ParseProcessRlimit(std::vector<std::string>&& args);
Tom Cherry60971e62019-09-10 10:40:47 -070066 Result<void> ParseRebootOnFailure(std::vector<std::string>&& args);
Tom Cherryb1ffb1d2019-06-26 11:22:52 -070067 Result<void> ParseRestartPeriod(std::vector<std::string>&& args);
68 Result<void> ParseSeclabel(std::vector<std::string>&& args);
69 Result<void> ParseSetenv(std::vector<std::string>&& args);
70 Result<void> ParseShutdown(std::vector<std::string>&& args);
71 Result<void> ParseSigstop(std::vector<std::string>&& args);
72 Result<void> ParseSocket(std::vector<std::string>&& args);
Tom Cherryf74b7f52019-09-23 16:16:54 -070073 Result<void> ParseStdioToKmsg(std::vector<std::string>&& args);
Suren Baghdasaryanc9c0bba2020-04-30 11:58:39 -070074 Result<void> ParseTaskProfiles(std::vector<std::string>&& args);
Tom Cherryb1ffb1d2019-06-26 11:22:52 -070075 Result<void> ParseTimeoutPeriod(std::vector<std::string>&& args);
76 Result<void> ParseFile(std::vector<std::string>&& args);
77 Result<void> ParseUser(std::vector<std::string>&& args);
78 Result<void> ParseWritepid(std::vector<std::string>&& args);
79 Result<void> ParseUpdatable(std::vector<std::string>&& args);
80
Tom Cherry2aeb1ad2019-06-26 10:46:20 -070081 bool IsValidName(const std::string& name) const;
82
83 ServiceList* service_list_;
Tom Cherry14c24722019-09-18 13:47:19 -070084 Subcontext* subcontext_;
Tom Cherry2aeb1ad2019-06-26 10:46:20 -070085 std::unique_ptr<Service> service_;
86 std::string filename_;
Tom Cherry2aeb1ad2019-06-26 10:46:20 -070087};
88
89} // namespace init
90} // namespace android