Browse code

Merge pull request #12423 from crosbymichael/idkbutitworks

Ensure state is destroyed on daemont restart

Jessie Frazelle authored on 2015/04/16 13:19:38
Showing 2 changed files
... ...
@@ -271,19 +271,8 @@ func (daemon *Daemon) register(container *Container, updateSuffixarray bool) err
271 271
 		if err := container.ToDisk(); err != nil {
272 272
 			logrus.Debugf("saving stopped state to disk %s", err)
273 273
 		}
274
-
275
-		info := daemon.execDriver.Info(container.ID)
276
-		if !info.IsRunning() {
277
-			logrus.Debugf("Container %s was supposed to be running but is not.", container.ID)
278
-
279
-			logrus.Debug("Marking as stopped")
280
-
281
-			container.SetStopped(&execdriver.ExitStatus{ExitCode: -127})
282
-			if err := container.ToDisk(); err != nil {
283
-				return err
284
-			}
285
-		}
286 274
 	}
275
+
287 276
 	return nil
288 277
 }
289 278
 
... ...
@@ -268,29 +268,25 @@ func (d *driver) Unpause(c *execdriver.Command) error {
268 268
 
269 269
 func (d *driver) Terminate(c *execdriver.Command) error {
270 270
 	defer d.cleanContainer(c.ID)
271
-	// lets check the start time for the process
272
-	active := d.activeContainers[c.ID]
273
-	if active == nil {
274
-		return fmt.Errorf("active container for %s does not exist", c.ID)
271
+	container, err := d.factory.Load(c.ID)
272
+	if err != nil {
273
+		return err
275 274
 	}
276
-	state, err := active.State()
275
+	defer container.Destroy()
276
+	state, err := container.State()
277 277
 	if err != nil {
278 278
 		return err
279 279
 	}
280 280
 	pid := state.InitProcessPid
281
-
282 281
 	currentStartTime, err := system.GetProcessStartTime(pid)
283 282
 	if err != nil {
284 283
 		return err
285 284
 	}
286
-
287 285
 	if state.InitProcessStartTime == currentStartTime {
288 286
 		err = syscall.Kill(pid, 9)
289 287
 		syscall.Wait4(pid, nil, 0, nil)
290 288
 	}
291
-
292 289
 	return err
293
-
294 290
 }
295 291
 
296 292
 func (d *driver) Info(id string) execdriver.Info {