[libvirt] [sandbox v2 05/11] Copy all needed init programs and all its deps to config subdir

Daniel P. Berrange berrange at redhat.com
Tue Jun 30 16:00:23 UTC 2015


On Mon, Jun 29, 2015 at 06:44:13PM +0200, Cédric Bosdonnat wrote:
> In order to be able to mount a custom host-image as / we need to be able
> to access libvirt-sandbox-init-common and all its needed dependencies.
> In the container case we also need to copy libvirt-sandbox-init-lxc.
> 
> They are now copied into SANDBOXCONFIGDIR /.libs. Hard linking is not
> possible since we may be working on separate partitions, and symlinks
> wouldn't help to work with apparmor. Copying makes apparmor happy and
> solves our problem.
> ---
>  configure.ac                                       |   7 +
>  .../libvirt-sandbox-builder-container.c            |  15 +-
>  libvirt-sandbox/libvirt-sandbox-builder.c          | 159 ++++++++++++++++++++-
>  libvirt-sandbox/libvirt-sandbox-builder.h          |   2 +
>  libvirt-sandbox/libvirt-sandbox-init-lxc.c         |   8 +-
>  libvirt-sandbox/libvirt-sandbox-init-qemu.c        |   9 +-
>  6 files changed, 196 insertions(+), 4 deletions(-)
> 

> diff --git a/libvirt-sandbox/libvirt-sandbox-init-lxc.c b/libvirt-sandbox/libvirt-sandbox-init-lxc.c
> index 798af37..e2fe7f0 100644
> --- a/libvirt-sandbox/libvirt-sandbox-init-lxc.c
> +++ b/libvirt-sandbox/libvirt-sandbox-init-lxc.c
> @@ -77,10 +77,16 @@ main(int argc, char **argv)
>          args[narg++] = "1000";
>      }
>  
> -    args[narg++] = LIBEXECDIR "/libvirt-sandbox-init-common";
> +    args[narg++] = SANDBOXCONFIGDIR "/.libs/libvirt-sandbox-init-common";
>      if (debug)
>          args[narg++] = "-d";
>  
> +    if (setenv("LD_LIBRARY_PATH", SANDBOXCONFIGDIR "/.libs", 1) != 0) {
> +        fprintf(stderr, "libvirt-sandbox-init-lxc: %s: cannot set LD_LIBRARY_PATH: %s\n",
> +                __func__, strerror(errno));
> +        exit(EXIT_FAILURE);
> +    }
> +
>      if (debug)
>          fprintf(stderr, "Running interactive\n");
>      execv(args[0], (char**)args);
> diff --git a/libvirt-sandbox/libvirt-sandbox-init-qemu.c b/libvirt-sandbox/libvirt-sandbox-init-qemu.c
> index 44305fd..62e8e40 100644
> --- a/libvirt-sandbox/libvirt-sandbox-init-qemu.c
> +++ b/libvirt-sandbox/libvirt-sandbox-init-qemu.c
> @@ -338,10 +338,17 @@ main(int argc ATTR_UNUSED, char **argv ATTR_UNUSED)
>          args[narg++] = "1000";
>      }
>  
> -    args[narg++] = LIBEXECDIR "/libvirt-sandbox-init-common";
> +    args[narg++] = SANDBOXCONFIGDIR "/.libs/libvirt-sandbox-init-common";
>      if (debug)
>          args[narg++] = "-d";
>  
> +    if (setenv("LD_LIBRARY_PATH", SANDBOXCONFIGDIR "/.libs", 1) < 0) {
> +        fprintf(stderr, "libvirt-sandbox-init-qemu: %s: cannot set LD_LIBRARY_PATH: %s\n",
> +                __func__, strerror(errno));
> +        exit_poweroff();
> +    }
> +
> +
>      if (debug)
>          fprintf(stderr, "libvirt-sandbox-init-qemu: Running common init %s\n", args[0]);
>      execv(args[0], (char**)args);

We need to unsetenv() in init-common to clear the LD_LIBRARY_PATH setting
to prevent it being used by the user application too

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list