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

Commit

Permalink
few improvements:
Browse files Browse the repository at this point in the history
- use iodaemon pid as well as the process pid in the log file name
- cleanup iodaemon and strace logs on successfull exit of iodaemon
- make sure we receive a line with "ready" when we are waiting for "ready"
  • Loading branch information
jvshahid committed Aug 24, 2016
1 parent c807283 commit 1a22c41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
8 changes: 6 additions & 2 deletions iodaemon/iodaemon.go
Expand Up @@ -36,8 +36,10 @@ func Spawn(
return err
}

currentPid := os.Getpid()
pid := strings.Split(filepath.Base(socketPath), ".")[0]
logFile, err = os.OpenFile(filepath.Join(filepath.Dir(socketPath), fmt.Sprintf(pid+".iodaemon")), os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644)
logFilePath := filepath.Join(filepath.Dir(socketPath), fmt.Sprintf("%s.%d.iodaemon", pid, currentPid))
logFile, err = os.OpenFile(logFilePath, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -105,6 +107,8 @@ func Spawn(
exit = byte(ws.ExitStatus())
}

logFile.Close()
os.Remove(logFilePath)
fmt.Fprintf(statusW, "%d\n", exit)
case <-time.After(timeout):
contents, err := ioutil.ReadFile("/proc/net/unix")
Expand All @@ -115,7 +119,7 @@ func Spawn(
}

fmt.Fprintf(logFile, "output of netstat -xap: \n")
cmd := exec.Command("netstat", "-xap")
cmd := exec.Command("/bin/netstat", "-xap")
cmd.Stdout = logFile
cmd.Stderr = logFile
if err := cmd.Run(); err != nil {
Expand Down
22 changes: 8 additions & 14 deletions process_tracker/process.go
Expand Up @@ -179,20 +179,6 @@ func (p *Process) Spawn(cmd *exec.Cmd, tty *garden.TTYSpec) (ready, active chan
}

go func() {
_, err := spawnOut.ReadBytes('\n')
if err != nil {
stderrContents, readErr := ioutil.ReadAll(spawnErr)
if readErr != nil {
ready <- fmt.Errorf("failed to read ready (%s), and failed to read the stderr: %s", err, readErr)
return
}

ready <- fmt.Errorf("failed to read ready (%s): %s", err, string(stderrContents))
return
}

ready <- nil

waitFor := func(expectedLog string) error {
p.logger.Info("waiting for " + expectedLog)
log, err := spawnOut.ReadBytes('\n')
Expand Down Expand Up @@ -221,6 +207,12 @@ func (p *Process) Spawn(cmd *exec.Cmd, tty *garden.TTYSpec) (ready, active chan
return nil
}

if waitFor("ready") != nil {
return
}

ready <- nil

if waitFor("listener-accepted") != nil {
return
}
Expand All @@ -247,6 +239,8 @@ func (p *Process) Spawn(cmd *exec.Cmd, tty *garden.TTYSpec) (ready, active chan
active <- nil

spawn.Wait()

os.Remove(straceOutput)
}()

return
Expand Down

0 comments on commit 1a22c41

Please sign in to comment.