From: Ben Pfaff Date: Wed, 22 Oct 2008 21:53:25 +0000 (-0700) Subject: Make pkidir, rundir, logdir modifiable from "configure" command line. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ddbf6040e308bd5f3c5d6ac6445f5a0e58735d07;p=openvswitch Make pkidir, rundir, logdir modifiable from "configure" command line. Make "make" behave properly when these are changed by re-running "configure", by putting their definitions into a generated file that depends on Makefile. --- diff --git a/Makefile.am b/Makefile.am index 398dcb00..bb69db7a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,12 +20,6 @@ endif AM_CFLAGS = -Wstrict-prototypes -rundir = $(localstatedir)/run -AM_CPPFLAGS += -DRUNDIR=\"$(rundir)\" - -logdir = $(localstatedir)/log/$(PACKAGE) -AM_CPPFLAGS += -DLOGDIR=\"$(logdir)\" - if NDEBUG AM_CPPFLAGS += -DNDEBUG AM_CFLAGS += -fomit-frame-pointer @@ -46,11 +40,12 @@ noinst_LIBRARIES = noinst_PROGRAMS = noinst_SCRIPTS = -do_subst = sed -e 's,[@]pkidir[@],$(pkidir),g' \ - -e 's,[@]rundir[@],$(rundir),g' \ +do_subst = sed -e 's,[@]PKIDIR[@],$(PKIDIR),g' \ + -e 's,[@]RUNDIR[@],$(RUNDIR),g' \ -e 's,[@]PERL[@],$(PERL),g' ro_script = sed "`printf '1a\\' && printf '\\n\# -*- buffer-read-only: t -*-'`" ro_man = printf '.\\" Local\040variables:\n.\\" buffer-read-only: t\n.\\" End:\n' +ro_c = echo '/* -*- mode: c; buffer-read-only: t -*- */' EXTRA_DIST += README.hwtables diff --git a/controller/controller.8.in b/controller/controller.8.in index 044125ba..f7f265c3 100644 --- a/controller/controller.8.in +++ b/controller/controller.8.in @@ -129,7 +129,7 @@ performance, so it should not be used in production. Causes a file (by default, \fBcontroller.pid\fR) to be created indicating the PID of the running process. If \fIpidfile\fR is not specified, or if it does not begin with \fB/\fR, then it is created in -\fB@rundir@\fR. +\fB@RUNDIR@\fR. .TP \fB-f\fR, \fB--force\fR diff --git a/include/automake.mk b/include/automake.mk index a86dcc0b..83f3b59e 100644 --- a/include/automake.mk +++ b/include/automake.mk @@ -5,6 +5,7 @@ noinst_HEADERS += \ include/daemon.h \ include/dhcp-client.h \ include/dhcp.h \ + include/dirs.h \ include/dynamic-string.h \ include/dpif.h \ include/fatal-signal.h \ diff --git a/include/dirs.h b/include/dirs.h new file mode 100644 index 00000000..36048cef --- /dev/null +++ b/include/dirs.h @@ -0,0 +1,40 @@ +/* Copyright (c) 2008 The Board of Trustees of The Leland Stanford + * Junior University + * + * We are making the OpenFlow specification and associated documentation + * (Software) available for public use and benefit with the expectation + * that others will use, modify and enhance the Software and contribute + * those enhancements back to the community. However, since we would + * like to make the Software available for broadest use, with as few + * restrictions as possible permission is hereby granted, free of + * charge, to any person obtaining a copy of this Software to deal in + * the Software under the copyrights without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * The name and trademarks of copyright holder(s) may NOT be used in + * advertising or publicity pertaining to the Software or any + * derivatives without specific, written prior permission. + */ + +#ifndef DIRS_H +#define DIRS_H 1 + +extern const char ofp_rundir[]; /* /usr/local/var/run */ +extern const char ofp_logdir[]; /* /usr/local/var/log */ + +#endif /* dirs.h */ diff --git a/lib/automake.mk b/lib/automake.mk index ee8eb348..be0f5f61 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -31,6 +31,7 @@ lib_libopenflow_a_SOURCES = \ lib/vconn-stream.c \ lib/vconn.c \ lib/vlog-socket.c \ + lib/dirs.c \ lib/vlog.c if HAVE_NETLINK @@ -58,3 +59,9 @@ EXTRA_DIST += \ lib/dh2048.pem \ lib/dh4096.pem \ lib/dhparams.h + +lib/dirs.c: Makefile + ($(ro_c) && \ + echo 'const char ofp_rundir[] = "@RUNDIR@";' && \ + echo 'const char ofp_logdir[] = "@LOGDIR@";') > lib/dirs.c.tmp + mv lib/dirs.c.tmp lib/dirs.c diff --git a/lib/daemon.c b/lib/daemon.c index f9bf5cef..8800d0d2 100644 --- a/lib/daemon.c +++ b/lib/daemon.c @@ -39,6 +39,7 @@ #include #include #include "fatal-signal.h" +#include "dirs.h" #include "util.h" #define THIS_MODULE VLM_daemon @@ -58,9 +59,9 @@ static bool force; char * make_pidfile_name(const char *name) { - return (!name ? xasprintf("%s/%s.pid", RUNDIR, program_name) + return (!name ? xasprintf("%s/%s.pid", ofp_rundir, program_name) : *name == '/' ? xstrdup(name) - : xasprintf("%s/%s", RUNDIR, name)); + : xasprintf("%s/%s", ofp_rundir, name)); } /* Sets up a following call to daemonize() to create a pidfile named 'name'. @@ -243,5 +244,5 @@ daemon_usage(void) " -D, --detach run in background as daemon\n" " -P, --pidfile[=FILE] create pidfile (default: %s/%s.pid)\n" " -f, --force with -P, start even if already running\n", - RUNDIR, program_name); + ofp_rundir, program_name); } diff --git a/m4/libopenflow.m4 b/m4/libopenflow.m4 index 4fa5b54e..c1787f4f 100644 --- a/m4/libopenflow.m4 +++ b/m4/libopenflow.m4 @@ -1,3 +1,5 @@ +# -*- autoconf -*- + # Copyright (c) 2008 The Board of Trustees of The Leland Stanford # Junior University # @@ -118,6 +120,35 @@ AC_DEFUN([OFP_CHECK_SOCKET_LIBS], [AC_CHECK_LIB([socket], [connect]) AC_SEARCH_LIBS([gethostbyname], [resolv], [RESOLVER_LIBS=-lresolv])]) +dnl Checks for the directory in which to store the PKI. +AC_DEFUN([OFP_CHECK_PKIDIR], + [AC_ARG_WITH( + [pkidir], + AC_HELP_STRING([--with-pkidir=DIR], + [PKI hierarchy directory [[DATADIR/openflow/pki]]]), + [PKIDIR=$withval], + [PKIDIR='${pkgdatadir}/pki']) + AC_SUBST([PKIDIR])]) + +dnl Checks for the directory in which to store pidfiles. +AC_DEFUN([OFP_CHECK_RUNDIR], + [AC_ARG_WITH( + [rundir], + AC_HELP_STRING([--with-rundir=DIR], + [directory used for pidfiles [[LOCALSTATEDIR/run]]]), + [RUNDIR=$withval], + [RUNDIR='${localstatedir}/run']) + AC_SUBST([RUNDIR])]) + +dnl Checks for the directory in which to store logs. +AC_DEFUN([OFP_CHECK_LOGDIR], + [AC_ARG_WITH( + [logdir], + AC_HELP_STRING([--with-logdir=DIR], + [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]), + [LOGDIR=$withval], + [LOGDIR='${localstatedir}/log/${PACKAGE}']) + AC_SUBST([LOGDIR])]) dnl Runs the checks required to include the headers in include/ and dnl link against lib/libopenflow.a. @@ -129,5 +160,8 @@ AC_DEFUN([OFP_CHECK_LIBOPENFLOW], AC_REQUIRE([OFP_CHECK_SNAT]) AC_REQUIRE([OFP_CHECK_FAULT_LIBS]) AC_REQUIRE([OFP_CHECK_SOCKET_LIBS]) + AC_REQUIRE([OFP_CHECK_PKIDIR]) + AC_REQUIRE([OFP_CHECK_RUNDIR]) + AC_REQUIRE([OFP_CHECK_LOGDIR]) AC_CHECK_FUNCS([strlcpy])]) diff --git a/secchan/secchan.8.in b/secchan/secchan.8.in index 5e887915..d7dd9b81 100644 --- a/secchan/secchan.8.in +++ b/secchan/secchan.8.in @@ -401,7 +401,7 @@ require the controller to send the CA certificate, but Causes a file (by default, \fBsecchan.pid\fR) to be created indicating the PID of the running process. If \fIpidfile\fR is not specified, or if it does not begin with \fB/\fR, then it is created in -\fB@rundir@\fR. +\fB@RUNDIR@\fR. .TP \fB-f\fR, \fB--force\fR diff --git a/switch/switch.8.in b/switch/switch.8.in index 6d1a33b4..4b3584e9 100644 --- a/switch/switch.8.in +++ b/switch/switch.8.in @@ -89,7 +89,7 @@ the switch is connected to a trustworthy controller. Causes a file (by default, \fBswitch.pid\fR) to be created indicating the PID of the running process. If \fIpidfile\fR is not specified, or if it does not begin with \fB/\fR, then it is created in -\fB@rundir@\fR. +\fB@RUNDIR@\fR. .TP \fB-f\fR, \fB--force\fR diff --git a/utilities/automake.mk b/utilities/automake.mk index 08bf61bb..e359d5fa 100644 --- a/utilities/automake.mk +++ b/utilities/automake.mk @@ -39,8 +39,6 @@ utilities_ofp_discover_LDADD = lib/libopenflow.a utilities_ofp_kill_SOURCES = utilities/ofp-kill.c utilities_ofp_kill_LDADD = lib/libopenflow.a -pkidir = $(pkgdatadir)/pki - utilities/ofp-pki: utilities/ofp-pki.in Makefile $(do_subst) < $(srcdir)/utilities/ofp-pki.in \ | $(ro_script) > utilities/ofp-pki diff --git a/utilities/ofp-discover.8.in b/utilities/ofp-discover.8.in index 772bccbd..e2ba8b2d 100644 --- a/utilities/ofp-discover.8.in +++ b/utilities/ofp-discover.8.in @@ -77,7 +77,7 @@ This option is mutually exclusive with \fB--exit-without-bind\fR and Causes a file (by default, \fBofp\-discover.pid\fR) to be created indicating the PID of the running process. If \fIpidfile\fR is not specified, or if it does not begin with \fB/\fR, then it is created in -\fB@rundir@\fR. +\fB@RUNDIR@\fR. The \fIpidfile\fR is created when \fBofp\-discover\fR detaches, so this this option has no effect when one of \fB--exit-without-bind\fR, diff --git a/utilities/ofp-discover.c b/utilities/ofp-discover.c index 4efaac71..d48f61ab 100644 --- a/utilities/ofp-discover.c +++ b/utilities/ofp-discover.c @@ -42,6 +42,7 @@ #include "daemon.h" #include "dhcp-client.h" #include "dhcp.h" +#include "dirs.h" #include "dynamic-string.h" #include "fatal-signal.h" #include "netdev.h" @@ -413,6 +414,6 @@ usage(void) " -v, --verbose set maximum verbosity level\n" " -h, --help display this help message\n" " -V, --version display version information\n", - program_name, program_name, RUNDIR, program_name); + program_name, program_name, ofp_rundir, program_name); exit(EXIT_SUCCESS); } diff --git a/utilities/ofp-kill.8.in b/utilities/ofp-kill.8.in index 122ff541..7b45bf0a 100644 --- a/utilities/ofp-kill.8.in +++ b/utilities/ofp-kill.8.in @@ -16,7 +16,7 @@ the PID of the process to kill as a text string. It then uses owns a lock on \fIpidfile\fR before it sends the signal. A \fIpidfile\fR whose name begins with \fB/\fR is used literally. -Otherwise, \fB@rundir@/\fR is prefixed. +Otherwise, \fB@RUNDIR@/\fR is prefixed. This program exists for use by \fBofp\-switch\-setup\fR, which cannot easily implement its functionality since Perl has no portable diff --git a/utilities/ofp-pki-cgi.in b/utilities/ofp-pki-cgi.in index 291352e1..837b3f92 100755 --- a/utilities/ofp-pki-cgi.in +++ b/utilities/ofp-pki-cgi.in @@ -9,7 +9,7 @@ $CGI::POST_MAX = 65536; # Limit POSTs to 64 kB. use strict; use warnings; -my $pkidir = '@pkidir@'; +my $pkidir = '@PKIDIR@'; my $q = new CGI; die unless $q->request_method() eq 'POST'; diff --git a/utilities/ofp-pki.8.in b/utilities/ofp-pki.8.in index 36803473..7242df56 100644 --- a/utilities/ofp-pki.8.in +++ b/utilities/ofp-pki.8.in @@ -67,7 +67,7 @@ administration: .TP \fBinit\fR -Initializes a new PKI (by default in directory \fB@pkidir@\fR) and populates +Initializes a new PKI (by default in directory \fB@PKIDIR@\fR) and populates it with a pair of certificate authorities for controllers and switches. @@ -115,7 +115,7 @@ bits in the generated RSA key. When DSA keys are used (as specified with \fB\-\^\-key=dsa\fR), \fBreq\fR needs access to the \fBdsaparam.pem\fR file created as part of the PKI hierarchy (but not to other files in that tree). By default, -\fBofp\-pki\fR looks for this file in \fB@pkidir@/dsaparam.pem\fR, but +\fBofp\-pki\fR looks for this file in \fB@PKIDIR@/dsaparam.pem\fR, but the \fB\-D\fR or \fB\-\^\-dsaparam\fR option (see below) may be used to specify an alternate location. @@ -288,7 +288,7 @@ Suppresses the interactive verification of fingerprints that the .TP \fB\-d\fR \fIdir\fR | \fB\-\^\-dir=\fR\fIdir\fR Specifies the location of the PKI hierarchy to be used or created by -the command (default: \fB@pkidir@\fR). All commands, except \fBreq\fR, +the command (default: \fB@PKIDIR@\fR). All commands, except \fBreq\fR, need access to a PKI hierarchy. .TP diff --git a/utilities/ofp-pki.in b/utilities/ofp-pki.in index 6f227d63..4a5466a8 100755 --- a/utilities/ofp-pki.in +++ b/utilities/ofp-pki.in @@ -1,6 +1,6 @@ #! /bin/sh -e -pkidir='@pkidir@' +pkidir='@PKIDIR@' command= prev= force=no