rootless: fix segfault on refresh if there are containers

create immediately a namespace if we need a refresh.  This is
necessary to access the rootless storage.

Closes: https://github.com/containers/libpod/issues/2894

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2019-04-10 23:12:30 +02:00
parent 6cd6eb6768
commit 09532c8cc0
No known key found for this signature in database
GPG Key ID: E4730F97F60286ED
1 changed files with 14 additions and 0 deletions

View File

@ -870,6 +870,20 @@ func makeRuntime(runtime *Runtime) (err error) {
_, err = os.Stat(runtimeAliveFile)
if err != nil {
// If we need to refresh, then it is safe to assume there are
// no containers running. Create immediately a namespace, as
// we will need to access the storage.
if os.Geteuid() != 0 {
aliveLock.Unlock()
became, ret, err := rootless.BecomeRootInUserNS()
if err != nil {
return err
}
if became {
os.Exit(ret)
}
}
// If the file doesn't exist, we need to refresh the state
// This will trigger on first use as well, but refreshing an
// empty state only creates a single file