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 #include "host/commands/run_cvd/launch/launch.h"
17 
18 #include <string>
19 
20 #include <fruit/fruit.h>
21 
22 #include "common/libs/utils/result.h"
23 #include "host/libs/config/command_source.h"
24 #include "host/libs/config/known_paths.h"
25 
26 namespace cuttlefish {
27 
ConsoleInfo(const CuttlefishConfig::InstanceSpecific & instance)28 std::string ConsoleInfo(const CuttlefishConfig::InstanceSpecific& instance) {
29   if (instance.console()) {
30     return "To access the console run: screen " + instance.console_path();
31   } else {
32     return "Serial console is disabled; use -console=true to enable it.";
33   }
34 }
35 
ConsoleForwarder(const CuttlefishConfig::InstanceSpecific & instance)36 Result<std::optional<MonitorCommand>> ConsoleForwarder(
37     const CuttlefishConfig::InstanceSpecific& instance) {
38   if (!instance.console()) {
39     return {};
40   }
41   // These fds will only be read from or written to, but open them with
42   // read and write access to keep them open in case the subprocesses exit
43   auto console_in_pipe_name = instance.console_in_pipe_name();
44   auto console_forwarder_in_wr =
45       CF_EXPECT(SharedFD::Fifo(console_in_pipe_name, 0600));
46 
47   auto console_out_pipe_name = instance.console_out_pipe_name();
48   auto console_forwarder_out_rd =
49       CF_EXPECT(SharedFD::Fifo(console_out_pipe_name, 0600));
50 
51   Command console_forwarder_cmd(ConsoleForwarderBinary());
52   return Command(ConsoleForwarderBinary())
53       .AddParameter("--console_in_fd=", console_forwarder_in_wr)
54       .AddParameter("--console_out_fd=", console_forwarder_out_rd);
55 }
56 
57 }  // namespace cuttlefish
58