chiark / gitweb /
server subprocesses should log to the same place the server does
[disorder] / server / speaker.c
index 1e3a059ca552ecea68833f6ccf1080f9d2cb3a40..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");
@@ -372,11 +375,17 @@ int addfd(int fd, int events) {
 
 /** @brief Table of speaker backends */
 static const struct speaker_backend *backends[] = {
-#if API_ALSA
+#if HAVE_ALSA_ASOUNDLIB_H
   &alsa_backend,
 #endif
   &command_backend,
   &network_backend,
+#if HAVE_COREAUDIO_AUDIOHARDWARE_H
+  &coreaudio_backend,
+#endif
+#if HAVE_SYS_SOUNDCARD_H
+  &oss_backend,
+#endif
   0
 };
 
@@ -426,7 +435,7 @@ static void mainloop(void) {
        * instead, but the post-poll code will cope even if it's
        * device_closed. */
       if(device_state == device_open)
-        backend->beforepoll();
+        backend->beforepoll(&timeout);
     }
     /* If any other tracks don't have a full buffer, try to read sample data
      * from them.  We do this last of all, so that if we run out of slots,
@@ -469,7 +478,8 @@ static void mainloop(void) {
       uint32_t l;
       char id[24];
 
-      if((fd = accept(listenfd, &addr, &addrlen)) >= 0) {
+      if((fd = accept(listenfd, (struct sockaddr *)&addr, &addrlen)) >= 0) {
+        blocking(fd);
         if(read(fd, &l, sizeof l) < 4) {
           error(errno, "reading length from inbound connection");
           xclose(fd);
@@ -575,25 +585,28 @@ 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;
+  const char *d;
 
   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(getenv("DISORDER_DEBUG_SPEAKER")) debugging = 1;
-  /* If stderr is a TTY then log there, otherwise to syslog. */
-  if(!isatty(2)) {
+  if((d = getenv("DISORDER_DEBUG_SPEAKER"))) debugging = atoi(d);
+  if(logsyslog) {
     openlog(progname, LOG_PID, LOG_DAEMON);
     log_default = &log_syslog;
   }
@@ -627,11 +640,14 @@ int main(int argc, char **argv) {
   if(unlink(addr.sun_path) < 0 && errno != ENOENT)
     error(errno, "removing %s", addr.sun_path);
   xsetsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one);
-  if(bind(listenfd, &addr, sizeof addr) < 0)
+  if(bind(listenfd, (const struct sockaddr *)&addr, sizeof addr) < 0)
     fatal(errno, "error binding socket to %s", addr.sun_path);
   xlisten(listenfd, 128);
   nonblock(listenfd);
   info("listening on %s", addr.sun_path);
+  memset(&sm, 0, sizeof sm);
+  sm.type = SM_READY;
+  speaker_send(1, &sm);
   mainloop();
   info("stopped (parent terminated)");
   exit(0);