Small improvements

This commit is contained in:
Alex Dadgar 2015-11-03 10:50:30 -08:00
parent 5562fc7672
commit 271702f4a2
3 changed files with 12 additions and 8 deletions

View File

@ -179,7 +179,7 @@ func TestJavaDriver_Start_Kill_Wait(t *testing.T) {
if err == nil {
t.Fatal("should err")
}
case <-time.After(2 * time.Second):
case <-time.After(8 * time.Second):
t.Fatalf("timeout")
}

View File

@ -54,8 +54,7 @@ type LinuxExecutor struct {
allocDir string
// Spawn process.
spawn *spawn.Spawner
spawnState string
spawn *spawn.Spawner
}
func (e *LinuxExecutor) Command() *cmd {
@ -180,7 +179,7 @@ func (e *LinuxExecutor) Start() error {
e.spawn.SetLogs(&spawn.Logs{
Stdout: filepath.Join(e.taskDir, allocdir.TaskLocal, fmt.Sprintf("%v.stdout", e.taskName)),
Stderr: filepath.Join(e.taskDir, allocdir.TaskLocal, fmt.Sprintf("%v.stderr", e.taskName)),
Stdin: "/dev/null",
Stdin: os.DevNull,
})
enterCgroup := func(pid int) error {
@ -309,13 +308,16 @@ func (e *LinuxExecutor) pathExists(path string) bool {
// should be called when tearing down the task.
func (e *LinuxExecutor) cleanTaskDir() error {
// Unmount dev.
// TODO: This should check if it is a mount.
errs := new(multierror.Error)
dev := filepath.Join(e.taskDir, "dev")
if e.pathExists(dev) {
if err := syscall.Unmount(dev, 0); err != nil {
errs = multierror.Append(errs, fmt.Errorf("Failed to unmount dev (%v): %v", dev, err))
}
if err := os.RemoveAll(dev); err != nil {
errs = multierror.Append(errs, fmt.Errorf("Failed to delete dev directory (%v): %v", dev, err))
}
}
// Unmount proc.
@ -324,6 +326,10 @@ func (e *LinuxExecutor) cleanTaskDir() error {
if err := syscall.Unmount(proc, 0); err != nil {
errs = multierror.Append(errs, fmt.Errorf("Failed to unmount proc (%v): %v", proc, err))
}
if err := os.RemoveAll(proc); err != nil {
errs = multierror.Append(errs, fmt.Errorf("Failed to delete proc directory (%v): %v", dev, err))
}
}
return errs.ErrorOrNil()

View File

@ -225,10 +225,8 @@ func (s *Spawner) waitAsParent() (int, error) {
}
}
if state, err := s.spawn.Wait(); err != nil {
if _, err := s.spawn.Wait(); err != nil {
return -1, err
} else if !state.Exited() {
return -1, fmt.Errorf("Task was killed or crashed")
}
return s.waitOnStatusFile()