1 /* 2 * Copyright (C) 2024 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 #ifndef ANDROID_DEVICE_GOOGLE_CUTTLEFISH_HOST_COMMANDS_SANDBOX_PROCESS_PROXY_COMMON_H 17 #define ANDROID_DEVICE_GOOGLE_CUTTLEFISH_HOST_COMMANDS_SANDBOX_PROCESS_PROXY_COMMON_H 18 19 #include <sys/socket.h> 20 #include <sys/un.h> 21 22 #include <optional> 23 #include <string> 24 #include <string_view> 25 26 #include <absl/status/statusor.h> 27 28 namespace cuttlefish { 29 namespace process_sandboxer { 30 31 static const constexpr std::string_view kHandshakeBegin = "hello"; 32 static const constexpr std::string_view kManagerSocketPath = "/manager.sock"; 33 34 class Message { 35 public: 36 static absl::StatusOr<Message> RecvFrom(int sock); 37 38 const std::string& Data() const; 39 absl::StatusOr<int> DataAsInt() const; 40 41 const std::optional<ucred>& Credentials() const; 42 43 std::string StrError() const; 44 45 private: 46 Message() = default; 47 48 std::string data_; 49 std::optional<ucred> credentials_; 50 }; 51 52 absl::StatusOr<size_t> SendStringMsg(int sock, std::string_view msg); 53 54 } // namespace process_sandboxer 55 } // namespace cuttlefish 56 #endif 57