Guillaume J. Charmes 12 лет назад
Родитель
Сommit
ccac5b1382
2 измененных файлов с 29 добавлено и 3 удалено
  1. 18 3
      commands.go
  2. 11 0
      container.go

+ 18 - 3
commands.go

@@ -798,20 +798,35 @@ func (srv *Server) CmdAttach(stdin io.ReadCloser, stdout io.Writer, args ...stri
 			return err
 			return err
 		}
 		}
 		wg.Add(1)
 		wg.Add(1)
-		go func() { io.Copy(cStdin, stdin); wg.Add(-1) }()
+		go func() {
+			Debugf("Begin stdin pipe [attach]")
+			io.Copy(cStdin, stdin)
+			wg.Add(-1)
+			Debugf("End of stdin pipe [attach]")
+		}()
 	}
 	}
 	cStdout, err := container.StdoutPipe()
 	cStdout, err := container.StdoutPipe()
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
 	wg.Add(1)
 	wg.Add(1)
-	go func() { io.Copy(stdout, cStdout); wg.Add(-1) }()
+	go func() {
+		Debugf("Begin stdout pipe [attach]")
+		io.Copy(stdout, cStdout)
+		wg.Add(-1)
+		Debugf("End of stdout pipe [attach]")
+	}()
 	cStderr, err := container.StderrPipe()
 	cStderr, err := container.StderrPipe()
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
 	wg.Add(1)
 	wg.Add(1)
-	go func() { io.Copy(stdout, cStderr); wg.Add(-1) }()
+	go func() {
+		Debugf("Begin stderr pipe [attach]")
+		io.Copy(stdout, cStderr)
+		wg.Add(-1)
+		Debugf("End of stderr pipe [attach]")
+	}()
 	wg.Wait()
 	wg.Wait()
 	return nil
 	return nil
 }
 }

+ 11 - 0
container.go

@@ -165,12 +165,16 @@ func (container *Container) startPty() error {
 	// Copy the PTYs to our broadcasters
 	// Copy the PTYs to our broadcasters
 	go func() {
 	go func() {
 		defer container.stdout.Close()
 		defer container.stdout.Close()
+		Debugf("[startPty] Begin of stdout pipe")
 		io.Copy(container.stdout, stdoutMaster)
 		io.Copy(container.stdout, stdoutMaster)
+		Debugf("[startPty] End of stdout pipe")
 	}()
 	}()
 
 
 	go func() {
 	go func() {
 		defer container.stderr.Close()
 		defer container.stderr.Close()
+		Debugf("[startPty] Begin of stderr pipe")
 		io.Copy(container.stderr, stderrMaster)
 		io.Copy(container.stderr, stderrMaster)
+		Debugf("[startPty] End of stderr pipe")
 	}()
 	}()
 
 
 	// stdin
 	// stdin
@@ -186,7 +190,9 @@ func (container *Container) startPty() error {
 		// container.cmd.SysProcAttr = &syscall.SysProcAttr{Setctty: true, Setsid: true}
 		// container.cmd.SysProcAttr = &syscall.SysProcAttr{Setctty: true, Setsid: true}
 		go func() {
 		go func() {
 			defer container.stdin.Close()
 			defer container.stdin.Close()
+			Debugf("[startPty] Begin of stdin pipe")
 			io.Copy(stdinMaster, container.stdin)
 			io.Copy(stdinMaster, container.stdin)
+			Debugf("[startPty] End of stdin pipe")
 		}()
 		}()
 	}
 	}
 	if err := container.cmd.Start(); err != nil {
 	if err := container.cmd.Start(); err != nil {
@@ -210,7 +216,9 @@ func (container *Container) start() error {
 		}
 		}
 		go func() {
 		go func() {
 			defer stdin.Close()
 			defer stdin.Close()
+			Debugf("Begin of stdin pipe [start]")
 			io.Copy(stdin, container.stdin)
 			io.Copy(stdin, container.stdin)
+			Debugf("End of stdin pipe [start]")
 		}()
 		}()
 	}
 	}
 	return container.cmd.Start()
 	return container.cmd.Start()
@@ -348,7 +356,10 @@ func (container *Container) releaseNetwork() error {
 
 
 func (container *Container) monitor() {
 func (container *Container) monitor() {
 	// Wait for the program to exit
 	// Wait for the program to exit
+	Debugf("Waiting for process")
 	container.cmd.Wait()
 	container.cmd.Wait()
+	Debugf("Process finished")
+
 	exitCode := container.cmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus()
 	exitCode := container.cmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus()
 
 
 	// Cleanup
 	// Cleanup