From 63ad732fd2031c8775ddf98cd538c8759c4537df Mon Sep 17 00:00:00 2001 Message-Id: <63ad732fd2031c8775ddf98cd538c8759c4537df.1714973409.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 9 Dec 2007 19:17:30 +0000 Subject: [PATCH 1/1] ensure tests avoid user config! Organization: Straylight/Edgeware From: Richard Kettlewell --- clients/disorder.c | 4 +++- lib/configuration.c | 32 ++++++++++++++++++++------------ lib/configuration.h | 1 + tests/queue.py | 4 +++- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/clients/disorder.c b/clients/disorder.c index 9513b05..6278295 100644 --- a/clients/disorder.c +++ b/clients/disorder.c @@ -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"); } } diff --git a/lib/configuration.c b/lib/configuration.c index 85e84a5..2dcf8f9 100644 --- a/lib/configuration.c +++ b/lib/configuration.c @@ -60,6 +60,12 @@ */ 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 */ diff --git a/lib/configuration.h b/lib/configuration.h index 6618e1a..02c953a 100644 --- a/lib/configuration.h +++ b/lib/configuration.h @@ -277,6 +277,7 @@ char *config_private(void); /* get the private config file */ extern char *configfile; +extern int config_per_user; #endif /* CONFIGURATION_H */ diff --git a/tests/queue.py b/tests/queue.py index 3be7c2a..b26bdf3 100755 --- a/tests/queue.py +++ b/tests/queue.py @@ -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" -- [mdw]