Browse code

Error on attempting service logs on TTY container

Right now getting logs from a service with an attached TTY does not
work. The behavior was undefined and caused the command to hang and
strange messages to occur in the daemon logs.

This returns errors, both deep in the swarmkit adapter (to guard against
undefined behavior, which is Bad) and in the daemon (to tell users that
the thing they're asking for is not possible).

Signed-off-by: Drew Erny <drew.erny@docker.com>

Drew Erny authored on 2017/03/09 11:00:41
Showing 2 changed files
... ...
@@ -397,6 +397,12 @@ func (c *containerAdapter) deactivateServiceBinding() error {
397 397
 }
398 398
 
399 399
 func (c *containerAdapter) logs(ctx context.Context, options api.LogSubscriptionOptions) (io.ReadCloser, error) {
400
+	// we can't handle the peculiarities of a TTY-attached container yet
401
+	conf := c.container.config()
402
+	if conf != nil && conf.Tty {
403
+		return nil, errors.New("logs not supported on containers with a TTY attached")
404
+	}
405
+
400 406
 	reader, writer := io.Pipe()
401 407
 
402 408
 	apiOptions := &backend.ContainerLogsConfig{
... ...
@@ -262,6 +262,13 @@ func (c *Cluster) ServiceLogs(ctx context.Context, input string, config *backend
262 262
 		c.mu.RUnlock()
263 263
 		return err
264 264
 	}
265
+	container := service.Spec.Task.GetContainer()
266
+	if container == nil {
267
+		return errors.New("service logs only supported for container tasks")
268
+	}
269
+	if container.TTY {
270
+		return errors.New("service logs not supported on tasks with a TTY attached")
271
+	}
265 272
 
266 273
 	// set the streams we'll use
267 274
 	stdStreams := []swarmapi.LogStream{}