[klibc] [PATCH 7/8] switch_root: Don't fail due to stray mount
maximilian attems
max at stro.at
Wed Jul 13 06:48:32 PDT 2011
Make switch_root more permissive and just print it's errors,
so that it doesn't fail on a deep mount somewhere.
This is analogue to switch_root(8) handling in util-linux.
Failure in nuke_dir() is no longer fatal, but will print warning
and move on.
Fixes:
https://bugs.launchpad.net/ubuntu/+source/klibc/+bug/31762
https://bugs.launchpad.net/ubuntu/+source/klibc/+bug/617426
Signed-off-by: maximilian attems <max at stro.at>
---
usr/kinit/switch_root/switch_rootlib.c | 18 ++++++++----------
1 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/usr/kinit/switch_root/switch_rootlib.c b/usr/kinit/switch_root/switch_rootlib.c
index 372d2b3..b34f2b4 100644
--- a/usr/kinit/switch_root/switch_rootlib.c
+++ b/usr/kinit/switch_root/switch_rootlib.c
@@ -97,17 +97,18 @@ static int nuke_dir(const char *what)
int err = 0;
struct stat st;
- if (lstat(what, &st))
- return errno;
+ if (lstat(what, &st)) {
+ fprintf(stderr, "failed to stat directory\n");
+ return 0;
+ }
if (!S_ISDIR(st.st_mode))
return ENOTDIR;
dir = opendir(what);
if (!dir) {
- /* EACCES means we can't read it. Might be empty and removable;
- if not, the rmdir() in nuke() will trigger an error. */
- return (errno == EACCES) ? 0 : errno;
+ fprintf(stderr, "failed to open directory\n");
+ return 0;
}
while ((d = readdir(dir))) {
@@ -118,14 +119,11 @@ static int nuke_dir(const char *what)
continue;
err = nuke_dirent(len, what, d->d_name, st.st_dev);
- if (err) {
- closedir(dir);
- return err;
- }
+ if (err)
+ fprintf(stderr, "failed to unlink %s\n", d->d_name);
}
closedir(dir);
-
return 0;
}
--
1.7.5.4
More information about the klibc
mailing list