Browse code

Add backwards READ compatibility for the old libcontainer API

Docker-DCO-1.1-Signed-off-by: Tibor Vass <teabee89@gmail.com> (github: tiborvass)

Tibor Vass authored on 2014/07/02 08:14:22
Showing 2 changed files
... ...
@@ -173,12 +173,21 @@ func (d *driver) Terminate(p *execdriver.Command) error {
173 173
 	// lets check the start time for the process
174 174
 	state, err := libcontainer.GetState(filepath.Join(d.root, p.ID))
175 175
 	if err != nil {
176
-		// if we don't have the data on disk then we can assume the process is gone
177
-		// because this is only removed after we know the process has stopped
178
-		if os.IsNotExist(err) {
179
-			return nil
176
+		if !os.IsNotExist(err) {
177
+			return err
180 178
 		}
181
-		return err
179
+		// TODO: Remove this part for version 1.2.0
180
+		// This is added only to ensure smooth upgrades from pre 1.1.0 to 1.1.0
181
+		data, err := ioutil.ReadAll(filepath.Join(d.root, p.ID, "start"))
182
+		if err != nil {
183
+			// if we don't have the data on disk then we can assume the process is gone
184
+			// because this is only removed after we know the process has stopped
185
+			if os.IsNotExist(err) {
186
+				return nil
187
+			}
188
+			return err
189
+		}
190
+		state.InitStartTime = string(data)
182 191
 	}
183 192
 
184 193
 	currentStartTime, err := system.GetProcessStartTime(p.Process.Pid)
... ...
@@ -1,6 +1,7 @@
1 1
 package native
2 2
 
3 3
 import (
4
+	"os"
4 5
 	"path/filepath"
5 6
 
6 7
 	"github.com/docker/libcontainer"
... ...
@@ -18,5 +19,10 @@ func (i *info) IsRunning() bool {
18 18
 	if _, err := libcontainer.GetState(filepath.Join(i.driver.root, i.ID)); err == nil {
19 19
 		return true
20 20
 	}
21
+	// TODO: Remove this part for version 1.2.0
22
+	// This is added only to ensure smooth upgrades from pre 1.1.0 to 1.1.0
23
+	if _, err := os.Stat(filepath.Join(i.driver.root, i.ID, "pid")); err == nil {
24
+		return true
25
+	}
21 26
 	return false
22 27
 }