Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3cb66ad3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "init: Refactor service.h/cpp"

parents c76078e4 e01ca4da
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -127,6 +127,7 @@ cc_library_static {
        "selabel.cpp",
        "selinux.cpp",
        "service.cpp",
        "service_utils.cpp",
        "sigchld_handler.cpp",
        "subcontext.cpp",
        "subcontext.proto",
@@ -259,6 +260,7 @@ cc_binary {
        "rlimit_parser.cpp",
        "tokenizer.cpp",
        "service.cpp",
        "service_utils.cpp",
        "subcontext.cpp",
        "subcontext.proto",
        "util.cpp",
+54 −249

File changed.

Preview size limit exceeded, changes collapsed.

+11 −26
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include "descriptors.h"
#include "keyword_map.h"
#include "parser.h"
#include "service_utils.h"
#include "subcontext.h"

#define SVC_DISABLED 0x001        // do not autostart with class
@@ -107,16 +108,16 @@ class Service {
    pid_t pid() const { return pid_; }
    android::base::boot_clock::time_point time_started() const { return time_started_; }
    int crash_count() const { return crash_count_; }
    uid_t uid() const { return uid_; }
    gid_t gid() const { return gid_; }
    unsigned namespace_flags() const { return namespace_flags_; }
    const std::vector<gid_t>& supp_gids() const { return supp_gids_; }
    uid_t uid() const { return proc_attr_.uid; }
    gid_t gid() const { return proc_attr_.gid; }
    unsigned namespace_flags() const { return namespaces_.flags; }
    const std::vector<gid_t>& supp_gids() const { return proc_attr_.supp_gids; }
    const std::string& seclabel() const { return seclabel_; }
    const std::vector<int>& keycodes() const { return keycodes_; }
    IoSchedClass ioprio_class() const { return ioprio_class_; }
    int ioprio_pri() const { return ioprio_pri_; }
    IoSchedClass ioprio_class() const { return proc_attr_.ioprio_class; }
    int ioprio_pri() const { return proc_attr_.ioprio_pri; }
    const std::set<std::string>& interfaces() const { return interfaces_; }
    int priority() const { return priority_; }
    int priority() const { return proc_attr_.priority; }
    int oom_score_adjust() const { return oom_score_adjust_; }
    bool is_override() const { return override_; }
    bool process_cgroup_empty() const { return process_cgroup_empty_; }
@@ -132,15 +133,10 @@ class Service {
    using OptionParser = Result<Success> (Service::*)(std::vector<std::string>&& args);
    class OptionParserMap;

    Result<Success> SetUpMountNamespace() const;
    Result<Success> SetUpPidNamespace() const;
    Result<Success> EnterNamespaces() const;
    void NotifyStateChange(const std::string& new_state) const;
    void StopOrReset(int how);
    void ZapStdio() const;
    void OpenConsole() const;
    void KillProcessGroup(int signal);
    void SetProcessAttributes();
    void SetProcessAttributesAndCaps();

    Result<Success> ParseCapabilities(std::vector<std::string>&& args);
    Result<Success> ParseClass(std::vector<std::string>&& args);
@@ -184,7 +180,6 @@ class Service {

    std::string name_;
    std::set<std::string> classnames_;
    std::string console_;

    unsigned flags_;
    pid_t pid_;
@@ -192,13 +187,9 @@ class Service {
    android::base::boot_clock::time_point time_crashed_;  // first crash within inspection window
    int crash_count_;                     // number of times crashed within window

    uid_t uid_;
    gid_t gid_;
    std::vector<gid_t> supp_gids_;
    std::optional<CapSet> capabilities_;
    unsigned namespace_flags_;
    // Pair of namespace type, path to namespace.
    std::vector<std::pair<int, std::string>> namespaces_to_enter_;
    ProcessAttributes proc_attr_;
    NamespaceInfo namespaces_;

    std::string seclabel_;

@@ -214,10 +205,6 @@ class Service {
    // keycodes for triggering this service via /dev/input/input*
    std::vector<int> keycodes_;

    IoSchedClass ioprio_class_;
    int ioprio_pri_;
    int priority_;

    int oom_score_adjust_;

    int swappiness_ = -1;
@@ -233,8 +220,6 @@ class Service {

    unsigned long start_order_;

    std::vector<std::pair<int, rlimit>> rlimits_;

    bool sigstop_ = false;

    std::chrono::seconds restart_period_ = 5s;

init/service_utils.cpp

0 → 100644
+265 −0

File added.

Preview size limit exceeded, changes collapsed.

init/service_utils.h

0 → 100644
+54 −0
Original line number Diff line number Diff line
/*
 * 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 <sys/resource.h>
#include <sys/types.h>

#include <string>
#include <vector>

#include <cutils/iosched_policy.h>

#include "result.h"

namespace android {
namespace init {

struct NamespaceInfo {
    unsigned flags;
    // Pair of namespace type, path to name.
    std::vector<std::pair<int, std::string>> namespaces_to_enter;
};
Result<Success> EnterNamespaces(const NamespaceInfo& info, const std::string& name, bool pre_apexd);

struct ProcessAttributes {
    std::string console;
    IoSchedClass ioprio_class;
    int ioprio_pri;
    std::vector<std::pair<int, rlimit>> rlimits;
    uid_t uid;
    gid_t gid;
    std::vector<gid_t> supp_gids;
    int priority;
};
Result<Success> SetProcessAttributes(const ProcessAttributes& attr);

Result<Success> WritePidToFiles(std::vector<std::string>* files);

}  // namespace init
}  // namespace android