blob: d2e69d9186b3b3273a0c19b22abfb728a0661839 [file] [log] [blame]
Vic Yange01ca4d2019-05-29 15:58:32 -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 <sys/resource.h>
20#include <sys/types.h>
21
22#include <string>
23#include <vector>
24
Tom Cherry5241d102019-09-10 14:20:35 -070025#include <android-base/unique_fd.h>
Vic Yange01ca4d2019-05-29 15:58:32 -070026#include <cutils/iosched_policy.h>
27
28#include "result.h"
29
30namespace android {
31namespace init {
32
Tom Cherry5241d102019-09-10 14:20:35 -070033class Descriptor {
34 public:
35 Descriptor(const std::string& name, android::base::unique_fd fd)
36 : name_(name), fd_(std::move(fd)){};
37
38 void Publish() const;
39
40 private:
41 std::string name_;
42 android::base::unique_fd fd_;
43};
44
Tom Cherry2e4c85f2019-07-09 13:33:36 -070045struct SocketDescriptor {
46 std::string name;
47 int type = 0;
48 uid_t uid = 0;
49 gid_t gid = 0;
50 int perm = 0;
51 std::string context;
52 bool passcred = false;
53
Tom Cherry5241d102019-09-10 14:20:35 -070054 Result<Descriptor> Create(const std::string& global_context) const;
Tom Cherry2e4c85f2019-07-09 13:33:36 -070055};
56
57struct FileDescriptor {
58 std::string name;
59 std::string type;
60
Tom Cherry5241d102019-09-10 14:20:35 -070061 Result<Descriptor> Create() const;
Tom Cherry2e4c85f2019-07-09 13:33:36 -070062};
63
Vic Yange01ca4d2019-05-29 15:58:32 -070064struct NamespaceInfo {
Tom Cherry247ffbf2019-07-08 15:09:36 -070065 int flags;
Vic Yange01ca4d2019-05-29 15:58:32 -070066 // Pair of namespace type, path to name.
67 std::vector<std::pair<int, std::string>> namespaces_to_enter;
68};
Tom Cherrybbcbc2f2019-06-10 11:08:01 -070069Result<void> EnterNamespaces(const NamespaceInfo& info, const std::string& name, bool pre_apexd);
Vic Yange01ca4d2019-05-29 15:58:32 -070070
71struct ProcessAttributes {
72 std::string console;
73 IoSchedClass ioprio_class;
74 int ioprio_pri;
75 std::vector<std::pair<int, rlimit>> rlimits;
76 uid_t uid;
77 gid_t gid;
78 std::vector<gid_t> supp_gids;
79 int priority;
80};
Tom Cherrybbcbc2f2019-06-10 11:08:01 -070081Result<void> SetProcessAttributes(const ProcessAttributes& attr);
Vic Yange01ca4d2019-05-29 15:58:32 -070082
Tom Cherrybbcbc2f2019-06-10 11:08:01 -070083Result<void> WritePidToFiles(std::vector<std::string>* files);
Vic Yange01ca4d2019-05-29 15:58:32 -070084
85} // namespace init
86} // namespace android