Browse code

Rename 'StdConfig' to 'StreamConfig'.

Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)

Vishnu Kannan authored on 2014/08/27 07:44:00
Showing 12 changed files
... ...
@@ -127,7 +127,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
127 127
 
128 128
 	if stdin != nil && container.Config.OpenStdin {
129 129
 		nJobs++
130
-		if cStdin, err := container.StdConfig.StdinPipe(); err != nil {
130
+		if cStdin, err := container.StdinPipe(); err != nil {
131 131
 			errors <- err
132 132
 		} else {
133 133
 			go func() {
... ...
@@ -163,7 +163,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
163 163
 	}
164 164
 	if stdout != nil {
165 165
 		nJobs++
166
-		if p, err := container.StdConfig.StdoutPipe(); err != nil {
166
+		if p, err := container.StdoutPipe(); err != nil {
167 167
 			errors <- err
168 168
 		} else {
169 169
 			cStdout = p
... ...
@@ -192,7 +192,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
192 192
 			if stdinCloser != nil {
193 193
 				defer stdinCloser.Close()
194 194
 			}
195
-			if cStdout, err := container.StdConfig.StdoutPipe(); err != nil {
195
+			if cStdout, err := container.StdoutPipe(); err != nil {
196 196
 				log.Errorf("attach: stdout pipe: %s", err)
197 197
 			} else {
198 198
 				io.Copy(&utils.NopWriter{}, cStdout)
... ...
@@ -201,7 +201,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
201 201
 	}
202 202
 	if stderr != nil {
203 203
 		nJobs++
204
-		if p, err := container.StdConfig.StderrPipe(); err != nil {
204
+		if p, err := container.StderrPipe(); err != nil {
205 205
 			errors <- err
206 206
 		} else {
207 207
 			cStderr = p
... ...
@@ -231,7 +231,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
231 231
 				defer stdinCloser.Close()
232 232
 			}
233 233
 
234
-			if cStderr, err := container.StdConfig.StderrPipe(); err != nil {
234
+			if cStderr, err := container.StderrPipe(); err != nil {
235 235
 				log.Errorf("attach: stdout pipe: %s", err)
236 236
 			} else {
237 237
 				io.Copy(&utils.NopWriter{}, cStderr)
... ...
@@ -41,7 +41,7 @@ var (
41 41
 	ErrContainerStartTimeout = errors.New("The container failed to start due to timed out.")
42 42
 )
43 43
 
44
-type StdConfig struct {
44
+type StreamConfig struct {
45 45
 	stdout    *broadcastwriter.BroadcastWriter
46 46
 	stderr    *broadcastwriter.BroadcastWriter
47 47
 	stdin     io.ReadCloser
... ...
@@ -72,8 +72,8 @@ type Container struct {
72 72
 	Driver         string
73 73
 	ExecDriver     string
74 74
 
75
-	command   *execdriver.Command
76
-	StdConfig StdConfig
75
+	command *execdriver.Command
76
+	StreamConfig
77 77
 
78 78
 	daemon                   *Daemon
79 79
 	MountLabel, ProcessLabel string
... ...
@@ -338,7 +338,7 @@ func (container *Container) Run() error {
338 338
 }
339 339
 
340 340
 func (container *Container) Output() (output []byte, err error) {
341
-	pipe, err := container.StdConfig.StdoutPipe()
341
+	pipe, err := container.StdoutPipe()
342 342
 	if err != nil {
343 343
 		return nil, err
344 344
 	}
... ...
@@ -351,7 +351,7 @@ func (container *Container) Output() (output []byte, err error) {
351 351
 	return output, err
352 352
 }
353 353
 
354
-// StdConfig.StdinPipe returns a WriteCloser which can be used to feed data
354
+// StreamConfig.StdinPipe returns a WriteCloser which can be used to feed data
355 355
 // to the standard input of the container's active process.
356 356
 // Container.StdoutPipe and Container.StderrPipe each return a ReadCloser
357 357
 // which can be used to retrieve the standard output (and error) generated
... ...
@@ -359,31 +359,31 @@ func (container *Container) Output() (output []byte, err error) {
359 359
 // copied and delivered to all StdoutPipe and StderrPipe consumers, using
360 360
 // a kind of "broadcaster".
361 361
 
362
-func (stdConfig *StdConfig) StdinPipe() (io.WriteCloser, error) {
363
-	return stdConfig.stdinPipe, nil
362
+func (streamConfig *StreamConfig) StdinPipe() (io.WriteCloser, error) {
363
+	return streamConfig.stdinPipe, nil
364 364
 }
365 365
 
366
-func (stdConfig *StdConfig) StdoutPipe() (io.ReadCloser, error) {
366
+func (streamConfig *StreamConfig) StdoutPipe() (io.ReadCloser, error) {
367 367
 	reader, writer := io.Pipe()
368
-	stdConfig.stdout.AddWriter(writer, "")
368
+	streamConfig.stdout.AddWriter(writer, "")
369 369
 	return utils.NewBufReader(reader), nil
370 370
 }
371 371
 
372
-func (stdConfig *StdConfig) StderrPipe() (io.ReadCloser, error) {
372
+func (streamConfig *StreamConfig) StderrPipe() (io.ReadCloser, error) {
373 373
 	reader, writer := io.Pipe()
374
-	stdConfig.stderr.AddWriter(writer, "")
374
+	streamConfig.stderr.AddWriter(writer, "")
375 375
 	return utils.NewBufReader(reader), nil
376 376
 }
377 377
 
378
-func (container *Container) StdoutLogPipe() io.ReadCloser {
378
+func (streamConfig *StreamConfig) StdoutLogPipe() io.ReadCloser {
379 379
 	reader, writer := io.Pipe()
380
-	container.StdConfig.stdout.AddWriter(writer, "stdout")
380
+	streamConfig.stdout.AddWriter(writer, "stdout")
381 381
 	return utils.NewBufReader(reader)
382 382
 }
383 383
 
384
-func (container *Container) StderrLogPipe() io.ReadCloser {
384
+func (streamConfig *StreamConfig) StderrLogPipe() io.ReadCloser {
385 385
 	reader, writer := io.Pipe()
386
-	container.StdConfig.stderr.AddWriter(writer, "stderr")
386
+	streamConfig.stderr.AddWriter(writer, "stderr")
387 387
 	return utils.NewBufReader(reader)
388 388
 }
389 389
 
... ...
@@ -1092,11 +1092,11 @@ func (container *Container) startLoggingToDisk() error {
1092 1092
 		return err
1093 1093
 	}
1094 1094
 
1095
-	if err := container.daemon.LogToDisk(container.StdConfig.stdout, pth, "stdout"); err != nil {
1095
+	if err := container.daemon.LogToDisk(container.stdout, pth, "stdout"); err != nil {
1096 1096
 		return err
1097 1097
 	}
1098 1098
 
1099
-	if err := container.daemon.LogToDisk(container.StdConfig.stderr, pth, "stderr"); err != nil {
1099
+	if err := container.daemon.LogToDisk(container.stderr, pth, "stderr"); err != nil {
1100 1100
 		return err
1101 1101
 	}
1102 1102
 
... ...
@@ -195,13 +195,13 @@ func (daemon *Daemon) register(container *Container, updateSuffixarray bool) err
195 195
 	container.daemon = daemon
196 196
 
197 197
 	// Attach to stdout and stderr
198
-	container.StdConfig.stderr = broadcastwriter.New()
199
-	container.StdConfig.stdout = broadcastwriter.New()
198
+	container.stderr = broadcastwriter.New()
199
+	container.stdout = broadcastwriter.New()
200 200
 	// Attach to stdin
201 201
 	if container.Config.OpenStdin {
202
-		container.StdConfig.stdin, container.StdConfig.stdinPipe = io.Pipe()
202
+		container.stdin, container.stdinPipe = io.Pipe()
203 203
 	} else {
204
-		container.StdConfig.stdinPipe = utils.NopWriteCloser(ioutil.Discard) // Silently drop stdin
204
+		container.stdinPipe = utils.NopWriteCloser(ioutil.Discard) // Silently drop stdin
205 205
 	}
206 206
 	// done
207 207
 	daemon.containers.Add(container.ID, container)
... ...
@@ -20,7 +20,7 @@ var (
20 20
 	ErrDriverNotFound          = errors.New("The requested docker init has not been found")
21 21
 )
22 22
 
23
-type StartCallback func(*ProcessConfig)
23
+type StartCallback func(*ProcessConfig, int)
24 24
 
25 25
 // Driver specific information based on
26 26
 // processes registered with the driver
... ...
@@ -84,14 +84,13 @@ type Mount struct {
84 84
 type ProcessConfig struct {
85 85
 	exec.Cmd `json:"-"`
86 86
 
87
-	Privileged   bool     `json:"privileged"`
88
-	User         string   `json:"user"`
89
-	Tty          bool     `json:"tty"`
90
-	Entrypoint   string   `json:"entrypoint"`
91
-	Arguments    []string `json:"arguments"`
92
-	Terminal     Terminal `json:"-"`             // standard or tty terminal
93
-	ContainerPid int      `json:"container_pid"` // the pid for the process inside a container
94
-	Console      string   `json:"-"`             // dev/console path
87
+	Privileged bool     `json:"privileged"`
88
+	User       string   `json:"user"`
89
+	Tty        bool     `json:"tty"`
90
+	Entrypoint string   `json:"entrypoint"`
91
+	Arguments  []string `json:"arguments"`
92
+	Terminal   Terminal `json:"-"` // standard or tty terminal
93
+	Console    string   `json:"-"` // dev/console path
95 94
 }
96 95
 
97 96
 // Process wrapps an os/exec.Cmd to add more metadata
... ...
@@ -109,12 +108,6 @@ type Command struct {
109 109
 	AutoCreatedDevices []*devices.Device   `json:"autocreated_devices"`
110 110
 	CapAdd             []string            `json:"cap_add"`
111 111
 	CapDrop            []string            `json:"cap_drop"`
112
-
113
-	ProcessConfig ProcessConfig `json:"process_config"` // Describes the init process of the container.
114
-}
115
-
116
-// Return the pid of the process
117
-// If the process is nil -1 will be returned
118
-func (processConfig *ProcessConfig) Pid() int {
119
-	return processConfig.ContainerPid
112
+	ContainerPid       int                 `json:"container_pid"`  // the pid for the process inside a container
113
+	ProcessConfig      ProcessConfig       `json:"process_config"` // Describes the init process of the container.
120 114
 }
... ...
@@ -184,10 +184,10 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
184 184
 		return -1, err
185 185
 	}
186 186
 
187
-	c.ProcessConfig.ContainerPid = pid
187
+	c.ContainerPid = pid
188 188
 
189 189
 	if startCallback != nil {
190
-		startCallback(&c.ProcessConfig)
190
+		startCallback(&c.ProcessConfig, pid)
191 191
 	}
192 192
 
193 193
 	<-waitLock
... ...
@@ -52,6 +52,7 @@ func TestLXCConfig(t *testing.T) {
52 52
 			Interface: nil,
53 53
 		},
54 54
 		AllowedDevices: make([]*devices.Device, 0),
55
+		ProcessConfig:  execdriver.ProcessConfig{},
55 56
 	}
56 57
 	p, err := driver.generateLXCConfig(command)
57 58
 	if err != nil {
... ...
@@ -121,8 +121,8 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
121 121
 		return &c.ProcessConfig.Cmd
122 122
 	}, func() {
123 123
 		if startCallback != nil {
124
-			c.ProcessConfig.ContainerPid = c.ProcessConfig.Process.Pid
125
-			startCallback(&c.ProcessConfig)
124
+			c.ContainerPid = c.ProcessConfig.Process.Pid
125
+			startCallback(&c.ProcessConfig, c.ContainerPid)
126 126
 		}
127 127
 	})
128 128
 }
... ...
@@ -128,7 +128,7 @@ func (m *containerMonitor) Start() error {
128 128
 			return err
129 129
 		}
130 130
 
131
-		pipes := execdriver.NewPipes(m.container.StdConfig.stdin, m.container.StdConfig.stdout, m.container.StdConfig.stderr, m.container.Config.OpenStdin)
131
+		pipes := execdriver.NewPipes(m.container.stdin, m.container.stdout, m.container.stderr, m.container.Config.OpenStdin)
132 132
 
133 133
 		m.container.LogEvent("start")
134 134
 
... ...
@@ -233,7 +233,7 @@ func (m *containerMonitor) shouldRestart(exitStatus int) bool {
233 233
 
234 234
 // callback ensures that the container's state is properly updated after we
235 235
 // received ack from the execution drivers
236
-func (m *containerMonitor) callback(processConfig *execdriver.ProcessConfig) {
236
+func (m *containerMonitor) callback(processConfig *execdriver.ProcessConfig, pid int) {
237 237
 	if processConfig.Tty {
238 238
 		// The callback is called after the process Start()
239 239
 		// so we are in the parent process. In TTY mode, stdin/out/err is the PtySlace
... ...
@@ -243,7 +243,7 @@ func (m *containerMonitor) callback(processConfig *execdriver.ProcessConfig) {
243 243
 		}
244 244
 	}
245 245
 
246
-	m.container.State.setRunning(processConfig.Pid())
246
+	m.container.State.setRunning(pid)
247 247
 
248 248
 	// signal that the process has started
249 249
 	// close channel only if not closed
... ...
@@ -269,16 +269,16 @@ func (m *containerMonitor) resetContainer(lock bool) {
269 269
 	}
270 270
 
271 271
 	if container.Config.OpenStdin {
272
-		if err := container.StdConfig.stdin.Close(); err != nil {
272
+		if err := container.stdin.Close(); err != nil {
273 273
 			log.Errorf("%s: Error close stdin: %s", container.ID, err)
274 274
 		}
275 275
 	}
276 276
 
277
-	if err := container.StdConfig.stdout.Clean(); err != nil {
277
+	if err := container.stdout.Clean(); err != nil {
278 278
 		log.Errorf("%s: Error close stdout: %s", container.ID, err)
279 279
 	}
280 280
 
281
-	if err := container.StdConfig.stderr.Clean(); err != nil {
281
+	if err := container.stderr.Clean(); err != nil {
282 282
 		log.Errorf("%s: Error close stderr: %s", container.ID, err)
283 283
 	}
284 284
 
... ...
@@ -290,7 +290,7 @@ func (m *containerMonitor) resetContainer(lock bool) {
290 290
 
291 291
 	// Re-create a brand new stdin pipe once the container exited
292 292
 	if container.Config.OpenStdin {
293
-		container.StdConfig.stdin, container.StdConfig.stdinPipe = io.Pipe()
293
+		container.stdin, container.stdinPipe = io.Pipe()
294 294
 	}
295 295
 
296 296
 	c := container.command.ProcessConfig.Cmd
... ...
@@ -467,7 +467,7 @@ func TestAttachDisconnect(t *testing.T) {
467 467
 	}
468 468
 
469 469
 	// Try to avoid the timeout in destroy. Best effort, don't check error
470
-	cStdin, _ := container.StdConfig.StdinPipe()
470
+	cStdin, _ := container.StdinPipe()
471 471
 	cStdin.Close()
472 472
 	container.State.WaitStop(-1 * time.Second)
473 473
 }
... ...
@@ -25,11 +25,11 @@ func TestRestartStdin(t *testing.T) {
25 25
 	}
26 26
 	defer daemon.Destroy(container)
27 27
 
28
-	stdin, err := container.StdConfig.StdinPipe()
28
+	stdin, err := container.StdinPipe()
29 29
 	if err != nil {
30 30
 		t.Fatal(err)
31 31
 	}
32
-	stdout, err := container.StdConfig.StdoutPipe()
32
+	stdout, err := container.StdoutPipe()
33 33
 	if err != nil {
34 34
 		t.Fatal(err)
35 35
 	}
... ...
@@ -55,11 +55,11 @@ func TestRestartStdin(t *testing.T) {
55 55
 	}
56 56
 
57 57
 	// Restart and try again
58
-	stdin, err = container.StdConfig.StdinPipe()
58
+	stdin, err = container.StdinPipe()
59 59
 	if err != nil {
60 60
 		t.Fatal(err)
61 61
 	}
62
-	stdout, err = container.StdConfig.StdoutPipe()
62
+	stdout, err = container.StdoutPipe()
63 63
 	if err != nil {
64 64
 		t.Fatal(err)
65 65
 	}
... ...
@@ -101,11 +101,11 @@ func TestStdin(t *testing.T) {
101 101
 	}
102 102
 	defer daemon.Destroy(container)
103 103
 
104
-	stdin, err := container.StdConfig.StdinPipe()
104
+	stdin, err := container.StdinPipe()
105 105
 	if err != nil {
106 106
 		t.Fatal(err)
107 107
 	}
108
-	stdout, err := container.StdConfig.StdoutPipe()
108
+	stdout, err := container.StdoutPipe()
109 109
 	if err != nil {
110 110
 		t.Fatal(err)
111 111
 	}
... ...
@@ -146,11 +146,11 @@ func TestTty(t *testing.T) {
146 146
 	}
147 147
 	defer daemon.Destroy(container)
148 148
 
149
-	stdin, err := container.StdConfig.StdinPipe()
149
+	stdin, err := container.StdinPipe()
150 150
 	if err != nil {
151 151
 		t.Fatal(err)
152 152
 	}
153
-	stdout, err := container.StdConfig.StdoutPipe()
153
+	stdout, err := container.StdoutPipe()
154 154
 	if err != nil {
155 155
 		t.Fatal(err)
156 156
 	}
... ...
@@ -611,7 +611,7 @@ func TestRestore(t *testing.T) {
611 611
 	}
612 612
 
613 613
 	// Simulate a crash/manual quit of dockerd: process dies, states stays 'Running'
614
-	cStdin, _ := container2.StdConfig.StdinPipe()
614
+	cStdin, _ := container2.StdinPipe()
615 615
 	cStdin.Close()
616 616
 	if _, err := container2.State.WaitStop(2 * time.Second); err != nil {
617 617
 		t.Fatal(err)
... ...
@@ -84,11 +84,11 @@ func containerFileExists(eng *engine.Engine, id, dir string, t log.Fataler) bool
84 84
 
85 85
 func containerAttach(eng *engine.Engine, id string, t log.Fataler) (io.WriteCloser, io.ReadCloser) {
86 86
 	c := getContainer(eng, id, t)
87
-	i, err := c.StdConfig.StdinPipe()
87
+	i, err := c.StdinPipe()
88 88
 	if err != nil {
89 89
 		t.Fatal(err)
90 90
 	}
91
-	o, err := c.StdConfig.StdoutPipe()
91
+	o, err := c.StdoutPipe()
92 92
 	if err != nil {
93 93
 		t.Fatal(err)
94 94
 	}
... ...
@@ -289,7 +289,7 @@ func runContainer(eng *engine.Engine, r *daemon.Daemon, args []string, t *testin
289 289
 		return "", err
290 290
 	}
291 291
 	defer r.Destroy(container)
292
-	stdout, err := container.StdConfig.StdoutPipe()
292
+	stdout, err := container.StdoutPipe()
293 293
 	if err != nil {
294 294
 		return "", err
295 295
 	}