The following commit has been merged in the master branch:
commit bbf6bc906ca53d45a96b9860f541c6973edd4541
Author: Guillem Jover <[email protected]>
Date:   Fri Aug 21 07:09:57 2009 +0200

    Add support for config.d style directory fragment loading
    
    Open the system config.d directory before the system configuration file,
    /etc/dpkg/dpkg.cfg.d for dpkg and /etc/dpkg/dselect.cfg.d for dselect,
    and load fragments with filenames matching the run-parts standard Debian
    constraints (^[a-zA-Z0-9_-]+$).
    
    This will allow external programs to drop configuration fragments on
    those directories.

diff --git a/debian/changelog b/debian/changelog
index 4d6e0de..82bcec0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -31,6 +31,8 @@ dpkg (1.15.4) UNRELEASED; urgency=low
   * Remove double slash in database path visible to the user in some error
     conditions.
   * Stop macthing sparc64-*-* GNU triplets with sparc Debian architecture.
+  * Add support for config.d style directories in dpkg and dselect,
+    (/etc/dpkg/dpkg.cfg.d and /etc/dpkg/dselect.cfg.d respectively).
 
   [ Raphael Hertzog ]
   * Replace install-info by a wrapper around GNU's install-info. The wrapper
diff --git a/debian/dpkg.install b/debian/dpkg.install
index 654c95f..30bf847 100644
--- a/debian/dpkg.install
+++ b/debian/dpkg.install
@@ -1,6 +1,7 @@
 ../dpkg.cfg etc/dpkg
 ../archtable usr/share/dpkg
 
+etc/dpkg/dpkg.cfg.d
 etc/alternatives
 usr/bin/dpkg
 usr/bin/dpkg-deb
diff --git a/debian/dselect.install b/debian/dselect.install
index b276c73..d1d7c5d 100644
--- a/debian/dselect.install
+++ b/debian/dselect.install
@@ -1,5 +1,6 @@
 ../dselect.cfg etc/dpkg
 
+etc/dpkg/dselect.cfg.d
 usr/bin/dselect
 usr/lib/dpkg/methods
 usr/share/locale/*/LC_MESSAGES/dselect.mo
diff --git a/dselect/Makefile.am b/dselect/Makefile.am
index 4bf7ce3..0845668 100644
--- a/dselect/Makefile.am
+++ b/dselect/Makefile.am
@@ -3,6 +3,8 @@
 SUBDIRS = methods po
 
 localedir = $(datadir)/locale
+pkgconfdir = $(sysconfdir)/@PACKAGE@
+
 AM_CPPFLAGS = \
        -DLOCALEDIR=\"$(localedir)\" \
        -DADMINDIR=\"$(admindir)\" -DLIBDIR=\"$(pkglibdir)\" \
@@ -58,3 +60,6 @@ curkeys.h: $(srcdir)/keyoverride $(srcdir)/mkcurkeys.pl
                echo "can't find curses file"; exit 1; \
        fi; \
        perl $(srcdir)/mkcurkeys.pl $< $$cursesfile >$@
+
+install-data-local:
+       $(mkdir_p) $(DESTDIR)$(pkgconfdir)/dselect.cfg.d
diff --git a/lib/dpkg/myopt.c b/lib/dpkg/myopt.c
index 454d3b4..c4b8080 100644
--- a/lib/dpkg/myopt.c
+++ b/lib/dpkg/myopt.c
@@ -27,6 +27,7 @@
 #include <string.h>
 #include <errno.h>
 #include <ctype.h>
+#include <dirent.h>
 #include <stdarg.h>
 #include <stdlib.h>
 
@@ -110,9 +111,64 @@ void myfileopt(const char* fn, const struct cmdinfo* 
cmdinfos) {
   if (fclose(file)) ohshite(_("error closing configuration file `%.255s'"), 
fn);
 }
 
+static int
+valid_config_filename(const struct dirent *dent)
+{
+  const char *c;
+
+  if (dent->d_name[0] == '.')
+    return 0;
+
+  for (c = dent->d_name; *c; c++)
+    if (!isalnum(*c) && *c != '_' && *c != '-')
+      return 0;
+
+  if (*c == '\0')
+    return 1;
+  else
+    return 0;
+}
+
+static void
+load_config_dir(const char *prog, const struct cmdinfo* cmdinfos)
+{
+  char *dirname;
+  struct dirent **dlist;
+  int dlist_n, i;
+
+  dirname = m_malloc(strlen(CONFIGDIR "/.cfg.d") + strlen(prog) + 1);
+  sprintf(dirname, "%s/%s.cfg.d", CONFIGDIR, prog);
+
+  dlist_n = scandir(dirname, &dlist, valid_config_filename, alphasort);
+  if (dlist_n < 0) {
+    if (errno == ENOENT) {
+      free(dirname);
+      return;
+    } else
+      ohshite(_("error opening configuration directory '%s'"), dirname);
+  }
+
+  for (i = 0; i < dlist_n; i++) {
+    char *filename;
+
+    filename = m_malloc(strlen(dirname) + 1 + strlen(dlist[i]->d_name) + 1);
+    sprintf(filename, "%s/%s", dirname, dlist[i]->d_name);
+
+    myfileopt(filename, cmdinfos);
+
+    free(filename);
+  }
+
+  free(dirname);
+  free(dlist);
+}
+
 void loadcfgfile(const char *prog, const struct cmdinfo* cmdinfos) {
   char *home, *file;
   int l1, l2;
+
+  load_config_dir(prog, cmdinfos);
+
   l1 = strlen(CONFIGDIR "/.cfg") + strlen(prog);
   file = m_malloc(l1 + 1);
   sprintf(file, CONFIGDIR "/%s.cfg", prog);
diff --git a/man/dpkg.1 b/man/dpkg.1
index 58a0915..7c47593 100644
--- a/man/dpkg.1
+++ b/man/dpkg.1
@@ -1,4 +1,4 @@
-.TH dpkg 1 "2008-04-06" "Debian Project" "dpkg suite"
+.TH dpkg 1 "2009-08-20" "Debian Project" "dpkg suite"
 .SH NAME
 dpkg \- package manager for Debian
 .
@@ -315,7 +315,8 @@ See \fBdpkg\-query\fP(1) for more information about the 
following actions.
 .
 .SH OPTIONS
 All options can be specified both on the command line and in the \fBdpkg\fP
-configuration file \fI/etc/dpkg/dpkg.cfg\fP. Each line in the configuration
+configuration file \fI/etc/dpkg/dpkg.cfg\fP or the files on the configuration
+directory \fI/etc/dpkg/dpkg.cfg.d/\fP. Each line in the configuration
 file is either an option (exactly the same as the command line option but
 without leading dashes) or a comment (if it starts with a \fB#\fR).
 .br
diff --git a/man/dpkg.cfg.5 b/man/dpkg.cfg.5
index 51c7412..9cbd0d7 100644
--- a/man/dpkg.cfg.5
+++ b/man/dpkg.cfg.5
@@ -1,4 +1,4 @@
-.TH dpkg.cfg 5 "2006-02-28" "Debian Project" "dpkg suite"
+.TH dpkg.cfg 5 "2009-08-20" "Debian Project" "dpkg suite"
 .SH NAME
 dpkg.cfg \- dpkg configuration file
 .
@@ -10,6 +10,8 @@ here. Comments are allowed by starting a line with a hash sign
 ("\fB#\fR").
 .
 .SH FILES
+.I /etc/dpkg/dpkg.cfg.d/[0-9a-zA-Z_-]*
+.br
 .I /etc/dpkg/dpkg.cfg
 .br
 .I ~/.dpkg.cfg
diff --git a/man/dselect.1 b/man/dselect.1
index 8154a2e..6bceb2d 100644
--- a/man/dselect.1
+++ b/man/dselect.1
@@ -1,4 +1,4 @@
-.TH dselect 1 "2006-02-28" "Debian Project" "Debian"
+.TH dselect 1 "2009-08-20" "Debian Project" "Debian"
 .SH NAME
 dselect \- Debian package management frontend
 .
@@ -44,7 +44,8 @@ of \fBdselect\fP or show additional information about the 
program.
 .
 .SH OPTIONS
 All options can be specified both on the commandline and in the \fBdselect\fP
-configuration file \fI/etc/dpkg/dselect.cfg\fP. Each line in the
+configuration file \fI/etc/dpkg/dselect.cfg\fP or the files on the
+configuration directory \fI/etc/dpkg/dpkg.cfg.d/\fP. Each line in the
 configuration file is either an option (exactly the same as the
 commandline option but without leading dashes) or a comment (if it starts
 with a \fB#\fR).
diff --git a/man/dselect.cfg.5 b/man/dselect.cfg.5
index b51e971..bbfe222 100644
--- a/man/dselect.cfg.5
+++ b/man/dselect.cfg.5
@@ -1,4 +1,4 @@
-.TH dselect.cfg 5 "2006-02-28" "Debian Project" "dpkg suite"
+.TH dselect.cfg 5 "2009-08-20" "Debian Project" "dpkg suite"
 .SH NAME
 dselect.cfg \- dselect configuration file
 .
@@ -10,6 +10,8 @@ here. Comments are allowed by starting a line with a hash sign
 ("\fB#\fR").
 .
 .SH FILES
+.I /etc/dpkg/dselect.cfg.d/[0-9a-zA-Z_-]*
+.br
 .I /etc/dpkg/dselect.cfg
 .br
 .I ~/.dselect.cfg
diff --git a/src/Makefile.am b/src/Makefile.am
index 1f754aa..0270f3d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,8 @@
 ## Process this file with automake to produce Makefile.in
 
 localedir = $(datadir)/locale
+pkgconfdir = $(sysconfdir)/@PACKAGE@
+
 AM_CPPFLAGS = \
        -DLOCALEDIR=\"$(localedir)\" \
        -DADMINDIR=\"$(admindir)\" \
@@ -61,6 +63,7 @@ dpkg_trigger_LDADD = \
        $(LIBINTL)
 
 install-data-local:
+       $(mkdir_p) $(DESTDIR)$(pkgconfdir)/dpkg.cfg.d
        $(mkdir_p) $(DESTDIR)$(admindir)/alternatives
        $(mkdir_p) $(DESTDIR)$(admindir)/info
        $(mkdir_p) $(DESTDIR)$(admindir)/updates

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to