[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libvir] [PATCH] detect path of dnsmasq, brctl



I have found 3 bugs in libvirtd in the way that it runs the external programs dnsmasq and brctl.

Bug (1) is that it searches the $PATH to find dnsmasq. This is normally OK when libvirtd is launched from start-up scripts, but it's not very helpful if you run libvirtd by hand because likely-as-not your path won't contain /usr/sbin (the normal location of dnsmasq).

Bug (2) is that if libvirtd can't execvp dnsmasq, then it doesn't fail in any obvious way.

Bug (3) is that the path to brctl is hard-coded.

This patch fixes bugs (1) & (3), but does not fix bug (2).

Firstly configure has been changed so that it searches for dnsmasq and brctl programs in the usual places. If it find them then it generates a config.h file which looks like this:

--------------------
/* Location or name of the brctl program (see bridge-utils) */
#define BRCTL "/usr/sbin/brctl"

/* Location or name of the dnsmasq program */
#define DNSMASQ "/usr/sbin/dnsmasq"
--------------------

If it doesn't find them then it just includes the program names, not full paths:

--------------------
/* Location or name of the brctl program (see bridge-utils) */
#define BRCTL "brctl"

/* Location or name of the dnsmasq program */
#define DNSMASQ "dnsmasq"
--------------------

The code continues to use execvp to actually run the programs, so if the program names contain '/' then the absolute paths are used directly, otherwise execvp will do a shell-like search for the program along $PATH.

Please nota bene the change to the spec file.

Rich.

--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
Index: configure.in
===================================================================
RCS file: /data/cvs/libvirt/configure.in,v
retrieving revision 1.87
diff -u -p -r1.87 configure.in
--- configure.in	19 Sep 2007 17:42:40 -0000	1.87
+++ configure.in	20 Sep 2007 17:33:09 -0000
@@ -36,6 +36,20 @@ AC_PATH_PROG(TAR, tar, /bin/tar)
 AC_PATH_PROG(XMLLINT, xmllint, /usr/bin/xmllint)
 AC_PATH_PROG(XSLTPROC, xsltproc, /usr/bin/xsltproc)
 
+dnl External programs that we can use if they are available.
+dnl We will hard-code paths to these programs unless we cannot
+dnl detect them, in which case we'll search for the program
+dnl along the $PATH at runtime and fail if it's not there.
+AC_PATH_PROG(DNSMASQ, dnsmasq, dnsmasq,
+	[/sbin:/usr/sbin:/usr/local/sbin:$PATH])
+AC_PATH_PROG(BRCTL, brctl, brctl,
+	[/sbin:/usr/sbin:/usr/local/sbin:$PATH])
+
+AC_DEFINE_UNQUOTED([DNSMASQ],["$DNSMASQ"],
+        [Location or name of the dnsmasq program])
+AC_DEFINE_UNQUOTED([BRCTL],["$BRCTL"],
+        [Location or name of the brctl program (see bridge-utils)])
+
 dnl Make sure we have an ANSI compiler
 AM_C_PROTOTYPES
 test "x$U" != "x" && AC_MSG_ERROR(Compiler not ANSI compliant)
Index: libvirt.spec.in
===================================================================
RCS file: /data/cvs/libvirt/libvirt.spec.in,v
retrieving revision 1.62
diff -u -p -r1.62 libvirt.spec.in
--- libvirt.spec.in	19 Sep 2007 01:56:55 -0000	1.62
+++ libvirt.spec.in	20 Sep 2007 17:33:09 -0000
@@ -23,6 +23,8 @@ BuildRequires: ncurses-devel
 BuildRequires: gettext
 BuildRequires: gnutls-devel
 BuildRequires: avahi-devel
+BuildRequires: dnsmasq
+BuildRequires: bridge-utils
 Obsoletes: libvir
 ExclusiveArch: i386 x86_64 ia64
 
Index: src/bridge.c
===================================================================
RCS file: /data/cvs/libvirt/src/bridge.c,v
retrieving revision 1.3
diff -u -p -r1.3 bridge.c
--- src/bridge.c	7 Aug 2007 13:02:35 -0000	1.3
+++ src/bridge.c	20 Sep 2007 17:33:10 -0000
@@ -45,7 +45,6 @@
 
 #define MAX_BRIDGE_ID 256
 
-#define BRCTL_PATH "/usr/sbin/brctl"
 #define JIFFIES_TO_MS(j) (((j)*1000)/HZ)
 #define MS_TO_JIFFIES(ms) (((ms)*HZ)/1000)
 
@@ -684,7 +683,7 @@ brSetForwardDelay(brControl *ctl ATTRIBU
 
     n = 0;
 
-    if (!(argv[n++] = strdup(BRCTL_PATH)))
+    if (!(argv[n++] = strdup(BRCTL)))
         goto error;
 
     if (!(argv[n++] = strdup("setfd")))
@@ -741,7 +740,7 @@ brSetEnableSTP(brControl *ctl ATTRIBUTE_
 
     n = 0;
 
-    if (!(argv[n++] = strdup(BRCTL_PATH)))
+    if (!(argv[n++] = strdup(BRCTL)))
         goto error;
 
     if (!(argv[n++] = strdup("stp")))
Index: src/qemu_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_driver.c,v
retrieving revision 1.24
diff -u -p -r1.24 qemu_driver.c
--- src/qemu_driver.c	20 Sep 2007 17:13:39 -0000	1.24
+++ src/qemu_driver.c	20 Sep 2007 17:33:12 -0000
@@ -830,7 +830,7 @@ qemudBuildDnsmasqArgv(virConnectPtr conn
 
     i = 0;
 
-    APPEND_ARG(*argv, i++, "dnsmasq");
+    APPEND_ARG(*argv, i++, DNSMASQ);
 
     APPEND_ARG(*argv, i++, "--keep-in-foreground");
     /*

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]