Quellcode durchsuchen

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 vor 17 Jahren
Ursprung
Commit
bbf6bc906c
10 geänderte Dateien mit 80 neuen und 6 gelöschten Zeilen
  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
   * Remove double slash in database path visible to the user in some error
     conditions.
     conditions.
   * Stop macthing sparc64-*-* GNU triplets with sparc Debian architecture.
   * 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 ]
   [ Raphael Hertzog ]
   * Replace install-info by a wrapper around GNU's install-info. The wrapper
   * 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
 ../dpkg.cfg etc/dpkg
 ../archtable usr/share/dpkg
 ../archtable usr/share/dpkg
 
 
+etc/dpkg/dpkg.cfg.d
 etc/alternatives
 etc/alternatives
 usr/bin/dpkg
 usr/bin/dpkg
 usr/bin/dpkg-deb
 usr/bin/dpkg-deb

+ 1 - 0
debian/dselect.install

@@ -1,5 +1,6 @@
 ../dselect.cfg etc/dpkg
 ../dselect.cfg etc/dpkg
 
 
+etc/dpkg/dselect.cfg.d
 usr/bin/dselect
 usr/bin/dselect
 usr/lib/dpkg/methods
 usr/lib/dpkg/methods
 usr/share/locale/*/LC_MESSAGES/dselect.mo
 usr/share/locale/*/LC_MESSAGES/dselect.mo

+ 5 - 0
dselect/Makefile.am

@@ -3,6 +3,8 @@
 SUBDIRS = methods po
 SUBDIRS = methods po
 
 
 localedir = $(datadir)/locale
 localedir = $(datadir)/locale
+pkgconfdir = $(sysconfdir)/@PACKAGE@
+
 AM_CPPFLAGS = \
 AM_CPPFLAGS = \
 	-DLOCALEDIR=\"$(localedir)\" \
 	-DLOCALEDIR=\"$(localedir)\" \
 	-DADMINDIR=\"$(admindir)\" -DLIBDIR=\"$(pkglibdir)\" \
 	-DADMINDIR=\"$(admindir)\" -DLIBDIR=\"$(pkglibdir)\" \
@@ -58,3 +60,6 @@ curkeys.h: $(srcdir)/keyoverride $(srcdir)/mkcurkeys.pl
 		echo "can't find curses file"; exit 1; \
 		echo "can't find curses file"; exit 1; \
 	fi; \
 	fi; \
 	perl $(srcdir)/mkcurkeys.pl $< $$cursesfile >$@
 	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 <string.h>
 #include <errno.h>
 #include <errno.h>
 #include <ctype.h>
 #include <ctype.h>
+#include <dirent.h>
 #include <stdarg.h>
 #include <stdarg.h>
 #include <stdlib.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);
   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) {
 void loadcfgfile(const char *prog, const struct cmdinfo* cmdinfos) {
   char *home, *file;
   char *home, *file;
   int l1, l2;
   int l1, l2;
+
+  load_config_dir(prog, cmdinfos);
+
   l1 = strlen(CONFIGDIR "/.cfg") + strlen(prog);
   l1 = strlen(CONFIGDIR "/.cfg") + strlen(prog);
   file = m_malloc(l1 + 1);
   file = m_malloc(l1 + 1);
   sprintf(file, CONFIGDIR "/%s.cfg", prog);
   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
 .SH NAME
 dpkg \- package manager for Debian
 dpkg \- package manager for Debian
 .
 .
@@ -315,7 +315,8 @@ See \fBdpkg\-query\fP(1) for more information about the following actions.
 .
 .
 .SH OPTIONS
 .SH OPTIONS
 All options can be specified both on the command line and in the \fBdpkg\fP
 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
 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).
 without leading dashes) or a comment (if it starts with a \fB#\fR).
 .br
 .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
 .SH NAME
 dpkg.cfg \- dpkg configuration file
 dpkg.cfg \- dpkg configuration file
 .
 .
@@ -10,6 +10,8 @@ here. Comments are allowed by starting a line with a hash sign
 ("\fB#\fR").
 ("\fB#\fR").
 .
 .
 .SH FILES
 .SH FILES
+.I /etc/dpkg/dpkg.cfg.d/[0-9a-zA-Z_-]*
+.br
 .I /etc/dpkg/dpkg.cfg
 .I /etc/dpkg/dpkg.cfg
 .br
 .br
 .I ~/.dpkg.cfg
 .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
 .SH NAME
 dselect \- Debian package management frontend
 dselect \- Debian package management frontend
 .
 .
@@ -44,7 +44,8 @@ of \fBdselect\fP or show additional information about the program.
 .
 .
 .SH OPTIONS
 .SH OPTIONS
 All options can be specified both on the commandline and in the \fBdselect\fP
 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
 configuration file is either an option (exactly the same as the
 commandline option but without leading dashes) or a comment (if it starts
 commandline option but without leading dashes) or a comment (if it starts
 with a \fB#\fR).
 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
 .SH NAME
 dselect.cfg \- dselect configuration file
 dselect.cfg \- dselect configuration file
 .
 .
@@ -10,6 +10,8 @@ here. Comments are allowed by starting a line with a hash sign
 ("\fB#\fR").
 ("\fB#\fR").
 .
 .
 .SH FILES
 .SH FILES
+.I /etc/dpkg/dselect.cfg.d/[0-9a-zA-Z_-]*
+.br
 .I /etc/dpkg/dselect.cfg
 .I /etc/dpkg/dselect.cfg
 .br
 .br
 .I ~/.dselect.cfg
 .I ~/.dselect.cfg

+ 3 - 0
src/Makefile.am

@@ -1,6 +1,8 @@
 ## Process this file with automake to produce Makefile.in
 ## Process this file with automake to produce Makefile.in
 
 
 localedir = $(datadir)/locale
 localedir = $(datadir)/locale
+pkgconfdir = $(sysconfdir)/@PACKAGE@
+
 AM_CPPFLAGS = \
 AM_CPPFLAGS = \
 	-DLOCALEDIR=\"$(localedir)\" \
 	-DLOCALEDIR=\"$(localedir)\" \
 	-DADMINDIR=\"$(admindir)\" \
 	-DADMINDIR=\"$(admindir)\" \
@@ -61,6 +63,7 @@ dpkg_trigger_LDADD = \
 	$(LIBINTL)
 	$(LIBINTL)
 
 
 install-data-local:
 install-data-local:
+	$(mkdir_p) $(DESTDIR)$(pkgconfdir)/dpkg.cfg.d
 	$(mkdir_p) $(DESTDIR)$(admindir)/alternatives
 	$(mkdir_p) $(DESTDIR)$(admindir)/alternatives
 	$(mkdir_p) $(DESTDIR)$(admindir)/info
 	$(mkdir_p) $(DESTDIR)$(admindir)/info
 	$(mkdir_p) $(DESTDIR)$(admindir)/updates
 	$(mkdir_p) $(DESTDIR)$(admindir)/updates