Skip to content

Commit c3f3dd3

Browse files
committed
use return error handling in SetupRootless
There is no good reason to use logrus and os.Exit() here, other parts of this function already return the error so do the same. The main podman process will exit then with the normal formatted error message. And also log an error about the last return which should never happen as we should have exited above if the re-exec worked or errored out. Signed-off-by: Paul Holzinger <[email protected]>
1 parent 90a03ca commit c3f3dd3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pkg/domain/infra/abi/system_linux.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ func (ic *ContainerEngine) SetupRootless(_ context.Context, noMoveProcess bool,
5959
}
6060
}
6161
}
62+
63+
// return early as we are already re-exec or root here so no need to join the rootless userns.
6264
return nil
6365
}
6466

@@ -81,8 +83,7 @@ func (ic *ContainerEngine) SetupRootless(_ context.Context, noMoveProcess bool,
8183
// if there is no pid file, try to join existing containers, and create a pause process.
8284
ctrs, err := ic.Libpod.GetRunningContainers()
8385
if err != nil {
84-
logrus.Error(err.Error())
85-
os.Exit(1)
86+
return err
8687
}
8788

8889
paths := []string{}
@@ -99,11 +100,12 @@ func (ic *ContainerEngine) SetupRootless(_ context.Context, noMoveProcess bool,
99100
}
100101
}
101102
if err != nil {
102-
logrus.Error(fmt.Errorf("invalid internal status, try resetting the pause process with %q: %w", os.Args[0]+" system migrate", err))
103-
os.Exit(1)
103+
return fmt.Errorf("invalid internal status, try resetting the pause process with %q: %w", os.Args[0]+" system migrate", err)
104104
}
105105
if became {
106106
os.Exit(ret)
107107
}
108+
109+
logrus.Error("Internal error, failed to re-exec podman into user namespace without error. This should never happen, if you see this please report a bug")
108110
return nil
109111
}

0 commit comments

Comments
 (0)