clang-tidy hinted that some of this code wasn't right. Looking deeper, there is really not much related to file and socket descriptors, except that they're published in similar ways to the environment. All of the abstraction into a 'Descriptor' class takes us further away from specifying what we really mean. This removes that abstraction, adds stricter checks and better errors for parsing init scripts, reports sockets and files that are unable to be acquired before exec, and updates the README.md for the passcred option. Test: build, logd (uses files and sockets) works Change-Id: I59e611e95c85bdbefa779ef69b32b9dd4ee203e2
94 lines
4.2 KiB
C++
94 lines
4.2 KiB
C++
/*
|
|
* Copyright (C) 2019 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <vector>
|
|
|
|
#include "parser.h"
|
|
#include "service.h"
|
|
#include "service_list.h"
|
|
#include "subcontext.h"
|
|
|
|
namespace android {
|
|
namespace init {
|
|
|
|
using InterfaceInheritanceHierarchyMap = std::map<std::string, std::set<std::string>>;
|
|
|
|
class ServiceParser : public SectionParser {
|
|
public:
|
|
ServiceParser(
|
|
ServiceList* service_list, std::vector<Subcontext>* subcontexts,
|
|
const std::optional<InterfaceInheritanceHierarchyMap>& interface_inheritance_hierarchy)
|
|
: service_list_(service_list),
|
|
subcontexts_(subcontexts),
|
|
interface_inheritance_hierarchy_(interface_inheritance_hierarchy),
|
|
service_(nullptr) {}
|
|
Result<void> ParseSection(std::vector<std::string>&& args, const std::string& filename,
|
|
int line) override;
|
|
Result<void> ParseLineSection(std::vector<std::string>&& args, int line) override;
|
|
Result<void> EndSection() override;
|
|
void EndFile() override { filename_ = ""; }
|
|
|
|
private:
|
|
using OptionParser = Result<void> (ServiceParser::*)(std::vector<std::string>&& args);
|
|
class OptionParserMap;
|
|
|
|
Result<void> ParseCapabilities(std::vector<std::string>&& args);
|
|
Result<void> ParseClass(std::vector<std::string>&& args);
|
|
Result<void> ParseConsole(std::vector<std::string>&& args);
|
|
Result<void> ParseCritical(std::vector<std::string>&& args);
|
|
Result<void> ParseDisabled(std::vector<std::string>&& args);
|
|
Result<void> ParseEnterNamespace(std::vector<std::string>&& args);
|
|
Result<void> ParseGroup(std::vector<std::string>&& args);
|
|
Result<void> ParsePriority(std::vector<std::string>&& args);
|
|
Result<void> ParseInterface(std::vector<std::string>&& args);
|
|
Result<void> ParseIoprio(std::vector<std::string>&& args);
|
|
Result<void> ParseKeycodes(std::vector<std::string>&& args);
|
|
Result<void> ParseOneshot(std::vector<std::string>&& args);
|
|
Result<void> ParseOnrestart(std::vector<std::string>&& args);
|
|
Result<void> ParseOomScoreAdjust(std::vector<std::string>&& args);
|
|
Result<void> ParseOverride(std::vector<std::string>&& args);
|
|
Result<void> ParseMemcgLimitInBytes(std::vector<std::string>&& args);
|
|
Result<void> ParseMemcgLimitPercent(std::vector<std::string>&& args);
|
|
Result<void> ParseMemcgLimitProperty(std::vector<std::string>&& args);
|
|
Result<void> ParseMemcgSoftLimitInBytes(std::vector<std::string>&& args);
|
|
Result<void> ParseMemcgSwappiness(std::vector<std::string>&& args);
|
|
Result<void> ParseNamespace(std::vector<std::string>&& args);
|
|
Result<void> ParseProcessRlimit(std::vector<std::string>&& args);
|
|
Result<void> ParseRestartPeriod(std::vector<std::string>&& args);
|
|
Result<void> ParseSeclabel(std::vector<std::string>&& args);
|
|
Result<void> ParseSetenv(std::vector<std::string>&& args);
|
|
Result<void> ParseShutdown(std::vector<std::string>&& args);
|
|
Result<void> ParseSigstop(std::vector<std::string>&& args);
|
|
Result<void> ParseSocket(std::vector<std::string>&& args);
|
|
Result<void> ParseTimeoutPeriod(std::vector<std::string>&& args);
|
|
Result<void> ParseFile(std::vector<std::string>&& args);
|
|
Result<void> ParseUser(std::vector<std::string>&& args);
|
|
Result<void> ParseWritepid(std::vector<std::string>&& args);
|
|
Result<void> ParseUpdatable(std::vector<std::string>&& args);
|
|
|
|
bool IsValidName(const std::string& name) const;
|
|
|
|
ServiceList* service_list_;
|
|
std::vector<Subcontext>* subcontexts_;
|
|
std::optional<InterfaceInheritanceHierarchyMap> interface_inheritance_hierarchy_;
|
|
std::unique_ptr<Service> service_;
|
|
std::string filename_;
|
|
};
|
|
|
|
} // namespace init
|
|
} // namespace android
|