From ed9c3e6f466dfb6d2e79802060fabd5f4b66f78e Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 27 Aug 2020 12:10:21 +0200 Subject: [PATCH] state: fix race condition when reading cgroup by the time crun attempts to read from the cgroup, systemd might have already cleaned it up. When using systemd, on ENOENT state reports the container as "stopped" instead of an error. Closes: https://github.com/containers/podman/issues/7148 Signed-off-by: Giuseppe Scrivano --- src/libcrun/container.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libcrun/container.c b/src/libcrun/container.c index 9c3f279adc..b4ffa7b3ed 100644 --- a/src/libcrun/container.c +++ b/src/libcrun/container.c @@ -2194,7 +2194,17 @@ libcrun_get_container_state_string (const char *id, libcrun_container_status_t * ret = libcrun_cgroup_is_container_paused (status->cgroup_path, cgroup_mode, &paused, err); if (UNLIKELY (ret < 0)) - return ret; + { + /* The cgroup might have been cleaned up by systemd by the time we try to read it, so ignore ENOENT. */ + if (status->systemd_cgroup && crun_error_get_errno (err) == ENOENT) + { + crun_error_release (err); + *container_status = "stopped"; + return 0; + } + + return ret; + } } if (! *running)