瀏覽代碼

Extract client signals to pkg/signal

SIGCHLD and SIGWINCH used in api/client (cli code) are not
available on Windows. Extracting into separate files with build
tags.

Signed-off-by: Ahmet Alp Balkan <ahmetb@microsoft.com>
Ahmet Alp Balkan 10 年之前
父節點
當前提交
91a86670aa
共有 4 個文件被更改,包括 28 次插入5 次删除
  1. 2 3
      api/client/commands.go
  2. 2 2
      api/client/utils.go
  3. 12 0
      pkg/signal/signal_unix.go
  4. 12 0
      pkg/signal/signal_windows.go

+ 2 - 3
api/client/commands.go

@@ -18,7 +18,6 @@ import (
 	"runtime"
 	"runtime"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
-	"syscall"
 	"text/tabwriter"
 	"text/tabwriter"
 	"text/template"
 	"text/template"
 	"time"
 	"time"
@@ -608,7 +607,7 @@ func (cli *DockerCli) forwardAllSignals(cid string) chan os.Signal {
 	signal.CatchAll(sigc)
 	signal.CatchAll(sigc)
 	go func() {
 	go func() {
 		for s := range sigc {
 		for s := range sigc {
-			if s == syscall.SIGCHLD {
+			if s == signal.SIGCHLD {
 				continue
 				continue
 			}
 			}
 			var sig string
 			var sig string
@@ -619,7 +618,7 @@ func (cli *DockerCli) forwardAllSignals(cid string) chan os.Signal {
 				}
 				}
 			}
 			}
 			if sig == "" {
 			if sig == "" {
-				log.Errorf("Unsupported signal: %d. Discarding.", s)
+				log.Errorf("Unsupported signal: %v. Discarding.", s)
 			}
 			}
 			if _, _, err := readBody(cli.call("POST", fmt.Sprintf("/containers/%s/kill?signal=%s", cid, sig), nil, false)); err != nil {
 			if _, _, err := readBody(cli.call("POST", fmt.Sprintf("/containers/%s/kill?signal=%s", cid, sig), nil, false)); err != nil {
 				log.Debugf("Error sending signal: %s", err)
 				log.Debugf("Error sending signal: %s", err)

+ 2 - 2
api/client/utils.go

@@ -14,12 +14,12 @@ import (
 	gosignal "os/signal"
 	gosignal "os/signal"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
-	"syscall"
 
 
 	log "github.com/Sirupsen/logrus"
 	log "github.com/Sirupsen/logrus"
 	"github.com/docker/docker/api"
 	"github.com/docker/docker/api"
 	"github.com/docker/docker/dockerversion"
 	"github.com/docker/docker/dockerversion"
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/engine"
+	"github.com/docker/docker/pkg/signal"
 	"github.com/docker/docker/pkg/stdcopy"
 	"github.com/docker/docker/pkg/stdcopy"
 	"github.com/docker/docker/pkg/term"
 	"github.com/docker/docker/pkg/term"
 	"github.com/docker/docker/registry"
 	"github.com/docker/docker/registry"
@@ -238,7 +238,7 @@ func (cli *DockerCli) monitorTtySize(id string, isExec bool) error {
 	cli.resizeTty(id, isExec)
 	cli.resizeTty(id, isExec)
 
 
 	sigchan := make(chan os.Signal, 1)
 	sigchan := make(chan os.Signal, 1)
-	gosignal.Notify(sigchan, syscall.SIGWINCH)
+	gosignal.Notify(sigchan, signal.SIGWINCH)
 	go func() {
 	go func() {
 		for _ = range sigchan {
 		for _ = range sigchan {
 			cli.resizeTty(id, isExec)
 			cli.resizeTty(id, isExec)

+ 12 - 0
pkg/signal/signal_unix.go

@@ -0,0 +1,12 @@
+// +build !windows
+
+package signal
+
+import (
+	"syscall"
+)
+
+// Signals used in api/client (no windows equivalent, use
+// invalid signals so they don't get handled)
+const SIGCHLD = syscall.SIGCHLD
+const SIGWINCH = syscall.SIGWINCH

+ 12 - 0
pkg/signal/signal_windows.go

@@ -0,0 +1,12 @@
+// +build windows
+
+package signal
+
+import (
+	"syscall"
+)
+
+// Signals used in api/client (no windows equivalent, use
+// invalid signals so they don't get handled)
+const SIGCHLD = syscall.Signal(0xff)
+const SIGWINCH = syscall.Signal(0xff)