mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 14:24:39 +00:00
agent/proxy: pull exit status extraction to constrained file
This commit is contained in:
parent
1a2b28602c
commit
420edc4c1e
@ -7,7 +7,6 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -151,10 +150,8 @@ func (p *Daemon) keepAlive(stopCh <-chan struct{}) {
|
|||||||
process = nil
|
process = nil
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.Logger.Printf("[INFO] agent/proxy: daemon exited with error: %s", err)
|
p.Logger.Printf("[INFO] agent/proxy: daemon exited with error: %s", err)
|
||||||
} else if status, ok := ps.Sys().(syscall.WaitStatus); ok {
|
} else if status, ok := exitStatus(ps); ok {
|
||||||
p.Logger.Printf(
|
p.Logger.Printf("[INFO] agent/proxy: daemon exited with exit code: %d", status)
|
||||||
"[INFO] agent/proxy: daemon exited with exit code: %d",
|
|
||||||
status.ExitStatus())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,8 +173,15 @@ func (p *Daemon) start() (*os.Process, error) {
|
|||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
// Args must always contain a 0 entry which is usually the executed binary.
|
||||||
|
// To be safe and a bit more robust we default this, but only to prevent
|
||||||
|
// a panic below.
|
||||||
|
if len(cmd.Args) == 0 {
|
||||||
|
cmd.Args = []string{cmd.Path}
|
||||||
|
}
|
||||||
|
|
||||||
// Start it
|
// Start it
|
||||||
p.Logger.Printf("[DEBUG] agent/proxy: starting proxy: %q %#v", cmd.Path, cmd.Args)
|
p.Logger.Printf("[DEBUG] agent/proxy: starting proxy: %q %#v", cmd.Path, cmd.Args[1:])
|
||||||
err := cmd.Start()
|
err := cmd.Start()
|
||||||
return cmd.Process, err
|
return cmd.Process, err
|
||||||
}
|
}
|
||||||
|
10
agent/proxy/exitstatus_other.go
Normal file
10
agent/proxy/exitstatus_other.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// +build !darwin,!linux,!windows
|
||||||
|
|
||||||
|
package proxy
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
// exitStatus for other platforms where we don't know how to extract it.
|
||||||
|
func exitStatus(ps *os.ProcessState) (int, bool) {
|
||||||
|
return 0, false
|
||||||
|
}
|
18
agent/proxy/exitstatus_syscall.go
Normal file
18
agent/proxy/exitstatus_syscall.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// +build darwin linux windows
|
||||||
|
|
||||||
|
package proxy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
// exitStatus for platforms with syscall.WaitStatus which are listed
|
||||||
|
// at the top of this file in the build constraints.
|
||||||
|
func exitStatus(ps *os.ProcessState) (int, bool) {
|
||||||
|
if status, ok := ps.Sys().(syscall.WaitStatus); ok {
|
||||||
|
return status.ExitStatus(), true
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0, false
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user