Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
capture stderr of iodaemon and return the pid and unix socket path on…
Browse files Browse the repository at this point in the history
… ready

Signed-off-by: Brandon Shroyer <bshroyer@pivotal.io>
  • Loading branch information
jvshahid authored and Brandon Shroyer committed Aug 23, 2016
1 parent 8c7d829 commit c807283
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion iodaemon/iodaemon.go
Expand Up @@ -69,7 +69,7 @@ func Spawn(
var once sync.Once

for {
fmt.Fprintln(multiWriter, "ready")
fmt.Fprintf(multiWriter, "ready pid: %d, process-pid: %s, socket path: %s\n", os.Getpid(), pid, socketPath)
conn, err := acceptConnection(multiWriter, listener, stdoutR, stderrR, statusR)
fmt.Fprintln(multiWriter, "accepted-connection")
if err != nil {
Expand Down
29 changes: 17 additions & 12 deletions process_tracker/process.go
Expand Up @@ -9,6 +9,7 @@ import (
"os/exec"
"path"
"path/filepath"
"strings"
"sync"
"syscall"

Expand Down Expand Up @@ -196,12 +197,24 @@ func (p *Process) Spawn(cmd *exec.Cmd, tty *garden.TTYSpec) (ready, active chan
p.logger.Info("waiting for " + expectedLog)
log, err := spawnOut.ReadBytes('\n')
if err != nil {
p.logger.Error("errored waiting for "+expectedLog, err, lager.Data{"log": string(log)})
stderrContents, readErr := ioutil.ReadAll(spawnErr)
if readErr != nil {
p.logger.Error("errored waiting for "+expectedLog, err, lager.Data{"log": string(log), "readErr": readErr})
return err
}

p.logger.Error("errored waiting for "+expectedLog, err, lager.Data{"log": string(log), "stderr": string(stderrContents)})
return err
}

if string(log) != expectedLog+"\n" {
p.logger.Error("errored waiting for "+expectedLog+" got "+string(log), err)
if !strings.HasPrefix(string(log), expectedLog) {
stderrContents, readErr := ioutil.ReadAll(spawnErr)
if readErr != nil {
p.logger.Error("errored waiting for "+expectedLog, err, lager.Data{"log": string(log), "readErr": readErr})
return err
}

p.logger.Error("errored waiting for "+expectedLog, err, lager.Data{"stderr": string(stderrContents), "log": string(log)})
return errors.New("mismatched log from iodaemon")
}

Expand All @@ -227,15 +240,7 @@ func (p *Process) Spawn(cmd *exec.Cmd, tty *garden.TTYSpec) (ready, active chan
return
}

_, err = spawnOut.ReadBytes('\n')
if err != nil {
stderrContents, readErr := ioutil.ReadAll(spawnErr)
if readErr != nil {
p.logger.Error("failed to read active, and failed to read the stderr", err, lager.Data{"stderr": readErr})
return
}

p.logger.Error("failed to read active", err, lager.Data{"stderr": string(stderrContents)})
if waitFor("active") != nil {
return
}

Expand Down

0 comments on commit c807283

Please sign in to comment.