diff options
| author | Greg Steuck <blackgnezdo@gmail.com> | 2018-12-02 05:22:10 -0800 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-12-02 13:22:10 +0000 |
| commit | 7a0edfbe7c3703a0bf48f01dd818173a68a8f747 (patch) | |
| tree | 90c0faa35925f3a0cfcdd376315265a6936e396f /vm | |
| parent | 048d09b2054f0baeea83fe2595e496c0630e845f (diff) | |
vm/gce: use openbsd console diagnostic code for both vmm and gce
* openbsd: use console diagnostic code for both vmm and gce.
* gometalinter wants less indentation and more stuff in scope
* Comment no longer applies
Diffstat (limited to 'vm')
| -rw-r--r-- | vm/gce/gce.go | 31 | ||||
| -rw-r--r-- | vm/vmimpl/openbsd.go | 27 | ||||
| -rw-r--r-- | vm/vmm/vmm.go | 18 |
3 files changed, 48 insertions, 28 deletions
diff --git a/vm/gce/gce.go b/vm/gce/gce.go index 44f9e5d08..4c3708ad5 100644 --- a/vm/gce/gce.go +++ b/vm/gce/gce.go @@ -49,16 +49,17 @@ type Pool struct { } type instance struct { - env *vmimpl.Env - cfg *Config - GCE *gce.Context - debug bool - name string - ip string - gceKey string // per-instance private ssh key associated with the instance - sshKey string // ssh key - sshUser string - closed chan bool + env *vmimpl.Env + cfg *Config + GCE *gce.Context + debug bool + name string + ip string + gceKey string // per-instance private ssh key associated with the instance + sshKey string // ssh key + sshUser string + closed chan bool + consolew io.WriteCloser } func ctor(env *vmimpl.Env) (vmimpl.Pool, error) { @@ -189,6 +190,9 @@ func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) { func (inst *instance) Close() { close(inst.closed) inst.GCE.DeleteInstance(inst.name, false) + if inst.consolew != nil { + inst.consolew.Close() + } } func (inst *instance) Forward(port int) (string, error) { @@ -218,11 +222,13 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin con.Env = []string{} con.Stdout = conWpipe con.Stderr = conWpipe - if _, err := con.StdinPipe(); err != nil { // SSH would close connection on stdin EOF + conw, err := con.StdinPipe() + if err != nil { conRpipe.Close() conWpipe.Close() return nil, nil, err } + inst.consolew = conw if err := con.Start(); err != nil { conRpipe.Close() conWpipe.Close() @@ -358,6 +364,9 @@ func waitForConsoleConnect(merger *vmimpl.OutputMerger) error { } func (inst *instance) Diagnose() bool { + if inst.env.OS == "openbsd" { + return vmimpl.DiagnoseOpenBSD(inst.consolew) + } return false } diff --git a/vm/vmimpl/openbsd.go b/vm/vmimpl/openbsd.go new file mode 100644 index 000000000..79132ebf8 --- /dev/null +++ b/vm/vmimpl/openbsd.go @@ -0,0 +1,27 @@ +package vmimpl + +import ( + "io" + "time" +) + +// DiagnoseOpenBSD sends the debug commands to the given writer which +// is expected to be connected to a paniced openbsd kernel. If kernel +// just hanged, we've lost connection or detected some non-panic +// error, console still shows normal login prompt. +func DiagnoseOpenBSD(w io.Writer) bool { + commands := []string{ + "", + "set $lines = 0", // disable pagination + "show panic", + "trace", + "show registers", + "show proc", + "ps", + } + for _, c := range commands { + w.Write([]byte(c + "\n")) + time.Sleep(1 * time.Second) + } + return true +} diff --git a/vm/vmm/vmm.go b/vm/vmm/vmm.go index 72f47489c..4ba7d9a2f 100644 --- a/vm/vmm/vmm.go +++ b/vm/vmm/vmm.go @@ -311,23 +311,7 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin } func (inst *instance) Diagnose() bool { - // Note: this only works if kernel actually paniced and kernel shows panic console. - // If kernel just hanged, we've lost connection or detected some non-panic error, - // console still shows normal login prompt. - commands := []string{ - "", - "set $lines = 0", // disable pagination - "show panic", - "trace", - "show registers", - "show proc", - "ps", - } - for _, c := range commands { - inst.consolew.Write([]byte(c + "\n")) - time.Sleep(1 * time.Second) - } - return true + return vmimpl.DiagnoseOpenBSD(inst.consolew) } // Run the given vmctl(8) command and wait for it to finish. |
