man-db-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Man-db-devel] [PATCH] Use system defaults in absence of site configurat


From: Ikey Doherty
Subject: [Man-db-devel] [PATCH] Use system defaults in absence of site configuration
Date: Fri, 22 May 2015 14:41:49 +0100

From: Michael Ikey Doherty <address@hidden>

This enables man-db to work in a stateless manner, by providing the sane
default configuration in the system defaults directory, and a mechanism
in which site administrators can override the configuration locally with
the site configuration directory (/etc/)

Signed-off-by: Michael Ikey Doherty <address@hidden>
---
 configure.ac                      |  1 +
 m4/man-arg-default-config-file.m4 | 21 +++++++++++++++++++++
 src/Makefile.am                   | 11 ++++++-----
 src/manp.c                        | 18 +++++++++++++++---
 4 files changed, 43 insertions(+), 8 deletions(-)
 create mode 100644 m4/man-arg-default-config-file.m4

diff --git a/configure.ac b/configure.ac
index 0f555cf..6d32013 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,6 +30,7 @@ MAN_ARG_UNDOC
 MAN_ARG_DEVICE
 MAN_ARG_DB
 MAN_ARG_CONFIG_FILE
+MAN_ARG_DEFAULT_CONFIG_FILE
 MAN_ARG_SECTIONS
 MAN_ARG_AUTOMATIC_CREATE
 MAN_ARG_AUTOMATIC_UPDATE
diff --git a/m4/man-arg-default-config-file.m4 
b/m4/man-arg-default-config-file.m4
new file mode 100644
index 0000000..38ec52b
--- /dev/null
+++ b/m4/man-arg-default-config-file.m4
@@ -0,0 +1,21 @@
+# man-arg-config-file.m4 serial 1
+dnl MAN_ARG_DEFAULT_CONFIG_FILE
+dnl Add a --with-default-config-file option.
+
+AC_DEFUN([MAN_ARG_DEFAULT_CONFIG_FILE],
+[
+AC_ARG_WITH([default-config-file],
+[AS_HELP_STRING([--with-default-config-file=CF], [use config file CF 
[CF=DATADIR/defaults/mandb/man_db.conf]])],
+       [if test "$withval" = "yes" || test "$withval" = "no"
+        then
+               AC_MSG_ERROR([--with-default-config-file requires an argument])
+        else
+               default_config_file=$withval
+        fi],
+       [: ${default_config_file=\$\{datadir\}/defaults/mandb/man_db.conf}])
+default_config_file_basename=${withval##*/}
+default_config_file_dirname=`AS_DIRNAME(["$default_config_file"])`
+AC_SUBST([default_config_file])
+AC_SUBST([default_config_file_basename])
+AC_SUBST([default_config_file_dirname])
+])
diff --git a/src/Makefile.am b/src/Makefile.am
index d485ef4..18a84a5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -44,6 +44,7 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/lib \
        -I$(top_srcdir)/libdb \
        -DCONFIG_FILE=\"$(config_file)\" \
+       -DDEFAULT_CONFIG_FILE=\"$(default_config_file)\" \
        -DAPROPOS=\"$(bindir)/$(TRANS_APROPOS)\" \
        -DAPROPOS_NAME=\"$(TRANS_APROPOS)\" \
        -DMAN=\"$(bindir)/$(TRANS_MAN)\" \
@@ -184,12 +185,12 @@ install-exec-hook:
                $(LN_S) $(TRANS_WHATIS)$(EXEEXT) $(TRANS_APROPOS)$(EXEEXT)
 
 install-data-hook:
-       @if test -f $(DESTDIR)$(config_file); then \
-               echo "$(DESTDIR)$(config_file) already exists; overwrite 
manually if necessary"; \
+       @if test -f $(DESTDIR)$(default_config_file); then \
+               echo "$(DESTDIR)$(default_config_file) already exists; 
overwrite manually if necessary"; \
        else \
-               test -z "$(config_file_dirname)" || $(MKDIR_P) 
"$(DESTDIR)$(config_file_dirname)"; \
-               echo " $(INSTALL_DATA) man_db.conf $(DESTDIR)$(config_file)"; \
-               $(INSTALL_DATA) man_db.conf $(DESTDIR)$(config_file); \
+               test -z "$(default_config_file_dirname)" || $(MKDIR_P) 
"$(DESTDIR)$(default_config_file_dirname)"; \
+               echo " $(INSTALL_DATA) man_db.conf 
$(DESTDIR)$(default_config_file)"; \
+               $(INSTALL_DATA) man_db.conf $(DESTDIR)$(default_config_file); \
        fi
 
 uninstall-hook:
diff --git a/src/manp.c b/src/manp.c
index 75e43f2..6385821 100644
--- a/src/manp.c
+++ b/src/manp.c
@@ -866,16 +866,28 @@ void read_config_file (int optional)
        }
 
        if (getenv ("MAN_TEST_DISABLE_SYSTEM_CONFIG") == NULL) {
-               config = fopen (CONFIG_FILE, "r");
+               config = fopen (DEFAULT_CONFIG_FILE, "r");
                if (config == NULL) {
                        if (optional)
                                debug ("can't open %s; continuing anyway\n",
-                                      CONFIG_FILE);
+                                      DEFAULT_CONFIG_FILE);
                        else
                                error (FAIL, 0,
                                       _("can't open the manpath "
                                         "configuration file %s"),
-                                      CONFIG_FILE);
+                                      DEFAULT_CONFIG_FILE);
+               } else {
+                       debug ("From the config file %s:\n\n", 
DEFAULT_CONFIG_FILE);
+
+                       add_to_dirlist (config, 0);
+                       fclose (config);
+               }
+        /* site configuration */
+               config = fopen (CONFIG_FILE, "r");
+               if (config == NULL) {
+                       debug ("can't open %s; continuing anyway\n",
+                               CONFIG_FILE);
+
                } else {
                        debug ("From the config file %s:\n\n", CONFIG_FILE);
 
-- 
1.9.1

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]