Browse Source

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.
Guillem Jover 17 years ago
parent
commit
bbf6bc906c
10 changed files with 80 additions and 6 deletions
  1. 2 0
      debian/changelog
  2. 1 0
      debian/dpkg.install
  3. 1 0
      debian/dselect.install
  4. 5 0
      dselect/Makefile.am
  5. 56 0
      lib/dpkg/myopt.c
  6. 3 2
      man/dpkg.1
  7. 3 1
      man/dpkg.cfg.5
  8. 3 2
      man/dselect.1
  9. 3 1
      man/dselect.cfg.5
  10. 3 0
      src/Makefile.am

+ 2 - 0
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

+ 1 - 0
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

+ 1 - 0
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

+ 5 - 0
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

+ 56 - 0
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);

+ 3 - 2
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

+ 3 - 1
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

+ 3 - 2
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).

+ 3 - 1
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

+ 3 - 0
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