| Vic Yang | e01ca4d | 2019-05-29 15:58:32 -0700 | [diff] [blame] | 1 | /* | 
 | 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 Cherry | 5241d10 | 2019-09-10 14:20:35 -0700 | [diff] [blame] | 25 | #include <android-base/unique_fd.h> | 
| Vic Yang | e01ca4d | 2019-05-29 15:58:32 -0700 | [diff] [blame] | 26 | #include <cutils/iosched_policy.h> | 
 | 27 |  | 
 | 28 | #include "result.h" | 
 | 29 |  | 
 | 30 | namespace android { | 
 | 31 | namespace init { | 
 | 32 |  | 
| Tom Cherry | 5241d10 | 2019-09-10 14:20:35 -0700 | [diff] [blame] | 33 | class 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 Cherry | 2e4c85f | 2019-07-09 13:33:36 -0700 | [diff] [blame] | 45 | struct 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 Cherry | 5241d10 | 2019-09-10 14:20:35 -0700 | [diff] [blame] | 54 |     Result<Descriptor> Create(const std::string& global_context) const; | 
| Tom Cherry | 2e4c85f | 2019-07-09 13:33:36 -0700 | [diff] [blame] | 55 | }; | 
 | 56 |  | 
 | 57 | struct FileDescriptor { | 
 | 58 |     std::string name; | 
 | 59 |     std::string type; | 
 | 60 |  | 
| Tom Cherry | 5241d10 | 2019-09-10 14:20:35 -0700 | [diff] [blame] | 61 |     Result<Descriptor> Create() const; | 
| Tom Cherry | 2e4c85f | 2019-07-09 13:33:36 -0700 | [diff] [blame] | 62 | }; | 
 | 63 |  | 
| Vic Yang | e01ca4d | 2019-05-29 15:58:32 -0700 | [diff] [blame] | 64 | struct NamespaceInfo { | 
| Tom Cherry | 247ffbf | 2019-07-08 15:09:36 -0700 | [diff] [blame] | 65 |     int flags; | 
| Vic Yang | e01ca4d | 2019-05-29 15:58:32 -0700 | [diff] [blame] | 66 |     // Pair of namespace type, path to name. | 
 | 67 |     std::vector<std::pair<int, std::string>> namespaces_to_enter; | 
 | 68 | }; | 
| Tom Cherry | bbcbc2f | 2019-06-10 11:08:01 -0700 | [diff] [blame] | 69 | Result<void> EnterNamespaces(const NamespaceInfo& info, const std::string& name, bool pre_apexd); | 
| Vic Yang | e01ca4d | 2019-05-29 15:58:32 -0700 | [diff] [blame] | 70 |  | 
 | 71 | struct 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; | 
| Tom Cherry | f74b7f5 | 2019-09-23 16:16:54 -0700 | [diff] [blame] | 80 |     bool stdio_to_kmsg; | 
| Vic Yang | e01ca4d | 2019-05-29 15:58:32 -0700 | [diff] [blame] | 81 | }; | 
| Tom Cherry | bbcbc2f | 2019-06-10 11:08:01 -0700 | [diff] [blame] | 82 | Result<void> SetProcessAttributes(const ProcessAttributes& attr); | 
| Vic Yang | e01ca4d | 2019-05-29 15:58:32 -0700 | [diff] [blame] | 83 |  | 
| Tom Cherry | bbcbc2f | 2019-06-10 11:08:01 -0700 | [diff] [blame] | 84 | Result<void> WritePidToFiles(std::vector<std::string>* files); | 
| Vic Yang | e01ca4d | 2019-05-29 15:58:32 -0700 | [diff] [blame] | 85 |  | 
 | 86 | }  // namespace init | 
 | 87 | }  // namespace android |