From ddbf6040e308bd5f3c5d6ac6445f5a0e58735d07 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 22 Oct 2008 14:53:25 -0700 Subject: [PATCH] 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. --- Makefile.am | 11 +++------- controller/controller.8.in | 2 +- include/automake.mk | 1 + include/dirs.h | 40 +++++++++++++++++++++++++++++++++++++ lib/automake.mk | 7 +++++++ lib/daemon.c | 7 ++++--- m4/libopenflow.m4 | 34 +++++++++++++++++++++++++++++++ secchan/secchan.8.in | 2 +- switch/switch.8.in | 2 +- utilities/automake.mk | 2 -- utilities/ofp-discover.8.in | 2 +- utilities/ofp-discover.c | 3 ++- utilities/ofp-kill.8.in | 2 +- utilities/ofp-pki-cgi.in | 2 +- utilities/ofp-pki.8.in | 6 +++--- utilities/ofp-pki.in | 2 +- 16 files changed, 101 insertions(+), 24 deletions(-) create mode 100644 include/dirs.h diff --git a/Makefile.am b/Makefile.am index 398dcb00c..bb69db7a0 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 044125baa..f7f265c35 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 a86dcc0bd..83f3b59e9 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 000000000..36048cef9 --- /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 ee8eb348d..be0f5f617 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 f9bf5cef9..8800d0d2c 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 4fa5b54ed..c1787f4fa 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 5e887915b..d7dd9b810 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 6d1a33b4f..4b3584e9a 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 08bf61bb5..e359d5fa8 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 772bccbd6..e2ba8b2d5 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 4efaac718..d48f61abc 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 122ff5414..7b45bf0a7 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 291352e1c..837b3f92b 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 36803473f..7242df561 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 6f227d63b..4a5466a8f 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 -- 2.43.0