Blame SOURCES/0038-Allow-customizing-lockfile-location-at-configure-tim.patch

05e71a
From f45756c1ca3b54e8bd45b40b809bd1a8d3cedfdb Mon Sep 17 00:00:00 2001
05e71a
From: Phil Sutter <phil@nwl.cc>
05e71a
Date: Tue, 19 Mar 2019 20:09:37 +0100
05e71a
Subject: [PATCH] Allow customizing lockfile location at configure time
05e71a
05e71a
Users may pass LOCKFILE=/some/path/to/file when calling configure to
05e71a
make libebtc use that path for its lockfile.
05e71a
05e71a
To simplify things, drop LOCKDIR completely and instead call dirname()
05e71a
when trying to create the parent directory.
05e71a
05e71a
Given that we always define LOCKFILE via compiler flag, drop the
05e71a
fallback define from libebtc.c.
05e71a
05e71a
Signed-off-by: Phil Sutter <phil@nwl.cc>
05e71a
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
05e71a
Signed-off-by: Phil Sutter <psutter@redhat.com>
05e71a
---
05e71a
 Makefile.am  | 4 +---
05e71a
 configure.ac | 3 +++
05e71a
 libebtc.c    | 7 ++-----
05e71a
 3 files changed, 6 insertions(+), 8 deletions(-)
05e71a
05e71a
diff --git a/Makefile.am b/Makefile.am
05e71a
index 59ae595ee16de..53fcbadbca7b4 100644
05e71a
--- a/Makefile.am
05e71a
+++ b/Makefile.am
05e71a
@@ -5,8 +5,6 @@
05e71a
 PROGNAME = ${PACKAGE_NAME}
05e71a
 PROGVERSION = ${PACKAGE_VERSION}
05e71a
 PROGDATE = December\ 2011
05e71a
-LOCKDIR = /var/lib/ebtables
05e71a
-LOCKFILE = ${LOCKDIR}/lock
05e71a
 INITDIR = /etc/rc.d/init.d
05e71a
 initddir = ${INITDIR}
05e71a
 sysconfigdir = ${sysconfdir}/sysconfig
05e71a
@@ -21,7 +19,7 @@ AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_srcdir}/include \
05e71a
 	-DPROGVERSION=\"${PACKAGE_VERSION}\" -DPROGNAME=\"${PACKAGE_NAME}\" \
05e71a
 	-DPROGDATE=\"${PROGDATE}\" \
05e71a
 	-D_PATH_ETHERTYPES=\"${sysconfdir}/ethertypes\" \
05e71a
-	-DLOCKFILE=\"${LOCKFILE}\" -DLOCKDIR=\"${LOCKDIR}\" \
05e71a
+	-DLOCKFILE=\"${LOCKFILE}\" \
05e71a
 	-DEBTD_ARGC_MAX=${EBTD_ARGC_MAX} -DEBTD_CMDLINE_MAXLN=${EBTD_CMDLINE_MAXLN} \
05e71a
 	-DEBTD_PIPE=\"${PIPE}\" -DEBTD_PIPE_DIR=\"${PIPE_DIR}\"
05e71a
 AM_CFLAGS = ${regular_CFLAGS}
05e71a
diff --git a/configure.ac b/configure.ac
05e71a
index a3bc3c93a279f..00d97734ff9a9 100644
05e71a
--- a/configure.ac
05e71a
+++ b/configure.ac
05e71a
@@ -10,6 +10,9 @@ AC_DISABLE_STATIC
05e71a
 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
05e71a
 AM_PROG_LIBTOOL
05e71a
 
05e71a
+AC_ARG_VAR([LOCKFILE], [Custom libebtc lockfile path (default: /var/lib/ebtables/lock)])
05e71a
+AS_IF([test "x$LOCKFILE" = x], [LOCKFILE="/var/lib/ebtables/lock"])
05e71a
+
05e71a
 regular_CFLAGS="-Wall -Wunused"
05e71a
 regular_CPPFLAGS=""
05e71a
 case "$host" in
05e71a
diff --git a/libebtc.c b/libebtc.c
05e71a
index 92fd76485c723..f2a2b500ea751 100644
05e71a
--- a/libebtc.c
05e71a
+++ b/libebtc.c
05e71a
@@ -36,6 +36,7 @@
05e71a
 #include <sys/stat.h>
05e71a
 #include <sys/types.h>
05e71a
 #include <errno.h>
05e71a
+#include <libgen.h>
05e71a
 
05e71a
 static void decrease_chain_jumps(struct ebt_u_replace *replace);
05e71a
 static int iterate_entries(struct ebt_u_replace *replace, int type);
05e71a
@@ -134,10 +135,6 @@ void ebt_list_extensions()
05e71a
 	}
05e71a
 }
05e71a
 
05e71a
-#ifndef LOCKFILE
05e71a
-#define LOCKDIR "/var/lib/ebtables"
05e71a
-#define LOCKFILE LOCKDIR"/lock"
05e71a
-#endif
05e71a
 int use_lockfd;
05e71a
 /* Returns 0 on success, -1 when the file is locked by another process
05e71a
  * or -2 on any other error. */
05e71a
@@ -148,7 +145,7 @@ static int lock_file()
05e71a
 retry:
05e71a
 	fd = open(LOCKFILE, O_CREAT, 00600);
05e71a
 	if (fd < 0) {
05e71a
-		if (try == 1 || mkdir(LOCKDIR, 00700))
05e71a
+		if (try == 1 || mkdir(dirname(LOCKFILE), 00700))
05e71a
 			return -2;
05e71a
 		try = 1;
05e71a
 		goto retry;
05e71a
-- 
05e71a
2.21.0
05e71a