chiark / gitweb /
sync with disorder.dev
authorRichard Kettlewell <rjk@greenend.org.uk>
Mon, 19 Nov 2007 21:28:19 +0000 (21:28 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Mon, 19 Nov 2007 21:28:19 +0000 (21:28 +0000)
14 files changed:
doc/disorder_config.5.in
python/disorder.py.in
server/deadlock.c
server/normalize.c
server/play.c
server/rescan.c
server/setup.c
server/speaker.c
server/stats.c
server/trackdb.c
tests/Makefile.am
tests/alltests
tests/dtest.py
tests/version.py [new file with mode: 0755]

index 743bb51b2b4f1ea7ef36ed835a6b06435bfa7fd8..0b1535f6e74221c10b06adcd69ddf47406735ec6 100644 (file)
@@ -119,7 +119,7 @@ The home directory for state files.  Defaults to
 .IR pkgstatedir .
 The server will create this directory on startup if it does not exist.
 .TP
-.B plugin \fIPATH\fR
+.B plugins \fIPATH\fR
 Adds a directory to the plugin path.  (This is also used by the web
 interface.)
 .IP
index eb5850700fbd45a4889889836db4de64e4fbe9e8..5becda13e6dd771e5afdc8a4643e51f1ad4ed733 100644 (file)
@@ -53,6 +53,7 @@ import locale
 
 _configfile = "pkgconfdir/config"
 _dbhome = "pkgstatedir"
+_userconf = True
 
 # various regexps we'll use
 _ws = re.compile(r"^[ \t\n\r]+")
@@ -291,7 +292,7 @@ class client:
     self._readfile(_configfile)
     if os.path.exists(privconf):
       self._readfile(privconf)
-    if os.path.exists(passfile):
+    if os.path.exists(passfile) and _userconf:
       self._readfile(passfile)
     self.state = 'disconnected'
 
index 82e796d695a99c982a1fd9ed290055956802bf28..cda6d0d51d47142715fe264ee537ba3f7c38f16c 100644 (file)
@@ -48,6 +48,8 @@ static const struct option options[] = {
   { "config", required_argument, 0, 'c' },
   { "debug", no_argument, 0, 'd' },
   { "no-debug", no_argument, 0, 'D' },
+  { "syslog", no_argument, 0, 's' },
+  { "no-syslog", no_argument, 0, 'S' },
   { 0, 0, 0, 0 }
 };
 
@@ -60,6 +62,7 @@ static void help(void) {
          "  --version, -V           Display version number\n"
          "  --config PATH, -c PATH  Set configuration file\n"
          "  --debug, -d             Turn on debugging\n"
+          "  --[no-]syslog           Force logging\n"
           "\n"
           "Deadlock manager for DisOrder.  Not intended to be run\n"
           "directly.\n");
@@ -75,22 +78,23 @@ static void version(void) {
 }
 
 int main(int argc, char **argv) {
-  int n, err, aborted;
+  int n, err, aborted, logsyslog = !isatty(2);
 
   set_progname(argv);
   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
-  while((n = getopt_long(argc, argv, "hVc:dD", options, 0)) >= 0) {
+  while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
     switch(n) {
     case 'h': help();
     case 'V': version();
     case 'c': configfile = optarg; break;
     case 'd': debugging = 1; break;
     case 'D': debugging = 0; break;
+    case 'S': logsyslog = 0; break;
+    case 's': logsyslog = 1; break;
     default: fatal(0, "invalid option");
     }
   }
-  /* if stderr is a TTY then log there, otherwise to syslog */
-  if(!isatty(2)) {
+  if(logsyslog) {
     openlog(progname, LOG_PID, LOG_DAEMON);
     log_default = &log_syslog;
   }
index f8c7df7f800ff4be791921d94d4ccf9c68e7eb7f..085d4dfb126cc3ff06e9b5f61d4f2417b071a44d 100644 (file)
@@ -28,6 +28,7 @@
 #include <config.h>
 #include "types.h"
 
+#include <getopt.h>
 #include <locale.h>
 #include <errno.h>
 #include <unistd.h>
 #include "log.h"
 #include "configuration.h"
 #include "speaker-protocol.h"
+#include "defs.h"
+
+static const struct option options[] = {
+  { "help", no_argument, 0, 'h' },
+  { "version", no_argument, 0, 'V' },
+  { "config", required_argument, 0, 'c' },
+  { "debug", no_argument, 0, 'd' },
+  { "no-debug", no_argument, 0, 'D' },
+  { "syslog", no_argument, 0, 's' },
+  { "no-syslog", no_argument, 0, 'S' },
+  { 0, 0, 0, 0 }
+};
+
+/* display usage message and terminate */
+static void help(void) {
+  xprintf("Usage:\n"
+         "  disorder-normalize [OPTIONS]\n"
+         "Options:\n"
+         "  --help, -h              Display usage message\n"
+         "  --version, -V           Display version number\n"
+         "  --config PATH, -c PATH  Set configuration file\n"
+         "  --debug, -d             Turn on debugging\n"
+          "  --[no-]syslog           Force logging\n"
+          "\n"
+          "Audio format normalizer for DisOrder.  Not intended to be run\n"
+          "directly.\n");
+  xfclose(stdout);
+  exit(0);
+}
+
+/* display version number and terminate */
+static void version(void) {
+  xprintf("disorder-normalize version %s\n", disorder_version_string);
+  xfclose(stdout);
+  exit(0);
+}
 
 /** @brief Copy bytes from one file descriptor to another
  * @param infd File descriptor read from
@@ -111,17 +148,27 @@ static void soxargs(const char ***pp, char **qq,
 
 int main(int argc, char attribute((unused)) **argv) {
   struct stream_header header, latest_format;
-  int n, p[2], outfd = -1;
+  int n, p[2], outfd = -1, logsyslog = !isatty(2);
   pid_t pid = -1;
 
   set_progname(argv);
   if(!setlocale(LC_CTYPE, ""))
     fatal(errno, "error calling setlocale");
-  if(argc > 1)
-    fatal(0, "not intended to be invoked by users");
+  while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
+    switch(n) {
+    case 'h': help();
+    case 'V': version();
+    case 'c': configfile = optarg; break;
+    case 'd': debugging = 1; break;
+    case 'D': debugging = 0; break;
+    case 'S': logsyslog = 0; break;
+    case 's': logsyslog = 1; break;
+    default: fatal(0, "invalid option");
+    }
+  }
   if(config_read(1))
     fatal(0, "cannot read configuration");
-  if(!isatty(2)) {
+  if(logsyslog) {
     openlog(progname, LOG_PID, LOG_DAEMON);
     log_default = &log_syslog;
   }
index 04d7d0117d54f2508560fa3ba1fa0b19e2940827..bd27474ce40a17ebd3ca23e4a672b4a25cbdfb21 100644 (file)
@@ -127,16 +127,12 @@ static int speaker_readable(ev_source *ev, int fd,
 }
 
 void speaker_setup(ev_source *ev) {
-  int sp[2], lfd;
+  int sp[2];
   pid_t pid;
   struct speaker_message sm;
 
   if(socketpair(PF_UNIX, SOCK_DGRAM, 0, sp) < 0)
     fatal(errno, "error calling socketpair");
-  if(!isatty(2))
-    lfd = logfd(ev, SPEAKER);
-  else
-    lfd = -1;
   if(!(pid = xfork())) {
     exitfn = _exit;
     ev_signal_atfork(ev);
@@ -144,17 +140,17 @@ void speaker_setup(ev_source *ev) {
     xdup2(sp[0], 1);
     xclose(sp[0]);
     xclose(sp[1]);
-    if(lfd != -1) {
-      xdup2(lfd, 2);
-      xclose(lfd);
-    }
     signal(SIGPIPE, SIG_DFL);
 #if 0
     execlp("valgrind", "valgrind", SPEAKER, "--config", configfile,
-          debugging ? "--debug" : "--no-debug", (char *)0);
+          debugging ? "--debug" : "--no-debug",
+          log_default == &log_syslog ? "--syslog" : "--no-syslog",
+          (char *)0);
 #else
     execlp(SPEAKER, SPEAKER, "--config", configfile,
-          debugging ? "--debug" : "--no-debug", (char *)0);
+          debugging ? "--debug" : "--no-debug",
+          log_default == &log_syslog ? "--syslog" : "--no-syslog",
+          (char *)0);
 #endif
     fatal(errno, "error invoking %s", SPEAKER);
   }
@@ -424,7 +420,11 @@ static int start(ev_source *ev,
            speaker_send(speaker_fd, &sm);
            D(("sent SM_PLAY for %s", sm.id));
          }
-         execlp("disorder-normalize", "disorder-normalize", (char *)0);
+         /* TODO stderr shouldn't be redirected for disorder-normalize
+          * (but it should be for play_track() */
+         execlp("disorder-normalize", "disorder-normalize",
+                log_default == &log_syslog ? "--syslog" : "--no-syslog",
+                (char *)0);
          fatal(errno, "executing disorder-normalize");
          /* end of the innermost fork */
        }
index aaa5f93604bedb26fc35f5f0358d6833c9c4f45b..890e3fe9a6b746369d541697e42470632b78b700 100644 (file)
@@ -59,6 +59,8 @@ static const struct option options[] = {
   { "config", required_argument, 0, 'c' },
   { "debug", no_argument, 0, 'd' },
   { "no-debug", no_argument, 0, 'D' },
+  { "syslog", no_argument, 0, 's' },
+  { "no-syslog", no_argument, 0, 'S' },
   { 0, 0, 0, 0 }
 };
 
@@ -71,6 +73,7 @@ static void help(void) {
          "  --version, -V           Display version number\n"
          "  --config PATH, -c PATH  Set configuration file\n"
          "  --debug, -d             Turn on debugging\n"
+          "  --[no-]syslog           Force logging\n"
           "\n"
           "Rescanner for DisOrder.  Not intended to be run\n"
           "directly.\n");
@@ -320,24 +323,25 @@ static void expire_noticed(void) {
 }
 
 int main(int argc, char **argv) {
-  int n;
+  int n, logsyslog = !isatty(2);
   struct sigaction sa;
   
   set_progname(argv);
   mem_init();
   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
-  while((n = getopt_long(argc, argv, "hVc:dD", options, 0)) >= 0) {
+  while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
     switch(n) {
     case 'h': help();
     case 'V': version();
     case 'c': configfile = optarg; break;
     case 'd': debugging = 1; break;
     case 'D': debugging = 0; break;
+    case 'S': logsyslog = 0; break;
+    case 's': logsyslog = 1; break;
     default: fatal(0, "invalid option");
     }
   }
-  /* If stderr is a TTY then log there, otherwise to syslog. */
-  if(!isatty(2)) {
+  if(logsyslog) {
     openlog(progname, LOG_PID, LOG_DAEMON);
     log_default = &log_syslog;
   }
index 47cbc873ee6e57966658ab2f5ca2293d7d82a34a..4ccb00e802afd419af3be666de1136eaa82dcf8c 100644 (file)
@@ -66,8 +66,10 @@ void make_root_login(void) {
   gcry_randomize(pwbin, sizeof pwbin, GCRY_STRONG_RANDOM);
   pwhex = hex(pwbin, sizeof pwbin);
   /* Create the file */
-  if((fd = open(privconfignew, O_WRONLY|O_CREAT, 0600)) < 0)
-    fatal(errno, "error creating %s", privconfignew);
+  if((fd = open(privconfignew, O_WRONLY|O_CREAT, 0600)) < 0) {
+    error(errno, "error creating %s", privconfignew);
+    return;                             /* not fatal! */
+  }
   /* Fix permissions */
   if(pw) {
     if(fchown(fd, 0, pw->pw_gid) < 0)
index bdebbbdd464ae504f7adc34ae7c710696a07c508..55dde7ee9bbf2572da6e317bf9e2ecfb378982cb 100644 (file)
@@ -117,6 +117,8 @@ static const struct option options[] = {
   { "config", required_argument, 0, 'c' },
   { "debug", no_argument, 0, 'd' },
   { "no-debug", no_argument, 0, 'D' },
+  { "syslog", no_argument, 0, 's' },
+  { "no-syslog", no_argument, 0, 'S' },
   { 0, 0, 0, 0 }
 };
 
@@ -129,6 +131,7 @@ static void help(void) {
          "  --version, -V           Display version number\n"
          "  --config PATH, -c PATH  Set configuration file\n"
          "  --debug, -d             Turn on debugging\n"
+          "  --[no-]syslog           Force logging\n"
           "\n"
           "Speaker process for DisOrder.  Not intended to be run\n"
           "directly.\n");
@@ -582,7 +585,7 @@ static void mainloop(void) {
 }
 
 int main(int argc, char **argv) {
-  int n;
+  int n, logsyslog = !isatty(2);
   struct sockaddr_un addr;
   static const int one = 1;
   struct speaker_message sm;
@@ -590,19 +593,20 @@ int main(int argc, char **argv) {
 
   set_progname(argv);
   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
-  while((n = getopt_long(argc, argv, "hVc:dD", options, 0)) >= 0) {
+  while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
     switch(n) {
     case 'h': help();
     case 'V': version();
     case 'c': configfile = optarg; break;
     case 'd': debugging = 1; break;
     case 'D': debugging = 0; break;
+    case 'S': logsyslog = 0; break;
+    case 's': logsyslog = 1; break;
     default: fatal(0, "invalid option");
     }
   }
   if((d = getenv("DISORDER_DEBUG_SPEAKER"))) debugging = atoi(d);
-  /* If stderr is a TTY then log there, otherwise to syslog. */
-  if(!isatty(2)) {
+  if(logsyslog) {
     openlog(progname, LOG_PID, LOG_DAEMON);
     log_default = &log_syslog;
   }
index d125caf8e3ca1b9f6110c3970d20515d71561ed8..f23ecf9a815a67c18994add4b0dad4c8a72e36c1 100644 (file)
@@ -26,6 +26,8 @@
 #include <errno.h>
 #include <pcre.h>
 #include <getopt.h>
+#include <syslog.h>
+#include <unistd.h>
 
 #include "defs.h"
 #include "mem.h"
@@ -40,6 +42,8 @@ static const struct option options[] = {
   { "config", required_argument, 0, 'c' },
   { "debug", no_argument, 0, 'd' },
   { "no-debug", no_argument, 0, 'D' },
+  { "syslog", no_argument, 0, 's' },
+  { "no-syslog", no_argument, 0, 'S' },
   { 0, 0, 0, 0 }
 };
 
@@ -52,6 +56,7 @@ static void help(void) {
          "  --version, -V            Display version number\n"
          "  --config PATH, -c PATH   Set configuration file\n"
          "  --[no-]debug, -d         Turn on (off) debugging\n"
+          "  --[no-]syslog            Force logging\n"
          "\n"
          "Generate DisOrder database statistics.\n");
   xfclose(stdout);
@@ -66,22 +71,28 @@ static void version(void) {
 }
 
 int main(int argc, char **argv) {
-  int n;
+  int n, logsyslog = !isatty(2);
   char **stats;
 
   set_progname(argv);
   mem_init();
   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
-  while((n = getopt_long(argc, argv, "hVc:dD", options, 0)) >= 0) {
+  while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
     switch(n) {
     case 'h': help();
     case 'V': version();
     case 'c': configfile = optarg; break;
     case 'd': debugging = 1; break;
     case 'D': debugging = 0; break;
+    case 'S': logsyslog = 0; break;
+    case 's': logsyslog = 1; break;
     default: fatal(0, "invalid option");
     }
   }
+  if(logsyslog) {
+    openlog(progname, LOG_PID, LOG_DAEMON);
+    log_default = &log_syslog;
+  }
   if(config_read(0))
     fatal(0, "cannot read configuration");
   trackdb_init(0);
index 34311ebc27e214053cf4402865df9f1cfc8e98ed..8cfd71f76f7b4b72d5c594eeae4937d6f251fee9 100644 (file)
@@ -157,22 +157,12 @@ static int reap_db_deadlock(ev_source attribute((unused)) *ev,
 static pid_t subprogram(ev_source *ev, const char *prog,
                         int outputfd) {
   pid_t pid;
-  int lfd;
 
   /* If we're in the background then trap subprocess stdout/stderr */
-  if(!isatty(2))
-    lfd = logfd(ev, prog);
-  else
-    lfd = -1;
   if(!(pid = xfork())) {
     exitfn = _exit;
     ev_signal_atfork(ev);
     signal(SIGPIPE, SIG_DFL);
-    if(lfd != -1) {
-      xdup2(lfd, 1);
-      xdup2(lfd, 2);
-      xclose(lfd);
-    }
     if(outputfd != -1) {
       xdup2(outputfd, 1);
       xclose(outputfd);
@@ -182,10 +172,10 @@ static pid_t subprogram(ev_source *ev, const char *prog,
     setpriority(PRIO_PROCESS, 0, 0);
     execlp(prog, prog, "--config", configfile,
            debugging ? "--debug" : "--no-debug",
+           log_default == &log_syslog ? "--syslog" : "--no-syslog",
            (char *)0);
     fatal(errno, "error invoking %s", prog);
   }
-  if(lfd != -1) xclose(lfd);
   return pid;
 }
 
index a99e2b80c19ac5f9b26ce7a4712bb5fdf5ed3a20..645dd5416ae9386e1b47fde480dd501d1249db2b 100644 (file)
@@ -19,9 +19,9 @@
 #
 
 check:
-       PATH=../server:$$PATH \
+       PATH=`pwd`/../server:`pwd`/..clients:$$PATH \
        PYTHONPATH=../python \
                topsrcdir=${top_srcdir} \
                ${PYTHON} ${srcdir}/alltests
 
-EXTRA_DIST=alltests dtest.py nothing.py
+EXTRA_DIST=alltests dtest.py nothing.py version.py
index fe0f3836860acc290d18586bacd7e2611aa21e00..c8f04c7574acd07f0d8f7614fd9c270c69f1fda8 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 import dtest
 
-tests = ["nothing"]
+tests = ["nothing", "version"]
 
 for test in tests:
     print "Test '%s'" % test
index 3d70924e288050be31986ae19e5b54a4cb5691fc..2bc834a1672ffae530cd7a36e067ddae1fac7a6f 100644 (file)
@@ -2,7 +2,7 @@
 
 """Utility module used by tests"""
 
-import os,os.path,subprocess,sys
+import os,os.path,subprocess,sys,disorder
 
 def copyfile(a,b):
     """copyfile(A, B)
@@ -13,7 +13,7 @@ def maketrack(s):
     """maketrack(S)
 
 Make track with relative path S exist"""
-    trackpath = "%s/%s" % (testroot, s)
+    trackpath = "%s/tracks/%s" % (testroot, s)
     trackdir = os.path.dirname(trackpath)
     if not os.path.exists(trackdir):
         os.makedirs(trackdir)
@@ -64,6 +64,8 @@ Start the daemon for test called TEST."""
                                "--foreground",
                                "--config", "%s/config" % testroot],
                               stderr=errs)
+    disorder._configfile = "%s/config" % testroot
+    disorder._userconf = False
 
 def stop():
     """stop()
@@ -72,6 +74,7 @@ Stop the daemon if it has not stopped already"""
     global daemon
     rc = daemon.poll()
     if rc == None:
+        print " stopping daemon"
         os.kill(daemon.pid, 15)
         rc = daemon.wait()
     print " daemon has stopped"
@@ -85,13 +88,14 @@ def run(test, setup=None, report=True, name=None):
     setup()
     start(name)
     try:
-        test()
-    except AssertionError, e:
-        global failures
-        failures += 1
-        print e
-        
-    stop()
+        try:
+            test()
+        except AssertionError, e:
+            global failures
+            failures += 1
+            print e
+    finally:
+        stop()
     if report:
         if failures:
             print " FAILED"
@@ -132,6 +136,18 @@ stopword 1 2 3 4 5 6 7 8 9
 stopword 11 12 13 14 15 16 17 18 19 20
 stopword 21 22 23 24 25 26 27 28 29 30
 stopword the a an and to too in on of we i am as im for is
+username fred
+password fredpass
+allow fred fredpass
+plugins ../plugins
+player *.mp3 execraw disorder-decode
+player *.ogg execraw disorder-decode
+player *.wav execraw disorder-decode
+player *.flac execraw disorder-decode
+tracklength *.mp3 disorder-tracklength
+tracklength *.ogg disorder-tracklength
+tracklength *.wav disorder-tracklength
+tracklength *.flac disorder-tracklength
 """ % (testroot, testroot, testroot, testroot))
 copyfile("%s/sounds/scratch.ogg" % topsrcdir,
          "%s/scratch.ogg" % testroot)
diff --git a/tests/version.py b/tests/version.py
new file mode 100755 (executable)
index 0000000..3566867
--- /dev/null
@@ -0,0 +1,12 @@
+#! /usr/bin/env python
+import dtest,time,disorder
+
+def test():
+    """Ask the server its version number"""
+    time.sleep(2)                       # give the daemon a chance to start up
+    c = disorder.client()
+    v = c.version()
+    print "Server version: %s" % v
+
+if __name__ == '__main__':
+    dtest.run(test)