diff --git a/cr-restore.c b/cr-restore.c index d3cc50c5d..4171155f4 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -1546,9 +1546,6 @@ static int restore_task_with_children(void *_arg) return 0; err_fini_mnt: - if (current->parent == NULL) - depopulate_roots_yard(); - err: if (current->parent == NULL) futex_abort_and_wake(&task_entries->nr_in_progress); @@ -1835,6 +1832,8 @@ static int restore_root_task(struct pstree_item *init) */ task_entries->nr_threads -= atomic_read(&task_entries->nr_zombies); + cleanup_mnt_ns(); + ret = stop_usernsd(); if (ret < 0) goto out_kill; @@ -1919,6 +1918,7 @@ out_kill: out: fini_cgroup(); + cleanup_mnt_ns(); stop_usernsd(); __restore_switch_stage(CR_STATE_FAIL); pr_err("Restoring FAILED.\n"); diff --git a/include/mount.h b/include/mount.h index ca2759330..08edfa2f7 100644 --- a/include/mount.h +++ b/include/mount.h @@ -118,5 +118,6 @@ extern int depopulate_roots_yard(void); extern char *rst_get_mnt_root(int mnt_id); extern int ext_mount_add(char *key, char *val); extern int mntns_maybe_create_roots(void); +extern void cleanup_mnt_ns(void); #endif /* __CR_MOUNT_H__ */ diff --git a/mount.c b/mount.c index 46f28e816..cd946d9f9 100644 --- a/mount.c +++ b/mount.c @@ -2734,14 +2734,19 @@ int depopulate_roots_yard(void) pr_perror("Can't unmount %s", mnt_roots); ret = 1; } - if (rmdir(mnt_roots)) { - pr_perror("Can't remove the directory %s", mnt_roots); - ret = 1; - } return ret; } +void cleanup_mnt_ns(void) +{ + if (mnt_roots == NULL) + return; + + if (rmdir(mnt_roots)) + pr_perror("Can't remove the directory %s", mnt_roots); +} + int prepare_mnt_ns(void) { int ret = -1;