1 //
2 // Copyright (C) 2023 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 #include "host/commands/run_cvd/launch/snapshot_control_files.h"
17
18 #include <unistd.h>
19
20 namespace cuttlefish {
21
Create(const CuttlefishConfig::InstanceSpecific & instance)22 Result<SnapshotControlFiles> SnapshotControlFiles::Create(
23 const CuttlefishConfig::InstanceSpecific& instance) {
24 auto confui_socket_path =
25 instance.PerInstanceInternalUdsPath("confui_sign.sock");
26 unlink(confui_socket_path.c_str());
27 auto confui_server_fd =
28 SharedFD::SocketLocalServer(confui_socket_path, false, SOCK_STREAM, 0600);
29 CF_EXPECTF(confui_server_fd->IsOpen(), "Could not open \"{}\": {}",
30 confui_socket_path, confui_server_fd->StrError());
31
32 SharedFD snapshot_control_fd;
33 SharedFD run_cvd_to_secure_env_fd;
34 CF_EXPECT(SharedFD::SocketPair(AF_UNIX, SOCK_STREAM, 0, &snapshot_control_fd,
35 &run_cvd_to_secure_env_fd));
36
37 return SnapshotControlFiles{
38 confui_server_fd,
39 snapshot_control_fd,
40 run_cvd_to_secure_env_fd,
41 };
42 }
43
44 } // namespace cuttlefish
45