Browse code

daemon: rename all receivers to "daemon"

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/08/09 20:19:49
Showing 6 changed files
... ...
@@ -11,7 +11,7 @@ import (
11 11
 	"golang.org/x/sys/unix"
12 12
 )
13 13
 
14
-func (d *Daemon) setupDumpStackTrap(root string) {
14
+func (daemon *Daemon) setupDumpStackTrap(root string) {
15 15
 	c := make(chan os.Signal, 1)
16 16
 	signal.Notify(c, unix.SIGUSR1)
17 17
 	go func() {
... ...
@@ -2,6 +2,6 @@
2 2
 
3 3
 package daemon // import "github.com/docker/docker/daemon"
4 4
 
5
-func (d *Daemon) setupDumpStackTrap(_ string) {
5
+func (daemon *Daemon) setupDumpStackTrap(_ string) {
6 6
 	return
7 7
 }
... ...
@@ -10,7 +10,7 @@ import (
10 10
 	"golang.org/x/sys/windows"
11 11
 )
12 12
 
13
-func (d *Daemon) setupDumpStackTrap(root string) {
13
+func (daemon *Daemon) setupDumpStackTrap(root string) {
14 14
 	// Windows does not support signals like *nix systems. So instead of
15 15
 	// trapping on SIGUSR1 to dump stacks, we wait on a Win32 event to be
16 16
 	// signaled. ACL'd to builtin administrators and local system
... ...
@@ -25,17 +25,17 @@ import (
25 25
 // Seconds to wait after sending TERM before trying KILL
26 26
 const termProcessTimeout = 10 * time.Second
27 27
 
28
-func (d *Daemon) registerExecCommand(container *container.Container, config *exec.Config) {
28
+func (daemon *Daemon) registerExecCommand(container *container.Container, config *exec.Config) {
29 29
 	// Storing execs in container in order to kill them gracefully whenever the container is stopped or removed.
30 30
 	container.ExecCommands.Add(config.ID, config)
31 31
 	// Storing execs in daemon for easy access via Engine API.
32
-	d.execCommands.Add(config.ID, config)
32
+	daemon.execCommands.Add(config.ID, config)
33 33
 }
34 34
 
35 35
 // ExecExists looks up the exec instance and returns a bool if it exists or not.
36 36
 // It will also return the error produced by `getConfig`
37
-func (d *Daemon) ExecExists(name string) (bool, error) {
38
-	if _, err := d.getExecConfig(name); err != nil {
37
+func (daemon *Daemon) ExecExists(name string) (bool, error) {
38
+	if _, err := daemon.getExecConfig(name); err != nil {
39 39
 		return false, err
40 40
 	}
41 41
 	return true, nil
... ...
@@ -43,8 +43,8 @@ func (d *Daemon) ExecExists(name string) (bool, error) {
43 43
 
44 44
 // getExecConfig looks up the exec instance by name. If the container associated
45 45
 // with the exec instance is stopped or paused, it will return an error.
46
-func (d *Daemon) getExecConfig(name string) (*exec.Config, error) {
47
-	ec := d.execCommands.Get(name)
46
+func (daemon *Daemon) getExecConfig(name string) (*exec.Config, error) {
47
+	ec := daemon.execCommands.Get(name)
48 48
 	if ec == nil {
49 49
 		return nil, errExecNotFound(name)
50 50
 	}
... ...
@@ -54,7 +54,7 @@ func (d *Daemon) getExecConfig(name string) (*exec.Config, error) {
54 54
 	// saying the container isn't running, we should return a 404 so that
55 55
 	// the user sees the same error now that they will after the
56 56
 	// 5 minute clean-up loop is run which erases old/dead execs.
57
-	container := d.containers.Get(ec.ContainerID)
57
+	container := daemon.containers.Get(ec.ContainerID)
58 58
 	if container == nil {
59 59
 		return nil, containerNotFound(name)
60 60
 	}
... ...
@@ -70,13 +70,13 @@ func (d *Daemon) getExecConfig(name string) (*exec.Config, error) {
70 70
 	return ec, nil
71 71
 }
72 72
 
73
-func (d *Daemon) unregisterExecCommand(container *container.Container, execConfig *exec.Config) {
73
+func (daemon *Daemon) unregisterExecCommand(container *container.Container, execConfig *exec.Config) {
74 74
 	container.ExecCommands.Delete(execConfig.ID, execConfig.Pid)
75
-	d.execCommands.Delete(execConfig.ID, execConfig.Pid)
75
+	daemon.execCommands.Delete(execConfig.ID, execConfig.Pid)
76 76
 }
77 77
 
78
-func (d *Daemon) getActiveContainer(name string) (*container.Container, error) {
79
-	container, err := d.GetContainer(name)
78
+func (daemon *Daemon) getActiveContainer(name string) (*container.Container, error) {
79
+	container, err := daemon.GetContainer(name)
80 80
 	if err != nil {
81 81
 		return nil, err
82 82
 	}
... ...
@@ -94,14 +94,14 @@ func (d *Daemon) getActiveContainer(name string) (*container.Container, error) {
94 94
 }
95 95
 
96 96
 // ContainerExecCreate sets up an exec in a running container.
97
-func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (string, error) {
98
-	cntr, err := d.getActiveContainer(name)
97
+func (daemon *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (string, error) {
98
+	cntr, err := daemon.getActiveContainer(name)
99 99
 	if err != nil {
100 100
 		return "", err
101 101
 	}
102 102
 
103 103
 	cmd := strslice.StrSlice(config.Cmd)
104
-	entrypoint, args := d.getEntrypointAndArgs(strslice.StrSlice{}, cmd)
104
+	entrypoint, args := daemon.getEntrypointAndArgs(strslice.StrSlice{}, cmd)
105 105
 
106 106
 	keys := []byte{}
107 107
 	if config.DetachKeys != "" {
... ...
@@ -125,7 +125,7 @@ func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (str
125 125
 	execConfig.User = config.User
126 126
 	execConfig.WorkingDir = config.WorkingDir
127 127
 
128
-	linkedEnv, err := d.setupLinkedContainers(cntr)
128
+	linkedEnv, err := daemon.setupLinkedContainers(cntr)
129 129
 	if err != nil {
130 130
 		return "", err
131 131
 	}
... ...
@@ -137,12 +137,12 @@ func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (str
137 137
 		execConfig.WorkingDir = cntr.Config.WorkingDir
138 138
 	}
139 139
 
140
-	d.registerExecCommand(cntr, execConfig)
140
+	daemon.registerExecCommand(cntr, execConfig)
141 141
 
142 142
 	attributes := map[string]string{
143 143
 		"execID": execConfig.ID,
144 144
 	}
145
-	d.LogContainerEventWithAttributes(cntr, "exec_create: "+execConfig.Entrypoint+" "+strings.Join(execConfig.Args, " "), attributes)
145
+	daemon.LogContainerEventWithAttributes(cntr, "exec_create: "+execConfig.Entrypoint+" "+strings.Join(execConfig.Args, " "), attributes)
146 146
 
147 147
 	return execConfig.ID, nil
148 148
 }
... ...
@@ -150,13 +150,13 @@ func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (str
150 150
 // ContainerExecStart starts a previously set up exec instance. The
151 151
 // std streams are set up.
152 152
 // If ctx is cancelled, the process is terminated.
153
-func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.Reader, stdout io.Writer, stderr io.Writer) (err error) {
153
+func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.Reader, stdout io.Writer, stderr io.Writer) (err error) {
154 154
 	var (
155 155
 		cStdin           io.ReadCloser
156 156
 		cStdout, cStderr io.Writer
157 157
 	)
158 158
 
159
-	ec, err := d.getExecConfig(name)
159
+	ec, err := daemon.getExecConfig(name)
160 160
 	if err != nil {
161 161
 		return errExecNotFound(name)
162 162
 	}
... ...
@@ -175,12 +175,12 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R
175 175
 	ec.Running = true
176 176
 	ec.Unlock()
177 177
 
178
-	c := d.containers.Get(ec.ContainerID)
178
+	c := daemon.containers.Get(ec.ContainerID)
179 179
 	logrus.Debugf("starting exec command %s in container %s", ec.ID, c.ID)
180 180
 	attributes := map[string]string{
181 181
 		"execID": ec.ID,
182 182
 	}
183
-	d.LogContainerEventWithAttributes(c, "exec_start: "+ec.Entrypoint+" "+strings.Join(ec.Args, " "), attributes)
183
+	daemon.LogContainerEventWithAttributes(c, "exec_start: "+ec.Entrypoint+" "+strings.Join(ec.Args, " "), attributes)
184 184
 
185 185
 	defer func() {
186 186
 		if err != nil {
... ...
@@ -220,7 +220,7 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R
220 220
 
221 221
 	p := &specs.Process{}
222 222
 	if runtime.GOOS != "windows" {
223
-		container, err := d.containerdCli.LoadContainer(ctx, ec.ContainerID)
223
+		container, err := daemon.containerdCli.LoadContainer(ctx, ec.ContainerID)
224 224
 		if err != nil {
225 225
 			return err
226 226
 		}
... ...
@@ -239,7 +239,7 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R
239 239
 		p.Cwd = "/"
240 240
 	}
241 241
 
242
-	if err := d.execSetPlatformOpt(c, ec, p); err != nil {
242
+	if err := daemon.execSetPlatformOpt(c, ec, p); err != nil {
243 243
 		return err
244 244
 	}
245 245
 
... ...
@@ -260,7 +260,7 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R
260 260
 	// Synchronize with libcontainerd event loop
261 261
 	ec.Lock()
262 262
 	c.ExecCommands.Lock()
263
-	systemPid, err := d.containerd.Exec(ctx, c.ID, ec.ID, p, cStdin != nil, ec.InitializeStdio)
263
+	systemPid, err := daemon.containerd.Exec(ctx, c.ID, ec.ID, p, cStdin != nil, ec.InitializeStdio)
264 264
 	// the exec context should be ready, or error happened.
265 265
 	// close the chan to notify readiness
266 266
 	close(ec.Started)
... ...
@@ -276,7 +276,7 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R
276 276
 	select {
277 277
 	case <-ctx.Done():
278 278
 		logrus.Debugf("Sending TERM signal to process %v in container %v", name, c.ID)
279
-		d.containerd.SignalProcess(ctx, c.ID, name, int(signal.SignalMap["TERM"]))
279
+		daemon.containerd.SignalProcess(ctx, c.ID, name, int(signal.SignalMap["TERM"]))
280 280
 
281 281
 		timeout := time.NewTimer(termProcessTimeout)
282 282
 		defer timeout.Stop()
... ...
@@ -284,7 +284,7 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R
284 284
 		select {
285 285
 		case <-timeout.C:
286 286
 			logrus.Infof("Container %v, process %v failed to exit within %v of signal TERM - using the force", c.ID, name, termProcessTimeout)
287
-			d.containerd.SignalProcess(ctx, c.ID, name, int(signal.SignalMap["KILL"]))
287
+			daemon.containerd.SignalProcess(ctx, c.ID, name, int(signal.SignalMap["KILL"]))
288 288
 		case <-attachErr:
289 289
 			// TERM signal worked
290 290
 		}
... ...
@@ -297,7 +297,7 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R
297 297
 			attributes := map[string]string{
298 298
 				"execID": ec.ID,
299 299
 			}
300
-			d.LogContainerEventWithAttributes(c, "exec_detach", attributes)
300
+			daemon.LogContainerEventWithAttributes(c, "exec_detach", attributes)
301 301
 		}
302 302
 	}
303 303
 	return nil
... ...
@@ -305,16 +305,16 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R
305 305
 
306 306
 // execCommandGC runs a ticker to clean up the daemon references
307 307
 // of exec configs that are no longer part of the container.
308
-func (d *Daemon) execCommandGC() {
308
+func (daemon *Daemon) execCommandGC() {
309 309
 	for range time.Tick(5 * time.Minute) {
310 310
 		var (
311 311
 			cleaned          int
312
-			liveExecCommands = d.containerExecIds()
312
+			liveExecCommands = daemon.containerExecIds()
313 313
 		)
314
-		for id, config := range d.execCommands.Commands() {
314
+		for id, config := range daemon.execCommands.Commands() {
315 315
 			if config.CanRemove {
316 316
 				cleaned++
317
-				d.execCommands.Delete(id, config.Pid)
317
+				daemon.execCommands.Delete(id, config.Pid)
318 318
 			} else {
319 319
 				if _, exists := liveExecCommands[id]; !exists {
320 320
 					config.CanRemove = true
... ...
@@ -329,9 +329,9 @@ func (d *Daemon) execCommandGC() {
329 329
 
330 330
 // containerExecIds returns a list of all the current exec ids that are in use
331 331
 // and running inside a container.
332
-func (d *Daemon) containerExecIds() map[string]struct{} {
332
+func (daemon *Daemon) containerExecIds() map[string]struct{} {
333 333
 	ids := map[string]struct{}{}
334
-	for _, c := range d.containers.List() {
334
+	for _, c := range daemon.containers.List() {
335 335
 		for _, id := range c.ExecCommands.List() {
336 336
 			ids[id] = struct{}{}
337 337
 		}
... ...
@@ -273,7 +273,7 @@ func getProbe(c *container.Container) probe {
273 273
 // Ensure the health-check monitor is running or not, depending on the current
274 274
 // state of the container.
275 275
 // Called from monitor.go, with c locked.
276
-func (d *Daemon) updateHealthMonitor(c *container.Container) {
276
+func (daemon *Daemon) updateHealthMonitor(c *container.Container) {
277 277
 	h := c.State.Health
278 278
 	if h == nil {
279 279
 		return // No healthcheck configured
... ...
@@ -283,7 +283,7 @@ func (d *Daemon) updateHealthMonitor(c *container.Container) {
283 283
 	wantRunning := c.Running && !c.Paused && probe != nil
284 284
 	if wantRunning {
285 285
 		if stop := h.OpenMonitorChannel(); stop != nil {
286
-			go monitor(d, c, stop, probe)
286
+			go monitor(daemon, c, stop, probe)
287 287
 		}
288 288
 	} else {
289 289
 		h.CloseMonitorChannel()
... ...
@@ -294,14 +294,14 @@ func (d *Daemon) updateHealthMonitor(c *container.Container) {
294 294
 // initHealthMonitor is called from monitor.go and we should never be running
295 295
 // two instances at once.
296 296
 // Called with c locked.
297
-func (d *Daemon) initHealthMonitor(c *container.Container) {
297
+func (daemon *Daemon) initHealthMonitor(c *container.Container) {
298 298
 	// If no healthcheck is setup then don't init the monitor
299 299
 	if getProbe(c) == nil {
300 300
 		return
301 301
 	}
302 302
 
303 303
 	// This is needed in case we're auto-restarting
304
-	d.stopHealthchecks(c)
304
+	daemon.stopHealthchecks(c)
305 305
 
306 306
 	if h := c.State.Health; h != nil {
307 307
 		h.SetStatus(types.Starting)
... ...
@@ -312,12 +312,12 @@ func (d *Daemon) initHealthMonitor(c *container.Container) {
312 312
 		c.State.Health = h
313 313
 	}
314 314
 
315
-	d.updateHealthMonitor(c)
315
+	daemon.updateHealthMonitor(c)
316 316
 }
317 317
 
318 318
 // Called when the container is being stopped (whether because the health check is
319 319
 // failing or for any other reason).
320
-func (d *Daemon) stopHealthchecks(c *container.Container) {
320
+func (daemon *Daemon) stopHealthchecks(c *container.Container) {
321 321
 	h := c.State.Health
322 322
 	if h != nil {
323 323
 		h.CloseMonitorChannel()
... ...
@@ -115,8 +115,8 @@ func (ctr *stateCounter) Collect(ch chan<- prometheus.Metric) {
115 115
 	ch <- prometheus.MustNewConstMetric(ctr.desc, prometheus.GaugeValue, float64(stopped), "stopped")
116 116
 }
117 117
 
118
-func (d *Daemon) cleanupMetricsPlugins() {
119
-	ls := d.PluginStore.GetAllManagedPluginsByCap(metricsPluginType)
118
+func (daemon *Daemon) cleanupMetricsPlugins() {
119
+	ls := daemon.PluginStore.GetAllManagedPluginsByCap(metricsPluginType)
120 120
 	var wg sync.WaitGroup
121 121
 	wg.Add(len(ls))
122 122
 
... ...
@@ -137,8 +137,8 @@ func (d *Daemon) cleanupMetricsPlugins() {
137 137
 	}
138 138
 	wg.Wait()
139 139
 
140
-	if d.metricsPluginListener != nil {
141
-		d.metricsPluginListener.Close()
140
+	if daemon.metricsPluginListener != nil {
141
+		daemon.metricsPluginListener.Close()
142 142
 	}
143 143
 }
144 144