[libvirt] [PATCH 3/3] Add a ./run script for running programs from the local directory.

Daniel P. Berrange berrange at redhat.com
Tue Sep 18 09:40:34 UTC 2012


On Tue, Sep 18, 2012 at 10:26:07AM +0100, Richard W.M. Jones wrote:
> On Tue, Sep 18, 2012 at 10:12:39AM +0100, Daniel P. Berrange wrote:
> > On Fri, Sep 14, 2012 at 11:09:28AM +0100, Richard W.M. Jones wrote:
> > > +# Do we have libtool?  If we have it then we can use it to make
> > > +# running valgrind simpler.  However don't depend on it.
> > > +if libtool --help >/dev/null 2>&1; then
> > 
> > I'm not sure I see the point of this conditional. Even if running from a
> > tar.gz build, with no locally installed libtool, there is the script at
> > $top_srcdir/libtool isn't there ?
> > 
> > > +    libtool="libtool --mode=execute"
> > > +fi
> > > +
> > > +# Run the program.
> > > +exec $libtool "$@"
> 
> This is directly copied from libguestfs.
> 
> The reason to use 'libtool --mode=execute' at all is so that you can
> use gdb.  Thus './run gdb ./program' is expanded to:
> 
>   libtool --mode=execute gdb ./program
> 
> (Same reasoning applies to './run valgrind ./program').

Oh, sure I know why you want to use libtool for this - just wondered
about why you had the check for it existing.

> The reason not to use ./libtool is because in libguestfs we replace
> the top-level ./libtool script with something else for a variety of
> complicated reasons.
> 
> The reason to check if libtool exists (running 'libtool --help') is so
> that the whole thing works if the user didn't install (global) libtool.
> 
> So I agree that for libvirt it's better to run the toplevel ./libtool
> program instead.  Please see the attached updated patch which changes
> this, and also doesn't set $PATH (wasn't required), but is otherwise
> the same.
> 
> BTW this script is super-useful.  For example to run the libguestfs
> test suite using a local copy of libvirt you just have to do:
> 
>   ../libvirt/run make check
> 
> Rich.
> 
> -- 
> Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
> Read my programming blog: http://rwmj.wordpress.com
> Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
> http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora

> From 33acff3e2bb81a7259a2affae2a3e5cf202ba2ee Mon Sep 17 00:00:00 2001
> From: "Richard W.M. Jones" <rjones at redhat.com>
> Date: Fri, 14 Sep 2012 10:08:54 +0100
> Subject: [PATCH] Add a ./run script for running programs from the local
>  directory.
> 
> With this script you can run libvirt programs without needing to
> install them first.  You just have to do for example:
> 
>   ./run ./tools/virsh [args ...]
> 
> If you are already in the tools/ subdirectory, then the following
> command will also work:
> 
>   ../run ./virsh [...]
> 
> You can also run the C programs under valgrind like this:
> 
>   ./run valgrind [valgrind opts...] ./program
> 
> or under gdb:
> 
>   ./run gdb --args ./program
> 
> This also works with sudo (eg. if you need root access for libvirt):
> 
>   sudo ./run ./tools/virsh list --all
> 
> Derived from libguestfs and simplified.  The ./run script in
> libguestfs is much more sophisticated:
> 
> https://github.com/libguestfs/libguestfs/blob/master/run.in
> ---
>  .gitignore             |    1 +
>  configure.ac           |    2 ++
>  docs/compiling.html.in |   11 ++-----
>  run.in                 |   74 ++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 79 insertions(+), 9 deletions(-)
>  create mode 100644 run.in
> 
> diff --git a/.gitignore b/.gitignore
> index 7d49a35..1cd2d45 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -94,6 +94,7 @@
>  /python/libvirt.[ch]
>  /python/libvirt.py
>  /python/libvirt_qemu.py
> +/run
>  /sc_*
>  /src/.*.stamp
>  /src/esx/*.generated.*
> diff --git a/configure.ac b/configure.ac
> index 2090e5f..186f79e 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -2972,6 +2972,8 @@ AC_DEFINE_UNQUOTED([isbase64],[libvirt_gl_isbase64],[Hack to avoid symbol clash]
>  AC_DEFINE_UNQUOTED([base64_encode],[libvirt_gl_base64_encode],[Hack to avoid symbol clash])
>  AC_DEFINE_UNQUOTED([base64_encode_alloc],[libvirt_gl_base64_encode_alloc],[Hack to avoid symbol clash])
>  
> +AC_CONFIG_FILES([run],
> +                [chmod +x,-w run])
>  AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile \
>  	  docs/schemas/Makefile \
>  	  gnulib/lib/Makefile \
> diff --git a/docs/compiling.html.in b/docs/compiling.html.in
> index d39986e..0bfb298 100644
> --- a/docs/compiling.html.in
> +++ b/docs/compiling.html.in
> @@ -101,18 +101,11 @@
>  
>      <p>
>        It is also possible to run virsh directly from the source tree
> +      using the ./run script (which sets some environment variables):
>      </p>
>  
>      <pre>
> -      $ ./tools/virsh ....
> +      $ ./run ./tools/virsh ....
>      </pre>
> -
> -    <p>
> -      A normal configuration of libvirt will build hypervisor drivers
> -      as loadable modules. When running from a non-installed source
> -      tree, libvirtd will attempt to find the modules from the same
> -      source tree. If this is not possible though, you can explicitly
> -      set <code>LIBVIRT_DRIVER_DIR=/path/to/source/tree/src/.libs</code>
> -    </p>
>    </body>
>  </html>
> diff --git a/run.in b/run.in
> new file mode 100644
> index 0000000..7700e52
> --- /dev/null
> +++ b/run.in
> @@ -0,0 +1,74 @@
> +#!/bin/bash -
> +# libvirt 'run' programs locally script
> +# Copyright (C) 2012 Red Hat Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> +
> +#----------------------------------------------------------------------
> +#
> +# With this script you can run libvirt programs without needing to
> +# install them first.  You just have to do for example:
> +#
> +#   ./run ./tools/virsh [args ...]
> +#
> +# If you are already in the tools/ subdirectory, then the following
> +# command will also work:
> +#
> +#   ../run ./virsh [...]
> +#
> +# You can also run the C programs under valgrind like this:
> +#
> +#   ./run valgrind [valgrind opts...] ./program
> +#
> +# or under gdb:
> +#
> +#   ./run gdb --args ./program
> +#
> +# This also works with sudo (eg. if you need root access for libvirt):
> +#
> +#   sudo ./run ./tools/virsh list --all
> +#
> +#----------------------------------------------------------------------
> +
> +# Find this script.
> +b=@abs_builddir@
> +
> +library_path="$b/src/.libs"
> +if [ -z "$LD_LIBRARY_PATH" ]; then
> +    LD_LIBRARY_PATH=$library_path
> +else
> +    LD_LIBRARY_PATH="$library_path:$LD_LIBRARY_PATH"
> +fi
> +export LD_LIBRARY_PATH
> +
> +export LIBVIRT_DRIVER_DIR="$b/src/.libs"
> +export LIBVIRTD_PATH="$b/daemon/libvirtd"
> +
> +# For Python.
> +export PYTHON=@PYTHON@
> +if [ -z "$PYTHONPATH" ]; then
> +    PYTHONPATH="$b/python:$b/python/.libs"
> +else
> +    PYTHONPATH="$b/python:$b/python/.libs:$PYTHONPATH"
> +fi
> +export PYTHONPATH
> +
> +# This is a cheap way to find some use-after-free and uninitialized
> +# read problems when using glibc.
> +random_val="$(awk 'BEGIN{srand(); print 1+int(255*rand())}' < /dev/null)"
> +export MALLOC_PERTURB_=$random_val
> +
> +# Run the program.
> +exec $b/libtool --mode=execute "$@"

ACK


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