Richard W.M. Jones
2011-Apr-27 09:40 UTC
[Libguestfs] [PATCH febootstrap] helper: Change to root directory before running find command.
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top -------------- next part -------------->From d638270b133f19ca7f9570e47a498381dc4cfe10 Mon Sep 17 00:00:00 2001From: Richard W.M. Jones <rjones at redhat.com> Date: Wed, 27 Apr 2011 10:39:24 +0100 Subject: [PATCH] helper: Change to root directory before running find command. --- helper/ext2initrd.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/helper/ext2initrd.c b/helper/ext2initrd.c index f10aef2..3d765ca 100644 --- a/helper/ext2initrd.c +++ b/helper/ext2initrd.c @@ -26,6 +26,7 @@ #include <unistd.h> #include <dirent.h> #include <errno.h> +#include <assert.h> #include "error.h" #include "full-write.h" @@ -80,7 +81,18 @@ ext2_make_initrd (const char *modpath, const char *initrd) for (i = 0; kmods[i] != NULL; ++i) n += strlen (kmods[i]) + 16; cmd = malloc (n); - sprintf (cmd, "find '%s' ", modpath); + /* "cd /" here is for virt-v2v. It's cwd might not be accessible by + * the current user (because it sometimes sets its own uid) and the + * "find" command works by changing directory then changing back to + * the cwd. This results in a warning: + * + * find: failed to restore initial working directory: Permission denied + * + * Note this only works because "modpath" and temporary "dir" are + * currently guaranteed to be absolute paths, hence assertion. + */ + assert (modpath[0] == '/'); + sprintf (cmd, "cd / ; find '%s' ", modpath); for (i = 0; kmods[i] != NULL; ++i) { if (i > 0) strcat (cmd, "-o "); strcat (cmd, "-name '"); -- 1.7.4.4
Apparently Analagous Threads
- [PATCH febootstrap 0/2] febootstrap-supermin-helper should visit directory entries in order and ignore backup files
- [PATCH] Change download_to_tmp so it can work with multi-root operating systems.
- [PATCH febootstrap] Pull in febootstrap-supermin-helper (C version) from libguestfs.
- libguestfs, porting to FreeBSD
- Re: febootstrap: no ext2 root device found