Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Commit

Permalink
error code propagation (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Mishin authored Sep 13, 2017
1 parent ea528d3 commit 6b72c45
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lib/box/websrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"os/exec"
"syscall"

"github.com/gravitational/planet/lib/constants"

"github.com/gravitational/roundtrip"
"github.com/gravitational/trace"
log "github.com/sirupsen/logrus"

"github.com/julienschmidt/httprouter"
"github.com/opencontainers/runc/libcontainer"

log "github.com/sirupsen/logrus"
"golang.org/x/net/websocket"
)

Expand Down Expand Up @@ -84,18 +85,23 @@ func (s *webServer) enter(w http.ResponseWriter, r *http.Request, p httprouter.P

cfg.In = conn
cfg.Out = cmdOut
if err = StartProcess(s.container, *cfg); err != nil {
log.Errorf("StartProcess(%v) failed with %v", cfg, trace.DebugReport(err))
if errTrace, ok := err.(*trace.TraceErr); ok {
if errExit, ok := errTrace.OrigError().(*exec.ExitError); ok {
if waitStatus, ok := errExit.ProcessState.Sys().(syscall.WaitStatus); ok {
cmdOut.writeExitCode(waitStatus.ExitStatus())
}
}

err = StartProcess(s.container, *cfg)
if err == nil {
return
}

log.Errorf("StartProcess(%v) failed with %v", cfg, trace.DebugReport(err))

if errExit, ok := trace.Unwrap(err).(*exec.ExitError); ok {
if waitStatus, ok := errExit.ProcessState.Sys().(syscall.WaitStatus); ok {
cmdOut.writeExitCode(waitStatus.ExitStatus())
return
}
}
log.Infof("StartProcess(%v) completed!", cfg)
cmdOut.writeExitCode(constants.ExitCodeUnknown)
}

s.socketServer.ServeHTTP(w, r)
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions lib/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ const (

// DNSResourceName specifies the name for the DNS resources
DNSResourceName = "kube-dns"

// ExitCodeUnknown is equivalent to EX_SOFTWARE as defined by sysexits(3)
ExitCodeUnknown = 70
)

0 comments on commit 6b72c45

Please sign in to comment.