blob: eadabee8de740c4d7479c505b480ff3612b166ea [file] [log] [blame]
Tom Cherrycb0f9bb2017-09-12 15:58:47 -07001/*
2 * Copyright (C) 2017 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#ifndef _INIT_SUBCONTEXT_H
18#define _INIT_SUBCONTEXT_H
19
20#include <signal.h>
21
22#include <string>
23#include <vector>
24
25#include <android-base/unique_fd.h>
26
27#include "builtins.h"
28
29namespace android {
30namespace init {
31
32extern const std::string kInitContext;
33extern const std::string kVendorContext;
34
35class Subcontext {
36 public:
37 Subcontext(std::string path_prefix, std::string context)
Tom Cherrye6d37cd2017-10-19 14:15:37 -070038 : path_prefix_(std::move(path_prefix)), context_(std::move(context)), pid_(0) {
Tom Cherrycb0f9bb2017-09-12 15:58:47 -070039 Fork();
40 }
41
42 Result<Success> Execute(const std::vector<std::string>& command);
43 void Restart();
44
45 const std::string& path_prefix() const { return path_prefix_; }
46 const std::string& context() const { return context_; }
47 pid_t pid() const { return pid_; }
48
49 private:
50 void Fork();
51
52 std::string path_prefix_;
53 std::string context_;
54 pid_t pid_;
55 android::base::unique_fd socket_;
56};
57
Tom Cherrycb0f9bb2017-09-12 15:58:47 -070058int SubcontextMain(int argc, char** argv, const KeywordFunctionMap* function_map);
59std::vector<Subcontext>* InitializeSubcontexts();
60bool SubcontextChildReap(pid_t pid);
61
62} // namespace init
63} // namespace android
64
65#endif