netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [ebtables PATCH 2/3] Allow customizing lockfile location at configure time
Date: Tue, 19 Mar 2019 20:09:37 +0100	[thread overview]
Message-ID: <20190319190938.20751-3-phil@nwl.cc> (raw)
In-Reply-To: <20190319190938.20751-1-phil@nwl.cc>

Users may pass LOCKFILE=/some/path/to/file when calling configure to
make libebtc use that path for its lockfile.

To simplify things, drop LOCKDIR completely and instead call dirname()
when trying to create the parent directory.

Given that we always define LOCKFILE via compiler flag, drop the
fallback define from libebtc.c.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 Makefile.am  | 4 +---
 configure.ac | 3 +++
 libebtc.c    | 7 ++-----
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 59ae595ee16de..53fcbadbca7b4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,8 +5,6 @@
 PROGNAME = ${PACKAGE_NAME}
 PROGVERSION = ${PACKAGE_VERSION}
 PROGDATE = December\ 2011
-LOCKDIR = /var/lib/ebtables
-LOCKFILE = ${LOCKDIR}/lock
 INITDIR = /etc/rc.d/init.d
 initddir = ${INITDIR}
 sysconfigdir = ${sysconfdir}/sysconfig
@@ -21,7 +19,7 @@ AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_srcdir}/include \
 	-DPROGVERSION=\"${PACKAGE_VERSION}\" -DPROGNAME=\"${PACKAGE_NAME}\" \
 	-DPROGDATE=\"${PROGDATE}\" \
 	-D_PATH_ETHERTYPES=\"${sysconfdir}/ethertypes\" \
-	-DLOCKFILE=\"${LOCKFILE}\" -DLOCKDIR=\"${LOCKDIR}\" \
+	-DLOCKFILE=\"${LOCKFILE}\" \
 	-DEBTD_ARGC_MAX=${EBTD_ARGC_MAX} -DEBTD_CMDLINE_MAXLN=${EBTD_CMDLINE_MAXLN} \
 	-DEBTD_PIPE=\"${PIPE}\" -DEBTD_PIPE_DIR=\"${PIPE_DIR}\"
 AM_CFLAGS = ${regular_CFLAGS}
diff --git a/configure.ac b/configure.ac
index a3bc3c93a279f..00d97734ff9a9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -10,6 +10,9 @@ AC_DISABLE_STATIC
 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
 AM_PROG_LIBTOOL
 
+AC_ARG_VAR([LOCKFILE], [Custom libebtc lockfile path (default: /var/lib/ebtables/lock)])
+AS_IF([test "x$LOCKFILE" = x], [LOCKFILE="/var/lib/ebtables/lock"])
+
 regular_CFLAGS="-Wall -Wunused"
 regular_CPPFLAGS=""
 case "$host" in
diff --git a/libebtc.c b/libebtc.c
index 92fd76485c723..f2a2b500ea751 100644
--- a/libebtc.c
+++ b/libebtc.c
@@ -36,6 +36,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <errno.h>
+#include <libgen.h>
 
 static void decrease_chain_jumps(struct ebt_u_replace *replace);
 static int iterate_entries(struct ebt_u_replace *replace, int type);
@@ -134,10 +135,6 @@ void ebt_list_extensions()
 	}
 }
 
-#ifndef LOCKFILE
-#define LOCKDIR "/var/lib/ebtables"
-#define LOCKFILE LOCKDIR"/lock"
-#endif
 int use_lockfd;
 /* Returns 0 on success, -1 when the file is locked by another process
  * or -2 on any other error. */
@@ -148,7 +145,7 @@ static int lock_file()
 retry:
 	fd = open(LOCKFILE, O_CREAT, 00600);
 	if (fd < 0) {
-		if (try == 1 || mkdir(LOCKDIR, 00700))
+		if (try == 1 || mkdir(dirname(LOCKFILE), 00700))
 			return -2;
 		try = 1;
 		goto retry;
-- 
2.21.0


  parent reply	other threads:[~2019-03-20  7:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-19 19:09 [ebtables PATCH 0/3] Misc items found in Fedora package Phil Sutter
2019-03-19 19:09 ` [ebtables PATCH 1/3] extensions: Drop Makefile Phil Sutter
2019-03-19 19:09 ` Phil Sutter [this message]
2019-03-19 19:09 ` [ebtables PATCH 3/3] extensions: Add AUDIT target Phil Sutter
2019-03-19 19:44   ` Jan Engelhardt
2019-03-20  8:09     ` Phil Sutter
2019-04-03 17:48 ` [ebtables PATCH 0/3] Misc items found in Fedora package Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190319190938.20751-3-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).