diff --git a/base/cvd/cuttlefish/host/commands/console_forwarder/BUILD.bazel b/base/cvd/cuttlefish/host/commands/console_forwarder/BUILD.bazel index 2e7c9f162db..2e8127f2fe3 100644 --- a/base/cvd/cuttlefish/host/commands/console_forwarder/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/console_forwarder/BUILD.bazel @@ -12,6 +12,7 @@ cf_cc_binary( deps = [ "//cuttlefish/common/libs/fs", "//cuttlefish/host/commands/kernel_log_monitor:kernel_log_monitor_utils", + "//cuttlefish/host/libs/config:config_instance_derived", "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/host/libs/config:logging", "//cuttlefish/posix:strerror", diff --git a/base/cvd/cuttlefish/host/commands/console_forwarder/main.cpp b/base/cvd/cuttlefish/host/commands/console_forwarder/main.cpp index f084081cb26..80173a06066 100644 --- a/base/cvd/cuttlefish/host/commands/console_forwarder/main.cpp +++ b/base/cvd/cuttlefish/host/commands/console_forwarder/main.cpp @@ -31,6 +31,7 @@ #include "cuttlefish/common/libs/fs/shared_fd.h" #include "cuttlefish/common/libs/fs/shared_select.h" +#include "cuttlefish/host/libs/config/config_instance_derived.h" #include "cuttlefish/host/libs/config/cuttlefish_config.h" #include "cuttlefish/host/libs/config/logging.h" #include "cuttlefish/posix/strerror.h" @@ -239,8 +240,8 @@ int ConsoleForwarderMain(int argc, char** argv) { auto console_log = instance.PerInstancePath("console_log"); auto console_log_fd = SharedFD::Open(console_log.c_str(), O_CREAT | O_APPEND | O_WRONLY, 0666); - auto kernel_log_fd = SharedFD::Open(instance.kernel_log_pipe_name(), - O_APPEND | O_WRONLY, 0666); + SharedFD kernel_log_fd = + SharedFD::Open(KernelLogPipeName(instance), O_APPEND | O_WRONLY, 0666); ConsoleForwarder console_forwarder(console_path, console_in, console_out, console_log_fd, kernel_log_fd); diff --git a/base/cvd/cuttlefish/host/commands/kernel_log_monitor/BUILD.bazel b/base/cvd/cuttlefish/host/commands/kernel_log_monitor/BUILD.bazel index 5cee670fefe..8e4d802e4b3 100644 --- a/base/cvd/cuttlefish/host/commands/kernel_log_monitor/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/kernel_log_monitor/BUILD.bazel @@ -14,6 +14,7 @@ cf_cc_binary( deps = [ ":kernel_log_monitor_utils", "//cuttlefish/common/libs/fs", + "//cuttlefish/host/libs/config:config_instance_derived", "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/host/libs/config:logging", "//cuttlefish/result", diff --git a/base/cvd/cuttlefish/host/commands/kernel_log_monitor/main.cc b/base/cvd/cuttlefish/host/commands/kernel_log_monitor/main.cc index e282251c790..8fec511c777 100644 --- a/base/cvd/cuttlefish/host/commands/kernel_log_monitor/main.cc +++ b/base/cvd/cuttlefish/host/commands/kernel_log_monitor/main.cc @@ -31,10 +31,11 @@ #include "cuttlefish/common/libs/fs/shared_fd.h" #include "cuttlefish/common/libs/fs/shared_select.h" -#include "cuttlefish/host/libs/config/cuttlefish_config.h" -#include "cuttlefish/host/libs/config/logging.h" #include "cuttlefish/host/commands/kernel_log_monitor/kernel_log_server.h" #include "cuttlefish/host/commands/kernel_log_monitor/utils.h" +#include "cuttlefish/host/libs/config/config_instance_derived.h" +#include "cuttlefish/host/libs/config/cuttlefish_config.h" +#include "cuttlefish/host/libs/config/logging.h" DEFINE_int32(log_pipe_fd, -1, "A file descriptor representing a (UNIX) socket from which to " @@ -89,8 +90,8 @@ int KernelLogMonitorMain(int argc, char** argv) { SharedFD pipe; if (FLAGS_log_pipe_fd < 0) { - auto log_name = instance.kernel_log_pipe_name(); - pipe = SharedFD::Open(log_name.c_str(), O_RDONLY); + std::string log_name = KernelLogPipeName(instance); + pipe = SharedFD::Open(log_name, O_RDONLY); } else { pipe = SharedFD::Dup(FLAGS_log_pipe_fd); close(FLAGS_log_pipe_fd); diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/launch/BUILD.bazel b/base/cvd/cuttlefish/host/commands/run_cvd/launch/BUILD.bazel index d2cc3f7e65d..018342d9a08 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/launch/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/run_cvd/launch/BUILD.bazel @@ -87,6 +87,7 @@ cf_cc_library( deps = [ "//cuttlefish/common/libs/fs", "//cuttlefish/common/libs/utils:subprocess", + "//cuttlefish/host/libs/config:config_instance_derived", "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/host/libs/config:known_paths", "//cuttlefish/host/libs/feature", @@ -174,6 +175,7 @@ cf_cc_library( deps = [ "//cuttlefish/common/libs/utils:subprocess", "//cuttlefish/host/commands/run_cvd:reporting", + "//cuttlefish/host/libs/config:config_instance_derived", "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/host/libs/config:known_paths", "//cuttlefish/host/libs/config:logging", diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/launch/console_forwarder.cpp b/base/cvd/cuttlefish/host/commands/run_cvd/launch/console_forwarder.cpp index 75680e7d620..d191454131d 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/launch/console_forwarder.cpp +++ b/base/cvd/cuttlefish/host/commands/run_cvd/launch/console_forwarder.cpp @@ -20,6 +20,7 @@ #include "cuttlefish/common/libs/fs/shared_fd.h" #include "cuttlefish/common/libs/utils/subprocess.h" +#include "cuttlefish/host/libs/config/config_instance_derived.h" #include "cuttlefish/host/libs/config/cuttlefish_config.h" #include "cuttlefish/host/libs/config/known_paths.h" #include "cuttlefish/host/libs/feature/command_source.h" @@ -42,15 +43,12 @@ Result> ConsoleForwarder( } // These fds will only be read from or written to, but open them with // read and write access to keep them open in case the subprocesses exit - auto console_in_pipe_name = instance.console_in_pipe_name(); - auto console_forwarder_in_wr = - CF_EXPECT(SharedFD::Fifo(console_in_pipe_name, 0600)); + SharedFD console_forwarder_in_wr = + CF_EXPECT(SharedFD::Fifo(ConsoleInPipeName(instance), 0600)); - auto console_out_pipe_name = instance.console_out_pipe_name(); - auto console_forwarder_out_rd = - CF_EXPECT(SharedFD::Fifo(console_out_pipe_name, 0600)); + SharedFD console_forwarder_out_rd = + CF_EXPECT(SharedFD::Fifo(ConsoleOutPipeName(instance), 0600)); - Command console_forwarder_cmd(ConsoleForwarderBinary()); return Command(ConsoleForwarderBinary()) .AddParameter("--console_in_fd=", console_forwarder_in_wr) .AddParameter("--console_out_fd=", console_forwarder_out_rd); diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/launch/kernel_log_monitor.cpp b/base/cvd/cuttlefish/host/commands/run_cvd/launch/kernel_log_monitor.cpp index e6ffbf6b0cf..5613bc9b825 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/launch/kernel_log_monitor.cpp +++ b/base/cvd/cuttlefish/host/commands/run_cvd/launch/kernel_log_monitor.cpp @@ -32,6 +32,7 @@ #include "cuttlefish/common/libs/utils/subprocess.h" #include "cuttlefish/host/commands/run_cvd/reporting.h" +#include "cuttlefish/host/libs/config/config_instance_derived.h" #include "cuttlefish/host/libs/config/cuttlefish_config.h" #include "cuttlefish/host/libs/config/known_paths.h" #include "cuttlefish/host/libs/feature/command_source.h" @@ -99,7 +100,7 @@ class KernelLogMonitor : public CommandSource, private: std::unordered_set Dependencies() const override { return {}; } Result ResultSetup() override { - auto log_name = instance_.kernel_log_pipe_name(); + std::string log_name = KernelLogPipeName(instance_); // Open the pipe here (from the launcher) to ensure the pipe is not deleted // due to the usage counters in the kernel reaching zero. If this is not // done and the kernel_log_monitor crashes for some reason the VMM may get diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/server_loop_impl.cpp b/base/cvd/cuttlefish/host/commands/run_cvd/server_loop_impl.cpp index 99dcb36a5ee..5b5faebd509 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/server_loop_impl.cpp +++ b/base/cvd/cuttlefish/host/commands/run_cvd/server_loop_impl.cpp @@ -322,9 +322,9 @@ void ServerLoopImpl::HandleActionWithNoData(const LauncherAction action, void ServerLoopImpl::DeleteFifos() { // TODO(schuffelen): Create these FIFOs in assemble_cvd instead of run_cvd. std::vector pipes = { - instance_.kernel_log_pipe_name(), - instance_.console_in_pipe_name(), - instance_.console_out_pipe_name(), + KernelLogPipeName(instance_), + ConsoleInPipeName(instance_), + ConsoleOutPipeName(instance_), LogcatPipeName(instance_), instance_.PerInstanceInternalPath("keymaster_fifo_vm.in"), instance_.PerInstanceInternalPath("keymaster_fifo_vm.out"), diff --git a/base/cvd/cuttlefish/host/libs/config/config_instance_derived.cc b/base/cvd/cuttlefish/host/libs/config/config_instance_derived.cc index c87de6edb52..094c95b524f 100644 --- a/base/cvd/cuttlefish/host/libs/config/config_instance_derived.cc +++ b/base/cvd/cuttlefish/host/libs/config/config_instance_derived.cc @@ -26,6 +26,22 @@ std::string AccessKregistryPath(const CuttlefishConfig::InstanceSpecific& ins) { return AbsolutePath(ins.PerInstancePath("access-kregistry")); } +std::string ConsoleInPipeName(const CuttlefishConfig::InstanceSpecific& ins) { + return ConsolePipePrefix(ins) + ".in"; +} + +std::string ConsoleOutPipeName(const CuttlefishConfig::InstanceSpecific& ins) { + return ConsolePipePrefix(ins) + ".out"; +} + +std::string ConsolePipePrefix(const CuttlefishConfig::InstanceSpecific& ins) { + return AbsolutePath(ins.PerInstanceInternalPath("console")); +} + +std::string KernelLogPipeName(const CuttlefishConfig::InstanceSpecific& ins) { + return AbsolutePath(ins.PerInstanceInternalPath("kernel-log-pipe")); +} + std::string LogcatPipeName(const CuttlefishConfig::InstanceSpecific& ins) { return AbsolutePath(ins.PerInstanceInternalPath("logcat-pipe")); } diff --git a/base/cvd/cuttlefish/host/libs/config/config_instance_derived.h b/base/cvd/cuttlefish/host/libs/config/config_instance_derived.h index 1ca504cece9..bee97e2307d 100644 --- a/base/cvd/cuttlefish/host/libs/config/config_instance_derived.h +++ b/base/cvd/cuttlefish/host/libs/config/config_instance_derived.h @@ -22,6 +22,10 @@ namespace cuttlefish { std::string AccessKregistryPath(const CuttlefishConfig::InstanceSpecific&); +std::string ConsoleInPipeName(const CuttlefishConfig::InstanceSpecific&); +std::string ConsoleOutPipeName(const CuttlefishConfig::InstanceSpecific&); +std::string ConsolePipePrefix(const CuttlefishConfig::InstanceSpecific&); +std::string KernelLogPipeName(const CuttlefishConfig::InstanceSpecific& ins); std::string LogcatPipeName(const CuttlefishConfig::InstanceSpecific&); std::string RestoreAdbdPipeName(const CuttlefishConfig::InstanceSpecific&); diff --git a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h index baa6e45cf48..0b1e0d5d9cd 100644 --- a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h +++ b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h @@ -363,16 +363,6 @@ class CuttlefishConfig { std::string logcat_path() const; - std::string kernel_log_pipe_name() const; - - std::string console_pipe_prefix() const; - std::string console_in_pipe_name() const; - std::string console_out_pipe_name() const; - - std::string gnss_pipe_prefix() const; - std::string gnss_in_pipe_name() const; - std::string gnss_out_pipe_name() const; - std::string launcher_log_path() const; std::string launcher_monitor_socket_path() const; diff --git a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp index 0293922f966..1bc3d9123e4 100644 --- a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp +++ b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp @@ -478,34 +478,6 @@ void CuttlefishConfig::MutableInstanceSpecific::set_external_network_mode( (*Dictionary())[kExternalNetworkMode] = fmt::format("{}", mode); } -std::string CuttlefishConfig::InstanceSpecific::kernel_log_pipe_name() const { - return AbsolutePath(PerInstanceInternalPath("kernel-log-pipe")); -} - -std::string CuttlefishConfig::InstanceSpecific::console_pipe_prefix() const { - return AbsolutePath(PerInstanceInternalPath("console")); -} - -std::string CuttlefishConfig::InstanceSpecific::console_in_pipe_name() const { - return console_pipe_prefix() + ".in"; -} - -std::string CuttlefishConfig::InstanceSpecific::console_out_pipe_name() const { - return console_pipe_prefix() + ".out"; -} - -std::string CuttlefishConfig::InstanceSpecific::gnss_pipe_prefix() const { - return AbsolutePath(PerInstanceInternalPath("gnss")); -} - -std::string CuttlefishConfig::InstanceSpecific::gnss_in_pipe_name() const { - return gnss_pipe_prefix() + ".in"; -} - -std::string CuttlefishConfig::InstanceSpecific::gnss_out_pipe_name() const { - return gnss_pipe_prefix() + ".out"; -} - static constexpr char kGnssGrpcProxyServerPort[] = "gnss_grpc_proxy_server_port"; int CuttlefishConfig::InstanceSpecific::gnss_grpc_proxy_server_port() const { diff --git a/base/cvd/cuttlefish/host/libs/vm_manager/crosvm_manager.cpp b/base/cvd/cuttlefish/host/libs/vm_manager/crosvm_manager.cpp index cbb52fbb903..7636167f1e3 100644 --- a/base/cvd/cuttlefish/host/libs/vm_manager/crosvm_manager.cpp +++ b/base/cvd/cuttlefish/host/libs/vm_manager/crosvm_manager.cpp @@ -747,7 +747,7 @@ Result> CrosvmManager::StartCommands( // kernel log event features working. If an alternative "earlycon" boot // console is configured below on a legacy serial port, it will control // the main log until the virtio-console takes over. - crosvm_cmd.AddHvcReadOnly(instance.kernel_log_pipe_name(), + crosvm_cmd.AddHvcReadOnly(KernelLogPipeName(instance), instance.enable_kernel_log()); // /dev/hvc1 = serial console @@ -757,8 +757,8 @@ Result> CrosvmManager::StartCommands( // only the serial port output is received by the console forwarder as // crosvm may print other messages to stdout. if (instance.kgdb() || instance.use_bootloader()) { - crosvm_cmd.AddSerialConsoleReadWrite(instance.console_out_pipe_name(), - instance.console_in_pipe_name(), + crosvm_cmd.AddSerialConsoleReadWrite(ConsoleOutPipeName(instance), + ConsoleInPipeName(instance), instance.enable_kernel_log()); // In kgdb mode, we have the interactive console on ttyS0 (both Android's // console and kdb), so we can disable the virtio-console port usually @@ -768,8 +768,8 @@ Result> CrosvmManager::StartCommands( crosvm_cmd.AddHvcSink(); } else { crosvm_cmd.AddSerialSink(); - crosvm_cmd.AddHvcReadWrite(instance.console_out_pipe_name(), - instance.console_in_pipe_name()); + crosvm_cmd.AddHvcReadWrite(ConsoleOutPipeName(instance), + ConsoleInPipeName(instance)); } } else { // Use an 8250 UART (ISA or platform device) for earlycon, as the @@ -778,7 +778,7 @@ Result> CrosvmManager::StartCommands( // dmesg will go there instead of the kernel.log if (instance.enable_kernel_log() && (instance.kgdb() || instance.use_bootloader())) { - crosvm_cmd.AddSerialConsoleReadOnly(instance.kernel_log_pipe_name()); + crosvm_cmd.AddSerialConsoleReadOnly(KernelLogPipeName(instance)); } // as above, create a fake virtio-console 'sink' port when the serial diff --git a/base/cvd/cuttlefish/host/libs/vm_manager/qemu_manager.cpp b/base/cvd/cuttlefish/host/libs/vm_manager/qemu_manager.cpp index 44cc79ef8d7..7951833de19 100644 --- a/base/cvd/cuttlefish/host/libs/vm_manager/qemu_manager.cpp +++ b/base/cvd/cuttlefish/host/libs/vm_manager/qemu_manager.cpp @@ -514,7 +514,7 @@ Result> QemuManager::StartCommands( // flags appear in the right order and "append=on" does the right thing if (instance.enable_kernel_log() && (instance.kgdb() || instance.use_bootloader())) { - add_serial_console_ro(instance.kernel_log_pipe_name()); + add_serial_console_ro(KernelLogPipeName(instance)); } } @@ -534,12 +534,12 @@ Result> QemuManager::StartCommands( // (Note that QEMU does not automatically generate console= parameters for // the bootloader/kernel cmdline, so the control of whether this pipe is // actually managed by the kernel as a console is handled elsewhere.) - add_hvc_ro(instance.kernel_log_pipe_name()); + add_hvc_ro(KernelLogPipeName(instance)); // /dev/hvc1 = serial console if (instance.console()) { if (instance.kgdb() || instance.use_bootloader()) { - add_serial_console(instance.console_pipe_prefix()); + add_serial_console(ConsolePipePrefix(instance)); // In kgdb mode, we have the interactive console on ttyS0 (both Android's // console and kdb), so we can disable the virtio-console port usually @@ -549,7 +549,7 @@ Result> QemuManager::StartCommands( add_hvc_sink(); } else { add_serial_sink(); - add_hvc(instance.console_pipe_prefix()); + add_hvc(ConsolePipePrefix(instance)); } } else { if (instance.kgdb() || instance.use_bootloader()) {