]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Add a ./run script for running programs from the local directory.
authorRichard W.M. Jones <rjones@redhat.com>
Fri, 14 Sep 2012 09:08:54 +0000 (10:08 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Tue, 18 Sep 2012 09:59:16 +0000 (10:59 +0100)
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
Makefile.am
configure.ac
docs/compiling.html.in
run.in [new file with mode: 0644]

index 7d49a35236666ae82c30696dc36e558528670b10..1cd2d45808e78442f83959a4870aae334a7c6815 100644 (file)
@@ -94,6 +94,7 @@
 /python/libvirt.[ch]
 /python/libvirt.py
 /python/libvirt_qemu.py
+/run
 /sc_*
 /src/.*.stamp
 /src/esx/*.generated.*
index 41636b1d3661434d3b3ac99bdf38d5b58366faa2..333e30086a2993b065908b2a2f9e7591e315b6dd 100644 (file)
@@ -27,6 +27,7 @@ EXTRA_DIST = \
   autogen.sh \
   cfg.mk \
   examples/domain-events/events-python \
+  run.in \
   $(XML_EXAMPLES)
 
 pkgconfigdir = $(libdir)/pkgconfig
index 2090e5f6a114a6da66cd7a357af1eab68b5dacbd..186f79e87d53a92111b6eaf5cac05190da736cd9 100644 (file)
@@ -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 \
index d39986ee85f9b830a117be8007a2681cb7709a7c..0bfb2981bc34a81edbb7fb0b5f2fa9242fc14e0b 100644 (file)
 
     <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 (file)
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 "$@"