Skip to content

Commit

Permalink
state: fix race condition when reading cgroup
Browse files Browse the repository at this point in the history
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: containers/podman#7148

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Aug 27, 2020
1 parent 8bd4f3e commit ed9c3e6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/libcrun/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ed9c3e6

Please sign in to comment.