Skip to content

Commit

Permalink
fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
arekouzounian committed Jul 1, 2024
1 parent 0d15f08 commit 1947b55
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions engine/process/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ const (
DefaultCpuTime = 1 // default max 1s in CPU
DefaultStackSize = 262144 // set default stack size to 0.25MB

// TODO: find better way to handle errors
EApplyingLimits = 10 // error code for applying limits
ERunningProc = 20 // error code when running command
)

// The process CLI is used to handle set limits on the current process/user
Expand Down Expand Up @@ -102,21 +100,28 @@ func main() {
err = cmd.Run()

if err != nil {
print.ProcDebug("error running process: %v\n", err)
if cast, ok := err.(*exec.ExitError); ok {
print.ProcDebug("exit error encountered: %v\n", err)
if ws, ok := cast.Sys().(syscall.WaitStatus); ok {
if ws.Signaled() {
// more verbose err message
cmd.Stderr.Write([]byte(err.Error()))
_, err := cmd.Stderr.Write([]byte(err.Error()))
if err != nil {
print.ProcDebug("error writing to command stderr: %v", err)
}

// signal exit code: 128 + signal code
os.Exit(128 + int(ws.Signal()))
}
} else {
print.ProcDebug("unable to capture WaitStatus on exit error\n")
}

// if for some reason we can't get the wait status then we
// can just get the (probably incorrect) error code from the cast
os.Exit(cast.ExitCode())
} else {
print.ProcDebug("encountered non exit-error failure: %v\n", err)
}
}
}

0 comments on commit 1947b55

Please sign in to comment.