chiark / gitweb /
ensure tests avoid user config!
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 9 Dec 2007 19:17:30 +0000 (19:17 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 9 Dec 2007 19:17:30 +0000 (19:17 +0000)
clients/disorder.c
lib/configuration.c
lib/configuration.h
tests/queue.py

index 9513b05daf5f0dd62917d844da33d0e1aa8bc31d..6278295318c595b820031c56c1ff8a95625ac107 100644 (file)
@@ -62,6 +62,7 @@ static const struct option options[] = {
   { "config", required_argument, 0, 'c' },
   { "debug", no_argument, 0, 'd' },
   { "local", no_argument, 0, 'l' },
+  { "no-per-user-config", no_argument, 0, 'N' },
   { "help-commands", no_argument, 0, 'H' },
   { 0, 0, 0, 0 }
 };
@@ -543,7 +544,7 @@ int main(int argc, char **argv) {
   pcre_malloc = xmalloc;
   pcre_free = xfree;
   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
-  while((n = getopt_long(argc, argv, "hVc:dHl", options, 0)) >= 0) {
+  while((n = getopt_long(argc, argv, "hVc:dHlN", options, 0)) >= 0) {
     switch(n) {
     case 'h': help();
     case 'H': help_commands();
@@ -551,6 +552,7 @@ int main(int argc, char **argv) {
     case 'c': configfile = optarg; break;
     case 'd': debugging = 1; break;
     case 'l': local = 1; break;
+    case 'N': config_per_user = 0; break;
     default: fatal(0, "invalid option");
     }
   }
index 85e84a5b8ea3674bc170f95d0909d95a2126d78b..2dcf8f97e90f9712b80ac660cd9950b6791fe30d 100644 (file)
  */
 char *configfile;
 
+/** @brief Read user configuration
+ *
+ * If clear, the user-specific configuration is not read.
+ */
+int config_per_user = 1;
+
 /** @brief Config file parser state */
 struct config_state {
   /** @brief Filename */
@@ -1181,19 +1187,21 @@ int config_read(int server) {
     return -1;
   xfree(privconf);
   /* if there's a per-user system config file for this user, read it */
-  if(!(pw = getpwuid(getuid())))
-    fatal(0, "cannot determine our username");
-  if((privconf = config_usersysconf(pw))
-     && access(privconf, F_OK) == 0
-     && config_include(c, privconf))
+  if(config_per_user) {
+    if(!(pw = getpwuid(getuid())))
+      fatal(0, "cannot determine our username");
+    if((privconf = config_usersysconf(pw))
+       && access(privconf, F_OK) == 0
+       && config_include(c, privconf))
       return -1;
-  xfree(privconf);
-  /* if we have a password file, read it */
-  if((privconf = config_userconf(getenv("HOME"), pw))
-     && access(privconf, F_OK) == 0
-     && config_include(c, privconf))
-    return -1;
-  xfree(privconf);
+    xfree(privconf);
+    /* if we have a password file, read it */
+    if((privconf = config_userconf(getenv("HOME"), pw))
+       && access(privconf, F_OK) == 0
+       && config_include(c, privconf))
+      return -1;
+    xfree(privconf);
+  }
   /* install default namepart and transform settings */
   config_postdefaults(c, server);
   /* everything is good so we shall use the new config */
index 6618e1ad3a5c6babfadbe40664bda170913c8590..02c953a83fca8e8a7bc99a701b41074440fa76f9 100644 (file)
@@ -277,6 +277,7 @@ char *config_private(void);
 /* get the private config file */
 
 extern char *configfile;
+extern int config_per_user;
 
 #endif /* CONFIGURATION_H */
 
index 3be7c2a58536640199224e826d747d1864ebc2c9..b26bdf3102ca8c0517f19c8b6bc17af63ee1730e 100755 (executable)
@@ -28,7 +28,9 @@ def test():
     q = c.queue()
     assert len(q) == 10, "queue is at proper length"
     print " getting queue via disorder(1)"
-    q = dtest.command(["disorder", "--config", disorder._configfile, "queue"])
+    q = dtest.command(["disorder",
+                       "--config", disorder._configfile, "--no-per-user-config",
+                       "queue"])
     tracks = filter(lambda s: re.match("^track", s), q)
     assert len(tracks) == 10, "queue is at proper length"