[ovs-dev] [PATCH v2] dirs: dbdir default must be based on sysconfdir.
Ben Pfaff
blp at nicira.com
Thu Aug 2 23:05:29 UTC 2012
On Thu, Aug 02, 2012 at 03:51:05PM -0700, Ansis Atteka wrote:
> On Thu, Aug 2, 2012 at 2:13 PM, Ben Pfaff <blp at nicira.com> wrote:
>
> > Some in-tree and out-of-tree code sets the OVS_SYSCONFDIR environment
> > variable to control where /etc files go (mostly for test purposes). When
> > the database directory (dbdir) was split off from the sysconfdir, the
> > configure-time default continued to be based on the sysconfdir, but
> > overriding the sysconfdir at runtime with OVS_SYSCONFDIR didn't have any
> > effect on the dbdir, which caused a visible change in behavior for code
> > that set the OVS_SYSCONFDIR environment variable. This commit reverts that
> > change in behavior, by basing the dbdir on OVS_SYSCONFDIR if that
> > environment variable is set (but the OVS_DBDIR environment variable is
> > not).
> >
> > Signed-off-by: Ben Pfaff <blp at nicira.com>
> > ---
> > v1->v2: Fix issues pointed out by Ansis, fix up ovs-ctl.in also.
...
> > +ALL_LOCAL += $(srcdir)/python/ovs/dirs.py
> > +$(srcdir)/python/ovs/dirs.py: python/ovs/dirs.py.template
> >
> It seems that the dependencies above aren't correct (see below).
I totally screwed up the generation rule. It seems that I just can't
do anything right today. v3 is below. It changes only the second
'sed' command in python/automake.mk.
> > -RUNDIR = os.environ.get("OVS_RUNDIR", "/var/run")
> > -LOGDIR = os.environ.get("OVS_LOGDIR", "/usr/local/var/log")
> > -DBDIR = os.environ.get("OVS_DBDIR", "/usr/local/etc/openvswitch")
> > -BINDIR = os.environ.get("OVS_BINDIR", "/usr/local/bin")
> > +PKGDATADIR = os.environ.get("OVS_PKGDATADIR",
> > """/usr/share/openvswitch""")
> > +RUNDIR = os.environ.get("OVS_RUNDIR", """/var/run/openvswitch""")
> > +LOGDIR = os.environ.get("OVS_LOGDIR", """/var/log/openvswitch""")
> > +BINDIR = os.environ.get("OVS_BINDIR", """/usr/bin""")
> >
> Just curious, why "local" is dropped for the default case?
It wasn't supposed to be, that's just how I had my local build tree
configured (like your example).
--8<--------------------------cut here-------------------------->8--
From: Ben Pfaff <blp at nicira.com>
Date: Thu, 2 Aug 2012 16:01:49 -0700
Subject: [PATCH] dirs: dbdir default must be based on sysconfdir.
Some in-tree and out-of-tree code sets the OVS_SYSCONFDIR environment
variable to control where /etc files go (mostly for test purposes). When
the database directory (dbdir) was split off from the sysconfdir, the
configure-time default continued to be based on the sysconfdir, but
overriding the sysconfdir at runtime with OVS_SYSCONFDIR didn't have any
effect on the dbdir, which caused a visible change in behavior for code
that set the OVS_SYSCONFDIR environment variable. This commit reverts that
change in behavior, by basing the dbdir on OVS_SYSCONFDIR if that
environment variable is set (but the OVS_DBDIR environment variable is
not).
Signed-off-by: Ben Pfaff <blp at nicira.com>
---
v1->v2: Fix issues pointed out by Ansis, fix up ovs-ctl.in also.
v2->v3: Fix more issues pointed out by Ansis.
lib/dirs.c.in | 15 +++++++++++++--
python/automake.mk | 29 +++++++++++++++++++++++------
python/ovs/dirs.py | 20 ++++++++++++--------
python/ovs/dirs.py.template | 17 +++++++++++++++++
utilities/ovs-lib.in | 11 +++++++++--
5 files changed, 74 insertions(+), 18 deletions(-)
create mode 100644 python/ovs/dirs.py.template
diff --git a/lib/dirs.c.in b/lib/dirs.c.in
index 2b998b9..658a74b 100644
--- a/lib/dirs.c.in
+++ b/lib/dirs.c.in
@@ -18,6 +18,7 @@
#include <config.h>
#include "dirs.h"
#include <stdlib.h>
+#include "util.h"
struct directory {
const char *value; /* Actual value; NULL if not yet determined. */
@@ -68,8 +69,18 @@ ovs_logdir(void)
const char *
ovs_dbdir(void)
{
- static struct directory d = { NULL, @DBDIR@, "OVS_DBDIR" };
- return get_dir(&d);
+ static const char *dbdir;
+ if (!dbdir) {
+ dbdir = getenv("OVS_DBDIR");
+ if (!dbdir || !dbdir[0]) {
+ char *sysconfdir = getenv("OVS_SYSCONFDIR");
+
+ dbdir = (sysconfdir
+ ? xasprintf("%s/openvswitch", sysconfdir)
+ : @DBDIR@);
+ }
+ }
+ return dbdir;
}
const char *
diff --git a/python/automake.mk b/python/automake.mk
index 3cd6e1e..c0f0db6 100644
--- a/python/automake.mk
+++ b/python/automake.mk
@@ -43,12 +43,15 @@ if HAVE_PYTHON
nobase_pkgdata_DATA = $(ovs_pyfiles) $(ovstest_pyfiles)
ovs-install-data-local:
$(MKDIR_P) python/ovs
- (echo "import os" && \
- echo 'PKGDATADIR = os.environ.get("OVS_PKGDATADIR", """$(pkgdatadir)""")' && \
- echo 'RUNDIR = os.environ.get("OVS_RUNDIR", """@RUNDIR@""")' && \
- echo 'LOGDIR = os.environ.get("OVS_LOGDIR", """@LOGDIR@""")' && \
- echo 'DBDIR = os.environ.get("OVS_DBDIR", """@DBDIR@""")' && \
- echo 'BINDIR = os.environ.get("OVS_BINDIR", """$(bindir)""")') \
+ sed \
+ -e '/^##/d' \
+ -e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \
+ -e 's,[@]RUNDIR[@],$(RUNDIR),g' \
+ -e 's,[@]LOGDIR[@],$(LOGDIR),g' \
+ -e 's,[@]bindir[@],$(bindir),g' \
+ -e 's,[@]sysconfdir[@],$(sysconfdir),g' \
+ -e 's,[@]DBDIR[@],$(DBDIR),g' \
+ < $(srcdir)/python/ovs/dirs.py.template \
> python/ovs/dirs.py.tmp
$(MKDIR_P) $(DESTDIR)$(pkgdatadir)/python/ovs
$(INSTALL_DATA) python/ovs/dirs.py.tmp $(DESTDIR)$(pkgdatadir)/python/ovs/dirs.py
@@ -68,3 +71,17 @@ $(srcdir)/python/ovs/version.py: config.status
$(ro_shell) > $(@F).tmp
echo 'VERSION = "$(VERSION)"' >> $(@F).tmp
if cmp -s $(@F).tmp $@; then touch $@; rm $(@F).tmp; else mv $(@F).tmp $@; fi
+
+ALL_LOCAL += $(srcdir)/python/ovs/dirs.py
+$(srcdir)/python/ovs/dirs.py: python/ovs/dirs.py.template
+ sed \
+ -e '/^##/d' \
+ -e 's,[@]pkgdatadir[@],/usr/local/share/openvswitch,g' \
+ -e 's,[@]RUNDIR[@],/var/run,g' \
+ -e 's,[@]LOGDIR[@],/usr/local/var/log,g' \
+ -e 's,[@]bindir[@],/usr/local/bin,g' \
+ -e 's,[@]sysconfdir[@],/usr/local/etc,g' \
+ -e 's,[@]DBDIR[@],/usr/local/etc/openvswitch,g' \
+ < $? > $@.tmp
+ mv $@.tmp $@
+EXTRA_DIST += python/ovs/dirs.py python/ovs/dirs.py.template
diff --git a/python/ovs/dirs.py b/python/ovs/dirs.py
index e4b37f9..b5e68a0 100644
--- a/python/ovs/dirs.py
+++ b/python/ovs/dirs.py
@@ -1,9 +1,13 @@
-# These are the default directories. They will be replaced by the
-# configured directories at install time.
-
import os
-PKGDATADIR = os.environ.get("OVS_PKGDATADIR", "/usr/local/share/openvswitch")
-RUNDIR = os.environ.get("OVS_RUNDIR", "/var/run")
-LOGDIR = os.environ.get("OVS_LOGDIR", "/usr/local/var/log")
-DBDIR = os.environ.get("OVS_DBDIR", "/usr/local/etc/openvswitch")
-BINDIR = os.environ.get("OVS_BINDIR", "/usr/local/bin")
+PKGDATADIR = os.environ.get("OVS_PKGDATADIR", """/usr/local/share/openvswitch""")
+RUNDIR = os.environ.get("OVS_RUNDIR", """/var/run""")
+LOGDIR = os.environ.get("OVS_LOGDIR", """/usr/local/var/log""")
+BINDIR = os.environ.get("OVS_BINDIR", """/usr/local/bin""")
+
+DBDIR = os.environ.get("OVS_DBDIR")
+if not DBDIR:
+ sysconfdir = os.environ.get("OVS_SYSCONFDIR")
+ if sysconfdir:
+ DBDIR = "%s/openvswitch" % sysconfdir
+ else:
+ DBDIR = """/usr/local/etc/openvswitch"""
diff --git a/python/ovs/dirs.py.template b/python/ovs/dirs.py.template
new file mode 100644
index 0000000..370c69f
--- /dev/null
+++ b/python/ovs/dirs.py.template
@@ -0,0 +1,17 @@
+## The @variables@ in this file are replaced by default directories for
+## use in python/ovs/dirs.py in the source directory and replaced by the
+## configured directories for use in the installed python/ovs/dirs.py.
+##
+import os
+PKGDATADIR = os.environ.get("OVS_PKGDATADIR", """@pkgdatadir@""")
+RUNDIR = os.environ.get("OVS_RUNDIR", """@RUNDIR@""")
+LOGDIR = os.environ.get("OVS_LOGDIR", """@LOGDIR@""")
+BINDIR = os.environ.get("OVS_BINDIR", """@bindir@""")
+
+DBDIR = os.environ.get("OVS_DBDIR")
+if not DBDIR:
+ sysconfdir = os.environ.get("OVS_SYSCONFDIR")
+ if sysconfdir:
+ DBDIR = "%s/openvswitch" % sysconfdir
+ else:
+ DBDIR = """@DBDIR@"""
diff --git a/utilities/ovs-lib.in b/utilities/ovs-lib.in
index 893e8d1..3c63ddd 100644
--- a/utilities/ovs-lib.in
+++ b/utilities/ovs-lib.in
@@ -22,14 +22,21 @@
# All of these should be substituted by the Makefile at build time.
logdir=${OVS_LOGDIR-'@LOGDIR@'} # /var/log/openvswitch
rundir=${OVS_RUNDIR-'@RUNDIR@'} # /var/run/openvswitch
-dbdir=${OVS_DBDIR-'@DBDIR@'} # /etc/openvswitch
- # or /var/lib/openvswitch
sysconfdir=${OVS_SYSCONFDIR-'@sysconfdir@'} # /etc
etcdir=$sysconfdir/openvswitch # /etc/openvswitch
datadir=${OVS_PKGDATADIR-'@pkgdatadir@'} # /usr/share/openvswitch
bindir=${OVS_BINDIR-'@bindir@'} # /usr/bin
sbindir=${OVS_SBINDIR-'@sbindir@'} # /usr/sbin
+# /etc/openvswitch or /var/lib/openvswitch
+if test X"$OVS_DBDIR" != X; then
+ dbdir=$OVS_DBDIR
+elif test X"$OVS_SYSCONFDIR" != X; then
+ dbdir=$OVS_SYSCONFDIR/openvswitch
+else
+ dbdir='@DBDIR@'
+fi
+
VERSION='@VERSION@'
LC_ALL=C; export LC_ALL
--
1.7.2.5
More information about the dev
mailing list