EXTRA_DIST += \
lib/dh1024.pem \
lib/dh2048.pem \
- lib/dh4096.pem
+ lib/dh4096.pem \
+ lib/dirs.c.in
EXTRA_DIST += \
lib/common.man \
lib/vlog-syn.man \
lib/vlog.man
-lib/dirs.c: Makefile
- ($(ro_c) && \
- echo 'const char ovs_pkgdatadir[] = "$(pkgdatadir)";' && \
- echo 'const char ovs_rundir[] = "@RUNDIR@";' && \
- echo 'const char ovs_logdir[] = "@LOGDIR@";' && \
- echo 'const char ovs_bindir[] = "$(bindir)";') > lib/dirs.c.tmp
+lib/dirs.c: lib/dirs.c.in Makefile
+ ($(ro_c) && sed < $(srcdir)/lib/dirs.c.in \
+ -e 's,[@]srcdir[@],$(srcdir),g' \
+ -e 's,[@]LOGDIR[@],"$(LOGDIR)",g' \
+ -e 's,[@]RUNDIR[@],"$(RUNDIR)",g' \
+ -e 's,[@]bindir[@],"$(bindir)",g' \
+ -e 's,[@]pkgdatadir[@],"$(pkgdatadir)",g') \
+ > lib/dirs.c.tmp
mv lib/dirs.c.tmp lib/dirs.c
install-data-local: lib-install-data-local
make_pidfile_name(const char *name)
{
return (!name
- ? xasprintf("%s/%s.pid", ovs_rundir, program_name)
- : abs_file_name(ovs_rundir, name));
+ ? xasprintf("%s/%s.pid", ovs_rundir(), program_name)
+ : abs_file_name(ovs_rundir(), name));
}
/* Sets up a following call to daemonize() to create a pidfile named 'name'.
" --pidfile[=FILE] create pidfile (default: %s/%s.pid)\n"
" --overwrite-pidfile with --pidfile, start even if already "
"running\n",
- ovs_rundir, program_name);
+ ovs_rundir(), program_name);
}
/* Opens and reads a PID from 'pidfile'. Returns the nonnegative PID if
--- /dev/null
+#line 2 "@srcdir@/lib/dirs.c.in"
+/*
+ * Copyright (c) 2008, 2009, 2010 Nicira Networks.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <config.h>
+#include "dirs.h"
+#include <stdlib.h>
+
+struct directory {
+ const char *value; /* Actual value; NULL if not yet determined. */
+ const char *default_value; /* Default value. */
+ const char *var_name; /* Environment variable to override default. */
+};
+
+static const char *
+get_dir(struct directory *d)
+{
+ if (!d->value) {
+ d->value = getenv(d->var_name);
+ if (!d->value || !d->value[0]) {
+ d->value = d->default_value;
+ }
+ }
+ return d->value;
+}
+
+const char *
+ovs_pkgdatadir(void)
+{
+ static struct directory d = { NULL, @pkgdatadir@, "OVS_PKGDATADIR" };
+ return get_dir(&d);
+}
+
+const char *
+ovs_rundir(void)
+{
+ static struct directory d = { NULL, @RUNDIR@, "OVS_RUNDIR" };
+ return get_dir(&d);
+}
+
+const char *
+ovs_logdir(void)
+{
+ static struct directory d = { NULL, @LOGDIR@, "OVS_LOGDIR" };
+ return get_dir(&d);
+}
+
+const char *
+ovs_bindir(void)
+{
+ static struct directory d = { NULL, @bindir@, "OVS_BINDIR" };
+ return get_dir(&d);
+}
/*
- * Copyright (c) 2008, 2009 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#ifndef DIRS_H
#define DIRS_H 1
-extern const char ovs_pkgdatadir[]; /* /usr/local/share/openvswitch */
-extern const char ovs_rundir[]; /* /usr/local/var/run/openvswitch */
-extern const char ovs_logdir[]; /* /usr/local/var/log/openvswitch */
-extern const char ovs_bindir[]; /* /usr/local/bin */
+const char *ovs_pkgdatadir(void); /* /usr/local/share/openvswitch */
+const char *ovs_rundir(void); /* /usr/local/var/run/openvswitch */
+const char *ovs_logdir(void); /* /usr/local/var/log/openvswitch */
+const char *ovs_bindir(void); /* /usr/local/bin */
#endif /* dirs.h */
list_init(&server->conns);
if (path) {
- server->path = abs_file_name(ovs_rundir, path);
+ server->path = abs_file_name(ovs_rundir(), path);
} else {
- server->path = xasprintf("%s/%s.%ld.ctl", ovs_rundir,
+ server->path = xasprintf("%s/%s.%ld.ctl", ovs_rundir(),
program_name, (long int) getpid());
}
\f
/* Connects to a Vlog server socket. 'path' should be the name of a Vlog
* server socket. If it does not start with '/', it will be prefixed with
- * ovs_rundir (e.g. /var/run/openvswitch).
+ * the rundir (e.g. /usr/local/var/run/openvswitch).
*
* Returns 0 if successful, otherwise a positive errno value. If successful,
* sets '*clientp' to the new unixctl_client, otherwise to NULL. */
/* Determine location. */
client = xmalloc(sizeof *client);
- client->connect_path = abs_file_name(ovs_rundir, path);
+ client->connect_path = abs_file_name(ovs_rundir(), path);
client->bind_path = xasprintf("/tmp/vlog.%ld.%d",
(long int) getpid(), counter++);
old_log_file_name = log_file_name;
log_file_name = (file_name
? xstrdup(file_name)
- : xasprintf("%s/%s.log", ovs_logdir, program_name));
+ : xasprintf("%s/%s.log", ovs_logdir(), program_name));
free(old_log_file_name);
file_name = NULL; /* Might have been freed. */
" -v, --verbose set maximum verbosity level\n"
" --log-file[=FILE] enable logging to specified FILE\n"
" (default: %s/%s.log)\n",
- ovs_logdir, program_name);
+ ovs_logdir(), program_name);
}
nobase_pkgdata_DATA = $(ovs_pyfiles)
ovs-install-data-local:
$(MKDIR_P) python/ovs
- (echo 'PKGDATADIR = """$(pkgdatadir)"""' && \
- echo 'RUNDIR = """@RUNDIR@"""' && \
- echo 'LOGDIR = """@LOGDIR@"""' && \
- echo 'BINDIR = """$(bindir)"""') > python/ovs/dirs.py.tmp
+ (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 'BINDIR = os.environ.get("OVS_BINDIR", """$(bindir)""")') \
+ > python/ovs/dirs.py.tmp
$(MKDIR_P) $(DESTDIR)$(pkgdatadir)/python/ovs
$(INSTALL_DATA) python/ovs/dirs.py.tmp $(DESTDIR)$(pkgdatadir)/python/ovs/dirs.py
rm python/ovs/dirs.py.tmp
# These are the default directories. They will be replaced by the
# configured directories at install time.
-PKGDATADIR = "/usr/local/share/openvswitch"
-RUNDIR = "/var/run"
-LOGDIR = "/usr/local/var/log"
-BINDIR = "/usr/local/bin"
+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")
+BINDIR = os.environ.get("OVS_BINDIR", "/usr/local/bin")
char *pidfile_name;
pid_t pid;
- pidfile_name = xasprintf("%s/%s.pid", ovs_rundir, target);
+ pidfile_name = xasprintf("%s/%s.pid", ovs_rundir(), target);
pid = read_pidfile(pidfile_name);
if (pid < 0) {
ovs_fatal(-pid, "cannot read pidfile \"%s\"", pidfile_name);
}
free(pidfile_name);
socket_name = xasprintf("%s/%s.%ld.ctl",
- ovs_rundir, target, (long int) pid);
+ ovs_rundir(), target, (long int) pid);
} else {
socket_name = xstrdup(target);
}
"running\n"
" -h, --help display this help message\n"
" -V, --version display version information\n",
- ovs_rundir, program_name);
+ ovs_rundir(), program_name);
exit(EXIT_SUCCESS);
}
struct stat s;
char *bridge_path, *datapath_name, *datapath_type;
- bridge_path = xasprintf("%s/%s.%s", ovs_rundir, name, default_suffix);
+ bridge_path = xasprintf("%s/%s.%s", ovs_rundir(), name, default_suffix);
dp_parse_name(name, &datapath_name, &datapath_type);
if (strstr(name, ":")) {
}
socket_name = xasprintf("%s/%s.%s",
- ovs_rundir, dpif_name, default_suffix);
+ ovs_rundir(), dpif_name, default_suffix);
if (stat(socket_name, &s)) {
ovs_fatal(errno, "cannot connect to %s: stat failed on %s",
name, socket_name);
/* Figure out controller names. */
if (!controllers.n) {
- svec_add_nocopy(&controllers,
- xasprintf("punix:%s/%s.mgmt", ovs_rundir, s->dp_name));
+ svec_add_nocopy(&controllers, xasprintf("punix:%s/%s.mgmt",
+ ovs_rundir(), s->dp_name));
}
for (i = 1; i < argc; i++) {
svec_add(&controllers, argv[i]);
{
static char *def;
if (!def) {
- def = xasprintf("unix:%s/db.sock", ovs_rundir);
+ def = xasprintf("unix:%s/db.sock", ovs_rundir());
}
return def;
}
/* Configure OpenFlow controller connection snooping. */
svec_init(&snoops);
svec_add_nocopy(&snoops, xasprintf("punix:%s/%s.snoop",
- ovs_rundir, br->name));
+ ovs_rundir(), br->name));
svec_init(&old_snoops);
ofproto_get_snoops(br->ofproto, &old_snoops);
if (!svec_equal(&snoops, &old_snoops)) {
bridge_ofproto_controller_for_mgmt(const struct bridge *br,
struct ofproto_controller *oc)
{
- oc->target = xasprintf("punix:%s/%s.mgmt", ovs_rundir, br->name);
+ oc->target = xasprintf("punix:%s/%s.mgmt", ovs_rundir(), br->name);
oc->max_backoff = 0;
oc->probe_interval = 60;
oc->band = OFPROTO_OUT_OF_BAND;
};
char *short_options = long_options_to_short_options(long_options);
- appctl_command = xasprintf("%s/ovs-appctl %%s", ovs_bindir);
+ appctl_command = xasprintf("%s/ovs-appctl %%s", ovs_bindir());
for (;;) {
int c;
struct dirent *de;
DIR *dir;
- dir = opendir(ovs_rundir);
+ dir = opendir(ovs_rundir());
if (!dir) {
- VLOG_ERR_ONCE("%s: open failed (%s)", ovs_rundir, strerror(errno));
+ VLOG_ERR_ONCE("%s: open failed (%s)", ovs_rundir(), strerror(errno));
return;
}
continue;
}
- file_name = xasprintf("%s/%s", ovs_rundir, de->d_name);
+ file_name = xasprintf("%s/%s", ovs_rundir(), de->d_name);
pid = read_pidfile(file_name);
free(file_name);
if (pid < 0 || kill(pid, 0)) {