mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix non exiting client issue
This commit is contained in:
parent
2ac4e662f1
commit
cacc7e564a
3 changed files with 66 additions and 67 deletions
14
api.go
14
api.go
|
@ -97,9 +97,9 @@ func getContainersExport(srv *Server, w http.ResponseWriter, r *http.Request) ([
|
|||
|
||||
in, out, err := hijackServer(w)
|
||||
if err != nil {
|
||||
defer in.Close()
|
||||
return nil, err
|
||||
}
|
||||
defer in.Close()
|
||||
fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: raw-stream-hijack\r\n\r\n")
|
||||
if err := srv.ContainerExport(name, out); err != nil {
|
||||
fmt.Fprintf(out, "Error: %s\n", err)
|
||||
|
@ -117,9 +117,9 @@ func getImages(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, err
|
|||
if viz {
|
||||
in, out, err := hijackServer(w)
|
||||
if err != nil {
|
||||
defer in.Close()
|
||||
return nil, err
|
||||
}
|
||||
defer in.Close()
|
||||
fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: raw-stream-hijack\r\n\r\n")
|
||||
if err := srv.ImagesViz(out); err != nil {
|
||||
fmt.Fprintf(out, "Error: %s\n", err)
|
||||
|
@ -269,9 +269,9 @@ func postImages(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, er
|
|||
|
||||
in, out, err := hijackServer(w)
|
||||
if err != nil {
|
||||
defer in.Close()
|
||||
return nil, err
|
||||
}
|
||||
defer in.Close()
|
||||
fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: raw-stream-hijack\r\n\r\n")
|
||||
if image != "" { //pull
|
||||
registry := r.Form.Get("registry")
|
||||
|
@ -317,9 +317,9 @@ func postImagesInsert(srv *Server, w http.ResponseWriter, r *http.Request) ([]by
|
|||
|
||||
in, out, err := hijackServer(w)
|
||||
if err != nil {
|
||||
defer in.Close()
|
||||
return nil, err
|
||||
}
|
||||
defer in.Close()
|
||||
fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: raw-stream-hijack\r\n\r\n")
|
||||
if err := srv.ImageInsert(name, url, path, out); err != nil {
|
||||
fmt.Fprintf(out, "Error: %s\n", err)
|
||||
|
@ -340,9 +340,9 @@ func postImagesPush(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte
|
|||
|
||||
in, out, err := hijackServer(w)
|
||||
if err != nil {
|
||||
defer in.Close()
|
||||
return nil, err
|
||||
}
|
||||
defer in.Close()
|
||||
fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: raw-stream-hijack\r\n\r\n")
|
||||
if err := srv.ImagePush(name, registry, out); err != nil {
|
||||
fmt.Fprintln(out, "Error: %s\n", err)
|
||||
|
@ -354,9 +354,9 @@ func postImagesPush(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte
|
|||
func postBuild(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, error) {
|
||||
in, out, err := hijackServer(w)
|
||||
if err != nil {
|
||||
defer in.Close()
|
||||
return nil, err
|
||||
}
|
||||
defer in.Close()
|
||||
fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: raw-stream-hijack\r\n\r\n")
|
||||
if err := srv.ImageCreateFromFile(in, out); err != nil {
|
||||
fmt.Fprintln(out, "Error: %s\n", err)
|
||||
|
@ -487,9 +487,9 @@ func postContainersAttach(srv *Server, w http.ResponseWriter, r *http.Request) (
|
|||
|
||||
in, out, err := hijackServer(w)
|
||||
if err != nil {
|
||||
defer in.Close()
|
||||
return nil, err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: raw-stream-hijack\r\n\r\n")
|
||||
if err := srv.ContainerAttach(name, logs, stream, stdin, stdout, stderr, in, out); err != nil {
|
||||
|
|
|
@ -1140,7 +1140,6 @@ func CmdRun(args ...string) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !config.AttachStdout && !config.AttachStderr {
|
||||
fmt.Println(out.Id)
|
||||
}
|
||||
|
|
118
server.go
118
server.go
|
@ -497,67 +497,67 @@ func (srv *Server) ContainerWait(name string) (int, error) {
|
|||
}
|
||||
|
||||
func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, stderr bool, in io.ReadCloser, out io.Writer) error {
|
||||
if container := srv.runtime.Get(name); container != nil {
|
||||
//logs
|
||||
if logs {
|
||||
if stdout {
|
||||
cLog, err := container.ReadLog("stdout")
|
||||
if err != nil {
|
||||
Debugf(err.Error())
|
||||
} else if _, err := io.Copy(out, cLog); err != nil {
|
||||
Debugf(err.Error())
|
||||
}
|
||||
}
|
||||
if stderr {
|
||||
cLog, err := container.ReadLog("stderr")
|
||||
if err != nil {
|
||||
Debugf(err.Error())
|
||||
} else if _, err := io.Copy(out, cLog); err != nil {
|
||||
Debugf(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//stream
|
||||
if stream {
|
||||
if container.State.Ghost {
|
||||
return fmt.Errorf("Impossible to attach to a ghost container")
|
||||
}
|
||||
|
||||
var (
|
||||
cStdin io.ReadCloser
|
||||
cStdout, cStderr io.Writer
|
||||
cStdinCloser io.Closer
|
||||
)
|
||||
|
||||
if stdin {
|
||||
r, w := io.Pipe()
|
||||
go func() {
|
||||
defer w.Close()
|
||||
defer Debugf("Closing buffered stdin pipe")
|
||||
io.Copy(w, in)
|
||||
}()
|
||||
cStdin = r
|
||||
cStdinCloser = in
|
||||
}
|
||||
if stdout {
|
||||
cStdout = out
|
||||
}
|
||||
if stderr {
|
||||
cStderr = out
|
||||
}
|
||||
|
||||
<-container.Attach(cStdin, cStdinCloser, cStdout, cStderr)
|
||||
|
||||
// If we are in stdinonce mode, wait for the process to end
|
||||
// otherwise, simply return
|
||||
if container.Config.StdinOnce && !container.Config.Tty {
|
||||
container.Wait()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
container := srv.runtime.Get(name)
|
||||
if container == nil {
|
||||
return fmt.Errorf("No such container: %s", name)
|
||||
}
|
||||
//logs
|
||||
if logs {
|
||||
if stdout {
|
||||
cLog, err := container.ReadLog("stdout")
|
||||
if err != nil {
|
||||
Debugf(err.Error())
|
||||
} else if _, err := io.Copy(out, cLog); err != nil {
|
||||
Debugf(err.Error())
|
||||
}
|
||||
}
|
||||
if stderr {
|
||||
cLog, err := container.ReadLog("stderr")
|
||||
if err != nil {
|
||||
Debugf(err.Error())
|
||||
} else if _, err := io.Copy(out, cLog); err != nil {
|
||||
Debugf(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//stream
|
||||
if stream {
|
||||
if container.State.Ghost {
|
||||
return fmt.Errorf("Impossible to attach to a ghost container")
|
||||
}
|
||||
|
||||
var (
|
||||
cStdin io.ReadCloser
|
||||
cStdout, cStderr io.Writer
|
||||
cStdinCloser io.Closer
|
||||
)
|
||||
|
||||
if stdin {
|
||||
r, w := io.Pipe()
|
||||
go func() {
|
||||
defer w.Close()
|
||||
defer Debugf("Closing buffered stdin pipe")
|
||||
io.Copy(w, in)
|
||||
}()
|
||||
cStdin = r
|
||||
cStdinCloser = in
|
||||
}
|
||||
if stdout {
|
||||
cStdout = out
|
||||
}
|
||||
if stderr {
|
||||
cStderr = out
|
||||
}
|
||||
|
||||
<-container.Attach(cStdin, cStdinCloser, cStdout, cStderr)
|
||||
|
||||
// If we are in stdinonce mode, wait for the process to end
|
||||
// otherwise, simply return
|
||||
if container.Config.StdinOnce && !container.Config.Tty {
|
||||
container.Wait()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue