aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Barker <paul@paulbarker.me.uk>2014-06-06 11:32:47 +0000
committerPaul Barker <paul@paulbarker.me.uk>2014-06-11 18:38:50 +0000
commit0d1021294725561c4c135b91a0f24af2307781ed (patch)
treef93ce7b401dc50b2bb8b62f09be150a3e7529f16
parent8496491eb106c5684ec4627b641fe27e395b3963 (diff)
downloadopkg-0d1021294725561c4c135b91a0f24af2307781ed.tar.gz
opkg-0d1021294725561c4c135b91a0f24af2307781ed.tar.bz2
opkg-0d1021294725561c4c135b91a0f24af2307781ed.zip
opkg_conf: Make lock_file a runtime config option
The ./configure option '--with-opkglockfile' is dropped and OPKGLOCKFILE is no longer set at compile time. Instead the lock file path may be set using the lock_file option in a config file as these config files are parsed before the lock file is used. The default value is now given by OPKG_CONF_DEFAULT_LOCK_FILE and to comply with the FHS and avoid the requirement to create any directories which shouldn't already exist it is placed at '/var/run/opkg.lock'. The static variable lock_file is also moved into the opkg_config structure. Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
-rw-r--r--configure.ac18
-rw-r--r--libopkg/Makefile.am2
-rw-r--r--libopkg/opkg_conf.c55
-rw-r--r--libopkg/opkg_conf.h2
-rw-r--r--tests/regress/opk.py1
5 files changed, 36 insertions, 42 deletions
diff --git a/configure.ac b/configure.ac
index 195eba2..14af540 100644
--- a/configure.ac
+++ b/configure.ac
@@ -265,23 +265,6 @@ if test x$opkgetcdir = x; then
opkgetcdir=/etc
fi
-opkglockfile=
-AC_ARG_WITH(opkglockfile,
-[ --with-opkglockfile=FILE specifies the file used to make sure there is only
- one instance of opkg runnning.
- Defaults to ${opkglibdir}/opkg/lock, i.e.
- /usr/lib/opkg/lock ],
-[case "${withval}" in
-yes) AC_MSG_ERROR(bad value ${withval} given for opkg lock file ) ;;
-no) ;;
-*) opkglockfile=$with_opkglockfile ;;
-esac])
-
-# Default if empty
-if test x$opkglockfile = x; then
- opkglockfile=${opkglibdir}/opkg/lock
-fi
-
CLEAN_DATE=`date +"%B %Y" | tr -d '\n'`
AC_ARG_WITH(static-libopkg,
@@ -291,7 +274,6 @@ AM_CONDITIONAL(STATIC_LIBOPKG, test "x$static_libopkg" = "xyes")
AC_SUBST(opkglibdir)
AC_SUBST(opkgetcdir)
-AC_SUBST(opkglockfile)
AC_SUBST([CLEAN_DATE])
AC_OUTPUT(
diff --git a/libopkg/Makefile.am b/libopkg/Makefile.am
index b1800a3..5707351 100644
--- a/libopkg/Makefile.am
+++ b/libopkg/Makefile.am
@@ -1,7 +1,7 @@
AM_CFLAGS=-Wall -DHOST_CPU_STR=\"@host_cpu@\" -DLIBDIR=\"@libdir@\" \
-DOPKGLIBDIR=\"@opkglibdir@\" -DOPKGETCDIR=\"@opkgetcdir@\" \
- -DOPKGLOCKFILE=\"@opkglockfile@\" -DDATADIR=\"@datadir@\" \
+ -DDATADIR=\"@datadir@\" \
-I$(top_srcdir) $(LIBARCHIVE_CFLAGS) $(BIGENDIAN_CFLAGS) $(CURL_CFLAGS) \
$(GPGME_CFLAGS) $(GPGERR_CFLAGS) $(PATHFINDER_CFLAGS)
diff --git a/libopkg/opkg_conf.c b/libopkg/opkg_conf.c
index 2642f92..2a1d153 100644
--- a/libopkg/opkg_conf.c
+++ b/libopkg/opkg_conf.c
@@ -39,7 +39,6 @@
#include "xfuncs.h"
static int lock_fd;
-static char *lock_file = NULL;
static opkg_conf_t _conf;
opkg_conf_t *opkg_config = &_conf;
@@ -49,6 +48,7 @@ opkg_conf_t *opkg_config = &_conf;
*/
static opkg_option_t options[] = {
{ "cache_dir", OPKG_OPT_TYPE_STRING, &_conf.cache_dir},
+ { "lock_file", OPKG_OPT_TYPE_STRING, &_conf.lock_file},
{ "force_defaults", OPKG_OPT_TYPE_BOOL, &_conf.force_defaults },
{ "force_maintainer", OPKG_OPT_TYPE_BOOL, &_conf.force_maintainer },
{ "force_depends", OPKG_OPT_TYPE_BOOL, &_conf.force_depends },
@@ -579,22 +579,30 @@ opkg_conf_load(void)
globfree(&globbuf);
}
- if (opkg_config->offline_root)
- sprintf_alloc (&lock_file, "%s/%s", opkg_config->offline_root, OPKGLOCKFILE);
- else
- sprintf_alloc (&lock_file, "%s", OPKGLOCKFILE);
+ if (opkg_config->lock_file == NULL)
+ opkg_config->lock_file = xstrdup(OPKG_CONF_DEFAULT_LOCK_FILE);
+
+ if (opkg_config->offline_root) {
+ char *tmp;
- lock_fd = creat(lock_file, S_IRUSR | S_IWUSR | S_IRGRP);
+ sprintf_alloc(&tmp, "%s/%s", opkg_config->offline_root,
+ opkg_config->lock_file);
+ free(opkg_config->lock_file);
+ opkg_config->lock_file = tmp;
+ }
+
+ lock_fd = creat(opkg_config->lock_file, S_IRUSR | S_IWUSR | S_IRGRP);
if (lock_fd == -1) {
- opkg_perror(ERROR, "Could not create lock file %s", lock_file);
+ opkg_perror(ERROR, "Could not create lock file %s",
+ opkg_config->lock_file);
goto err2;
}
if (lockf(lock_fd, F_TLOCK, (off_t)0) == -1) {
- opkg_perror(ERROR, "Could not lock %s", lock_file);
+ opkg_perror(ERROR, "Could not lock %s", opkg_config->lock_file);
if (close(lock_fd) == -1)
opkg_perror(ERROR, "Couldn't close descriptor %d (%s)",
- lock_fd, lock_file);
+ lock_fd, opkg_config->lock_file);
lock_fd = -1;
goto err2;
}
@@ -679,18 +687,17 @@ err4:
opkg_perror(ERROR, "Couldn't remove dir %s", opkg_config->tmp_dir);
err3:
if (lockf(lock_fd, F_ULOCK, (off_t)0) == -1)
- opkg_perror(ERROR, "Couldn't unlock %s", lock_file);
+ opkg_perror(ERROR, "Couldn't unlock %s",
+ opkg_config->lock_file);
if (close(lock_fd) == -1)
opkg_perror(ERROR, "Couldn't close descriptor %d (%s)",
- lock_fd, lock_file);
- if (unlink(lock_file) == -1)
- opkg_perror(ERROR, "Couldn't unlink %s", lock_file);
+ lock_fd, opkg_config->lock_file);
+ if (unlink(opkg_config->lock_file) == -1)
+ opkg_perror(ERROR, "Couldn't unlink %s",
+ opkg_config->lock_file);
err2:
- if (lock_file) {
- free(lock_file);
- lock_file = NULL;
- }
+ free(opkg_config->lock_file);
err1:
pkg_src_list_deinit(&opkg_config->pkg_src_list);
pkg_src_list_deinit(&opkg_config->dist_src_list);
@@ -767,18 +774,20 @@ opkg_conf_deinit(void)
if (lock_fd != -1) {
if (lockf(lock_fd, F_ULOCK, (off_t)0) == -1)
- opkg_perror(ERROR, "Couldn't unlock %s", lock_file);
+ opkg_perror(ERROR, "Couldn't unlock %s",
+ opkg_config->lock_file);
if (close(lock_fd) == -1)
opkg_perror(ERROR, "Couldn't close descriptor %d (%s)",
- lock_fd, lock_file);
+ lock_fd, opkg_config->lock_file);
}
- if (lock_file) {
- if (unlink(lock_file) == -1)
- opkg_perror(ERROR, "Couldn't unlink %s", lock_file);
+ if (opkg_config->lock_file) {
+ if (unlink(opkg_config->lock_file) == -1)
+ opkg_perror(ERROR, "Couldn't unlink %s",
+ opkg_config->lock_file);
- free(lock_file);
+ free(opkg_config->lock_file);
}
}
diff --git a/libopkg/opkg_conf.h b/libopkg/opkg_conf.h
index 803c91a..1b93de4 100644
--- a/libopkg/opkg_conf.h
+++ b/libopkg/opkg_conf.h
@@ -37,6 +37,7 @@ extern "C" {
#define OPKG_CONF_CACHE_DIR OPKG_STATE_DIR_PREFIX "/cache"
#define OPKG_CONF_DEFAULT_CONF_FILE_DIR OPKGETCDIR"/opkg"
+#define OPKG_CONF_DEFAULT_LOCK_FILE "/var/run/opkg.lock"
/* In case the config file defines no dest */
#define OPKG_CONF_DEFAULT_DEST_NAME "root"
@@ -60,6 +61,7 @@ typedef struct opkg_conf {
char *tmp_dir;
char *lists_dir;
char *cache_dir;
+ char *lock_file;
unsigned int pfm; /* package field mask */
diff --git a/tests/regress/opk.py b/tests/regress/opk.py
index dd4328d..1855f76 100644
--- a/tests/regress/opk.py
+++ b/tests/regress/opk.py
@@ -127,6 +127,7 @@ def regress_init():
os.makedirs("{}/usr/lib/opkg".format(cfg.offline_root))
os.makedirs("{}/etc/opkg".format(cfg.offline_root))
+ os.makedirs("{}/var/run".format(cfg.offline_root))
f = open("{}/etc/opkg/opkg.conf".format(cfg.offline_root), "w")
f.write("arch all 1\n")