Skip to content

Commit

Permalink
status: rmdirfd: try harder to remove mount points
Browse files Browse the repository at this point in the history
The previous patch left a mount point in /run/crun which could not be
removed, we should try harder to remove directories failing with EBUSY
as we do in create_missing_devs().

This patch also fixes the issue described in the previous commit
("status: rmdirfd: try harder to remove mount points").

Fixes: 523eed3 ("linux: add new fallback when mount fails with EBUSY")
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
  • Loading branch information
martinetd committed Apr 27, 2024
1 parent 0f9984a commit 39ab155
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/libcrun/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <yajl/yajl_tree.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
Expand Down Expand Up @@ -485,7 +486,20 @@ rmdirfd (const char *namedir, int fd, libcrun_error_t *err)
ret = unlinkat (dirfd (d), de->d_name, 0);
if (ret < 0)
{
retry_unlink:
ret = unlinkat (dirfd (d), de->d_name, AT_REMOVEDIR);
if (ret < 0 && errno == EBUSY)
{
cleanup_close int tfd = openat (dirfd (d), de->d_name, O_CLOEXEC | O_PATH | O_NOFOLLOW);
if (tfd >= 0)
{
proc_fd_path_t procpath;

get_proc_self_fd_path (procpath, tfd);
if (umount2 (procpath, MNT_DETACH) == 0)
goto retry_unlink;
}
}
if (ret < 0 && errno == ENOTEMPTY)
{
cleanup_close int cfd = -1;
Expand Down

0 comments on commit 39ab155

Please sign in to comment.