aboutsummaryrefslogtreecommitdiffstats
path: root/vm/vmimpl/console.go
diff options
context:
space:
mode:
authorJoey Jiao <quic_jiangenj@quicinc.com>2024-06-17 09:45:16 +0800
committerAleksandr Nogikh <nogikh@google.com>2025-02-10 11:56:14 +0000
commit529cb927961356394978d77470022859e718c44a (patch)
treebc2d2e2f6d8040f9908d6bd22701f359dbbb3516 /vm/vmimpl/console.go
parentef44b750e8fab8d6d5cb84920680581b13e0d470 (diff)
vm: support console_cmd to run cmd to collect console log
- Sometimes we need customized cmd to get serial log, ex FTDI4232H chip gets serial log through usb directly, thus we need to call cmd like `pyterm.py ftdi://ftdi:4232:FT7JLD0U/1`. - There are seveval places in console implementation to call osutil.Command, move the command code into one function.
Diffstat (limited to 'vm/vmimpl/console.go')
-rw-r--r--vm/vmimpl/console.go52
1 files changed, 23 insertions, 29 deletions
diff --git a/vm/vmimpl/console.go b/vm/vmimpl/console.go
index 200c44f73..7ae680f26 100644
--- a/vm/vmimpl/console.go
+++ b/vm/vmimpl/console.go
@@ -77,46 +77,45 @@ func (t *tty) Close() error {
// OpenRemoteKernelLog accesses to the host where Android VM runs on, not Android VM itself.
// The host stores all kernel outputs of Android VM so in case of crashes nothing will be lost.
func OpenRemoteKernelLog(ip, console string) (rc io.ReadCloser, err error) {
- rpipe, wpipe, err := osutil.LongPipe()
- if err != nil {
- return nil, err
- }
conAddr := "vsoc-01@" + ip
- cmd := osutil.Command("ssh", conAddr, "tail", "-f", console)
- cmd.Stdout = wpipe
- cmd.Stderr = wpipe
- if _, err := cmd.StdinPipe(); err != nil {
- rpipe.Close()
- wpipe.Close()
- return nil, err
- }
- if err := cmd.Start(); err != nil {
- rpipe.Close()
- wpipe.Close()
- return nil, fmt.Errorf("failed to connect to console server: %w", err)
- }
- wpipe.Close()
- con := &remoteCon{
- cmd: cmd,
- rpipe: rpipe,
+ args := []string{
+ conAddr,
+ "tail",
+ "-f",
+ console,
}
- return con, nil
+ return OpenConsoleByCmd("ssh", args)
}
// Open dmesg remotely.
func OpenRemoteConsole(bin string, args ...string) (rc io.ReadCloser, err error) {
+ args = append(args, "dmesg -w")
+ return OpenConsoleByCmd(bin, args)
+}
+
+// OpenAdbConsole provides fallback console output using 'adb shell dmesg -w'.
+func OpenAdbConsole(bin, dev string) (rc io.ReadCloser, err error) {
+ return OpenRemoteConsole(bin, "-s", dev, "shell")
+}
+
+// Open console log by cmd.
+func OpenConsoleByCmd(bin string, args []string) (rc io.ReadCloser, err error) {
rpipe, wpipe, err := osutil.LongPipe()
if err != nil {
return nil, err
}
- args = append(args, "dmesg -w")
cmd := osutil.Command(bin, args...)
cmd.Stdout = wpipe
cmd.Stderr = wpipe
+ if _, err := cmd.StdinPipe(); err != nil {
+ rpipe.Close()
+ wpipe.Close()
+ return nil, err
+ }
if err := cmd.Start(); err != nil {
rpipe.Close()
wpipe.Close()
- return nil, fmt.Errorf("failed to start adb: %w", err)
+ return nil, fmt.Errorf("failed to open console: %w", err)
}
wpipe.Close()
con := &remoteCon{
@@ -126,11 +125,6 @@ func OpenRemoteConsole(bin string, args ...string) (rc io.ReadCloser, err error)
return con, err
}
-// OpenAdbConsole provides fallback console output using 'adb shell dmesg -w'.
-func OpenAdbConsole(bin, dev string) (rc io.ReadCloser, err error) {
- return OpenRemoteConsole(bin, "-s", dev, "shell")
-}
-
type remoteCon struct {
closeMu sync.Mutex
readMu sync.Mutex