Skip to content

Commit 0463ad1

Browse files
committed
libpod: fix a confusing error message from 'podman system reset' on FreeBSD
This was discovered by a user while testing Podman on FreeBSD (oci-playground/freebsd-podman-testing/issues/17). The error message didn't stop 'podman system reset' from working and this commit simply suppressses the error on FreeBSD. Signed-off-by: Doug Rabson <dfr@rabson.org>
1 parent 0935710 commit 0463ad1

4 files changed

+96
-85
lines changed

libpod/runtime_migrate.go

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//go:build !remote
2+
3+
package libpod
4+
5+
import (
6+
"fmt"
7+
"path/filepath"
8+
9+
"github.com/containers/podman/v5/libpod/define"
10+
"github.com/sirupsen/logrus"
11+
)
12+
13+
// Migrate stops the rootless pause process and performs any necessary database
14+
// migrations that are required. It can also migrate all containers to a new OCI
15+
// runtime, if requested.
16+
func (r *Runtime) Migrate(newRuntime string) error {
17+
// Acquire the alive lock and hold it.
18+
// Ensures that we don't let other Podman commands run while we are
19+
// rewriting things in the DB.
20+
aliveLock, err := r.getRuntimeAliveLock()
21+
if err != nil {
22+
return fmt.Errorf("retrieving alive lock: %w", err)
23+
}
24+
aliveLock.Lock()
25+
defer aliveLock.Unlock()
26+
27+
if !r.valid {
28+
return define.ErrRuntimeStopped
29+
}
30+
31+
runningContainers, err := r.GetRunningContainers()
32+
if err != nil {
33+
return err
34+
}
35+
36+
allCtrs, err := r.state.AllContainers(false)
37+
if err != nil {
38+
return err
39+
}
40+
41+
logrus.Infof("Stopping all containers")
42+
for _, ctr := range runningContainers {
43+
fmt.Printf("stopped %s\n", ctr.ID())
44+
if err := ctr.Stop(); err != nil {
45+
return fmt.Errorf("cannot stop container %s: %w", ctr.ID(), err)
46+
}
47+
}
48+
49+
// Did the user request a new runtime?
50+
runtimeChangeRequested := newRuntime != ""
51+
var requestedRuntime OCIRuntime
52+
if runtimeChangeRequested {
53+
runtime, exists := r.ociRuntimes[newRuntime]
54+
if !exists {
55+
return fmt.Errorf("change to runtime %q requested but no such runtime is defined: %w", newRuntime, define.ErrInvalidArg)
56+
}
57+
requestedRuntime = runtime
58+
}
59+
60+
for _, ctr := range allCtrs {
61+
needsWrite := false
62+
63+
// Reset pause process location
64+
oldLocation := filepath.Join(ctr.state.RunDir, "conmon.pid")
65+
if ctr.config.ConmonPidFile == oldLocation {
66+
logrus.Infof("Changing conmon PID file for %s", ctr.ID())
67+
ctr.config.ConmonPidFile = filepath.Join(ctr.config.StaticDir, "conmon.pid")
68+
needsWrite = true
69+
}
70+
71+
// Reset runtime
72+
if runtimeChangeRequested && ctr.config.OCIRuntime != newRuntime {
73+
logrus.Infof("Resetting container %s runtime to runtime %s", ctr.ID(), newRuntime)
74+
ctr.config.OCIRuntime = newRuntime
75+
ctr.ociRuntime = requestedRuntime
76+
77+
needsWrite = true
78+
}
79+
80+
if needsWrite {
81+
if err := r.state.RewriteContainerConfig(ctr, ctr.config); err != nil {
82+
return fmt.Errorf("rewriting config for container %s: %w", ctr.ID(), err)
83+
}
84+
}
85+
}
86+
87+
return r.stopPauseProcess()
88+
}

libpod/runtime_migrate_freebsd.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build !remote
2+
3+
package libpod
4+
5+
func (r *Runtime) stopPauseProcess() error {
6+
return nil
7+
}

libpod/runtime_migrate_linux.go

-80
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ package libpod
55
import (
66
"fmt"
77
"os"
8-
"path/filepath"
98
"strconv"
109
"syscall"
1110

12-
"github.com/containers/podman/v5/libpod/define"
1311
"github.com/containers/podman/v5/pkg/rootless"
1412
"github.com/containers/podman/v5/pkg/util"
15-
"github.com/sirupsen/logrus"
1613
)
1714

1815
func (r *Runtime) stopPauseProcess() error {
@@ -41,80 +38,3 @@ func (r *Runtime) stopPauseProcess() error {
4138
}
4239
return nil
4340
}
44-
45-
// Migrate stops the rootless pause process and performs any necessary database
46-
// migrations that are required. It can also migrate all containers to a new OCI
47-
// runtime, if requested.
48-
func (r *Runtime) Migrate(newRuntime string) error {
49-
// Acquire the alive lock and hold it.
50-
// Ensures that we don't let other Podman commands run while we are
51-
// rewriting things in the DB.
52-
aliveLock, err := r.getRuntimeAliveLock()
53-
if err != nil {
54-
return fmt.Errorf("retrieving alive lock: %w", err)
55-
}
56-
aliveLock.Lock()
57-
defer aliveLock.Unlock()
58-
59-
if !r.valid {
60-
return define.ErrRuntimeStopped
61-
}
62-
63-
runningContainers, err := r.GetRunningContainers()
64-
if err != nil {
65-
return err
66-
}
67-
68-
allCtrs, err := r.state.AllContainers(false)
69-
if err != nil {
70-
return err
71-
}
72-
73-
logrus.Infof("Stopping all containers")
74-
for _, ctr := range runningContainers {
75-
fmt.Printf("stopped %s\n", ctr.ID())
76-
if err := ctr.Stop(); err != nil {
77-
return fmt.Errorf("cannot stop container %s: %w", ctr.ID(), err)
78-
}
79-
}
80-
81-
// Did the user request a new runtime?
82-
runtimeChangeRequested := newRuntime != ""
83-
var requestedRuntime OCIRuntime
84-
if runtimeChangeRequested {
85-
runtime, exists := r.ociRuntimes[newRuntime]
86-
if !exists {
87-
return fmt.Errorf("change to runtime %q requested but no such runtime is defined: %w", newRuntime, define.ErrInvalidArg)
88-
}
89-
requestedRuntime = runtime
90-
}
91-
92-
for _, ctr := range allCtrs {
93-
needsWrite := false
94-
95-
// Reset pause process location
96-
oldLocation := filepath.Join(ctr.state.RunDir, "conmon.pid")
97-
if ctr.config.ConmonPidFile == oldLocation {
98-
logrus.Infof("Changing conmon PID file for %s", ctr.ID())
99-
ctr.config.ConmonPidFile = filepath.Join(ctr.config.StaticDir, "conmon.pid")
100-
needsWrite = true
101-
}
102-
103-
// Reset runtime
104-
if runtimeChangeRequested && ctr.config.OCIRuntime != newRuntime {
105-
logrus.Infof("Resetting container %s runtime to runtime %s", ctr.ID(), newRuntime)
106-
ctr.config.OCIRuntime = newRuntime
107-
ctr.ociRuntime = requestedRuntime
108-
109-
needsWrite = true
110-
}
111-
112-
if needsWrite {
113-
if err := r.state.RewriteContainerConfig(ctr, ctr.config); err != nil {
114-
return fmt.Errorf("rewriting config for container %s: %w", ctr.ID(), err)
115-
}
116-
}
117-
}
118-
119-
return r.stopPauseProcess()
120-
}

libpod/runtime_migrate_unsupported.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build !remote && !linux
1+
//go:build !remote && !linux && !freebsd
22

33
package libpod
44

@@ -9,7 +9,3 @@ import (
99
func (r *Runtime) stopPauseProcess() error {
1010
return errors.New("not implemented (*Runtime) stopPauseProcess")
1111
}
12-
13-
func (r *Runtime) Migrate(newRuntime string) error {
14-
return errors.New("not implemented (*Runtime) migrate")
15-
}

0 commit comments

Comments
 (0)