source: roaraudio/roard/roard.c @ 2265:69f3bc9da749

Last change on this file since 2265:69f3bc9da749 was 2264:b83ab846836d, checked in by phi, 15 years ago

FILTER streams allways need to be /sync/

File size: 31.9 KB
RevLine 
[0]1//roard.c:
2
[668]3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
[0]25#include "roard.h"
26
[1494]27#ifdef ROAR_SUPPORT_LISTEN
[60]28char * server = ROAR_DEFAULT_SOCK_GLOBAL; // global server address
[1494]29#endif
[60]30
[2104]31#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_FS_POSIX)
32#define SUPPORT_PIDFILE
33char * pidfile = NULL;
34#endif
35
[1503]36#ifdef ROAR_HAVE_MAIN_ARGS
[0]37void usage (void) {
38 printf("Usage: roard [OPTIONS]...\n\n");
39
[68]40 printf("Misc Options:\n\n");
41 printf(
[775]42        " --daemon              - Bring the server into background after init\n"
[71]43        " --terminate           - Terminate after last client quited\n"
[2109]44        " --start               - No op parameter (starting roard is default operation)\n"
[274]45        " --restart             - Trys to stop an old instance and start a new with new settings\n"
[2109]46        " --stop                - Stops a running roard (provide --pidfile!)\n"
47        " --shutdown            - Terminates a running roard (provide --pidfile!)\n"
[276]48        " --realtime            - Trys to get realtime priority,\n"
49        "                         give multible times for being more realtime\n"
[444]50        " --chroot DIR          - chroots to the given dir\n"
51        " --setgid              - GroupID to the audio group as specified via -G\n"
52        " --setuid              - UserID to the audio user as specified via -U\n"
[905]53        " --sysclocksync        - calculate exact sample rate using the system clock\n"
[2017]54        " --location  LOC       - Set lion readable location of server\n"
[2104]55#ifdef SUPPORT_PIDFILE
56        " --pidfile PIDFILE     - Write a pidfile at PIDFILE\n"
57#endif
[68]58       );
59
60 printf("\nAudio Options:\n\n");
[0]61 printf(
62        " -R  --rate   RATE     - Set server rate\n"
63        " -B  --bits   BITS     - Set server bits\n"
64        " -C  --chans  CHANNELS - Set server channels\n"
65       );
66
[1923]67 printf("\nDriver Options: (obsolete, do not use, Use Ouput Options)\n\n");
[974]68 printf(" -d  --driver DRV      - Set the driver (default: %s)\n", ROAR_DRIVER_DEFAULT);
[0]69 printf(" -D  --device DEV      - Set the device\n");
70 printf(" -dO OPTS              - Set output options\n");
[973]71 printf(" --list-driver         - List all drivers\n");
[0]72
[932]73 printf("\nOutput Options:\n\n");
[974]74 printf(" -o  --odriver DRV     - Set the driver, use '--list-driver' to get a list\n");
[932]75 printf(" -O  --odevice DEV     - Set the device\n");
76 printf(" -oO OPTS              - Set output options\n");
77 printf(" -oN                   - Adds another output\n");
[961]78 printf(" -oP                   - Mark output as primary\n");
[932]79
[0]80 printf("\nSource Options:\n\n");
81 printf(" -s  --source DRV      - Use DRV as input driver\n"
82        " -S           DEV      - Use DEV as input device\n"
83        " -sO          OPTS     - Use OPTS as input options\n"
[1512]84        " -sN                   - Adds another source\n"
[0]85        " -sP                   - Make souce as primary\n"
86       );
87
[280]88 printf("\nCodec Filter Options:\n\n");
89 printf(" --list-cf             - List all codec filter\n"
90       );
[0]91
[1923]92 printf("\nMIDI Options:\n\n");
[1924]93 printf(" --midi-no-console     - Disable console based MIDI synth\n"
94        " --midi-console DEV    - Set device for MIDI console\n"
95       );
[1923]96
97 printf("\nLight Control Options:\n\n");
98 printf(" --light-channels NUM  - Sets the number of channels for Light control (default: %i)\n",
99                                  LIGHT_CHANNELS_DEFAULT
100       );
101
[0]102 printf("\nServer Options:\n\n");
103 printf(" -t  --tcp             - Use TCP listen socket\n"
104        " -u  --unix            - Use UNIX Domain listen socket (default)\n"
[508]105#ifdef ROAR_HAVE_LIBDNET
106        " -n  --decnet          - use DECnet listen socket\n"
107#endif
[518]108        " -4                    - Use IPv4 connections (implies -t)\n"
109#ifdef PF_INET6
110        " -6                    - Use IPv6 connections (implies -t)\n"
111#endif
112#ifdef IPV6_ADDRFORM
113        " -64                   - Try to downgrade sockets from IPv6 into IPv4,\n"
114        "                         this is normaly not usefull.\n"
115#endif
[0]116        " -p  --port            - TCP Port to bind to\n"
117        " -b  --bind            - IP/Hostname to bind to\n"
[1115]118        "     --sock            - Filename for UNIX Domain Socket\n"
[1993]119#ifdef ROAR_HAVE_LIBSLP
120        "     --slp             - Enable OpenSLP support\n"
121#endif
[450]122        " -G  GROUP             - Sets the group for the UNIX Domain Socket, (default: %s)\n"
[60]123        "                         You need the permittions to change the GID\n"
[444]124        " -U  USER              - Sets the user for the UNIX Domain Socket, (default: do not set)\n"
125        "                         You need the permittions to change the UID (normaly only root has)\n"
[548]126        " --no-listen           - Do not listen for new clients\n"
127        "                         (only usefull for relaing, impleys --terminate)\n"
[274]128        " --client-fh           - Comunicate with a client over this handle\n"
[501]129        "                         (only usefull for relaing)\n"
[920]130        " --close-fh            - Closes the given fh\n"
131        " --standby             - Start in standby state\n"
132        " --auto-standby        - Automatical goes into standby if there are no streams\n",
[450]133        ROAR_DEFAULT_SOCKGRP
[0]134       );
135// printf("\n Options:\n\n");
136 printf("\n");
137}
[1503]138#endif
[0]139
[2109]140int restart_server (char * server, int terminate) {
[579]141 struct roar_connection con;
[2111]142#ifdef ROAR_HAVE_KILL
143 char buf[80];
144 ssize_t l;
145 struct roar_vio_calls fh;
146 pid_t pid;
147 int ok;
148
149 if ( pidfile != NULL ) {
150  if ( roar_vio_open_file(&fh, pidfile, O_RDONLY, 0644) == -1 ) {
151   ROAR_WARN("restart_server(*): Can not read pidfile: %s", pidfile);
152  } else {
153   l = roar_vio_read(&fh, buf, 80);
154   roar_vio_close(&fh);
155   if ( l > 0 ) {
156    buf[l-1] = 0;
157    buf[79]  = 0;
158    pid = atoi(buf);
159    if ( terminate ) {
[2113]160     ok = kill(pid, SIGUSR1);
[2111]161    } else {
162     ok = kill(pid, SIGINT);
163    }
164    if ( ok == 0 ) {
165     return 0;
166    } else {
167     ROAR_WARN("restart_server(*): Can not kill roard by pidfile");
168    }
169   } else {
170    ROAR_WARN("restart_server(*): Can not find a PID in the pidfile");
171   }
172  }
173 }
174#endif
[2109]175
[579]176 if ( roar_connect(&con, server) == -1 ) {
177  return -1;
178 }
179
[2109]180 if ( roar_terminate(&con, terminate) == -1 ) {
[579]181  return -1;
182 }
183
184 return roar_disconnect(&con);
185}
186
[444]187#define R_SETUID 1
188#define R_SETGID 2
189
[1609]190int init_config (void) {
191 int i;
192
193 memset(g_config, 0, sizeof(struct roard_config));
194
195 for (i = 0; i < ROAR_DIR_DIRIDS; i++) {
196  g_config->streams[i].mixer_channels = 1;
197  g_config->streams[i].mixer.rpg_mul  = 1;
198  g_config->streams[i].mixer.rpg_div  = 1;
199  g_config->streams[i].mixer.scale    = 65535;
200  g_config->streams[i].mixer.mixer[0] = g_config->streams[i].mixer.scale;
201 }
202
[2264]203 g_config->streams[ROAR_DIR_FILTER  ].flags = ROAR_FLAG_SYNC;
[1899]204 g_config->streams[ROAR_DIR_MIDI_OUT].flags = ROAR_FLAG_SYNC;
[2160]205 g_config->streams[ROAR_DIR_BIDIR   ].flags = ROAR_FLAG_ANTIECHO;
[1899]206
[2017]207 g_config->location = "***default***";
208
[1609]209 return 0;
210}
211
[1145]212int add_output (char * drv, char * dev, char * opts, int prim, int count) {
[933]213 int stream;
214 struct roar_stream * s;
215 struct roar_stream_server * ss;
[938]216 char * k, * v;
[1208]217#ifdef ROAR_DRIVER_CODEC
218 char * to_free = NULL;
219#endif
[938]220 int codec;
[1926]221 int sync = 0, f_mmap = 0;
[1522]222 int32_t blocks = -1, blocksize = -1;
[1920]223 int dir = ROAR_DIR_OUTPUT;
[1991]224 int error = 0;
225 // DMX:
226 int32_t channel  = -1;
227 int32_t universe = -1;
228 uint16_t tu16;
[2085]229 float q = -32e6;
[933]230
[938]231 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
[933]232
[1145]233 if ( drv == NULL && count == 0 ) {
234  drv  = ROAR_DRIVER_DEFAULT;
235  prim = 1;
236  sync = 1;
[1208]237
238#ifdef ROAR_DRIVER_CODEC
239  if ( opts == NULL ) {
240   opts = to_free = strdup("codec=" ROAR_DRIVER_CODEC);
241  }
242#endif
[1145]243 }
244
[1227]245 if ( opts == NULL && count == 0 ) {
246  sync = 1;
247  prim = 1; // if ( prim == 0 ) prim = 1; -> prim allways = 1
248 }
249
[933]250 if ( (stream = streams_new()) == -1 ) {
[938]251  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
[982]252  if ( prim ) alive = 0;
[933]253  return -1;
254 }
255
256 streams_get(stream, &ss);
257 s = ROAR_STREAM(ss);
258
259 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
260
261 s->pos_rel_id = -1;
262// s->info.codec = codec;
263
[938]264 codec = s->info.codec;
265
266 k = strtok(opts, ",");
267 while (k != NULL) {
268//  ROAR_WARN("add_output(*): opts: %s", k);
269
270  if ( (v = strstr(k, "=")) != NULL ) {
271   *v++ = 0;
272  }
273
274  ROAR_DBG("add_output(*): opts: k='%s', v='%s'", k, v);
275  if ( strcmp(k, "rate") == 0 ) {
276   s->info.rate = atoi(v);
277  } else if ( strcmp(k, "channels") == 0 ) {
278   s->info.channels = atoi(v);
279  } else if ( strcmp(k, "bits") == 0 ) {
280   s->info.bits = atoi(v);
281  } else if ( strcmp(k, "codec") == 0 ) {
282   if ( (codec = roar_str2codec(v)) == -1 ) {
283    ROAR_ERR("add_output(*): unknown codec '%s'", v);
[1991]284    error++;
[938]285   }
[2085]286  } else if ( strcmp(k, "q") == 0 ) {
287   q = atof(v);
[1221]288  } else if ( strcmp(k, "blocks") == 0 ) {
289   blocks = atoi(v);
[1522]290  } else if ( strcmp(k, "blocksize") == 0 ) {
291   blocksize = atoi(v);
[1926]292  } else if ( strcmp(k, "mmap") == 0 ) {
293   f_mmap = 1;
[1919]294  } else if ( strcmp(k, "subsystem") == 0 ) {
295   if ( !strcasecmp(v, "wave") || !strcasecmp(v, "waveform") ) {
[1920]296    dir = ROAR_DIR_OUTPUT;
[1919]297   } else if ( !strcasecmp(v, "midi") ) {
298    dir = ROAR_DIR_MIDI_OUT;
299   } else if ( !strcasecmp(v, "light") ) {
300    dir = ROAR_DIR_LIGHT_OUT;
[2234]301   } else if ( !strcasecmp(v, "raw") ) {
302    dir = ROAR_DIR_RAW_OUT;
[1919]303   } else {
304    ROAR_ERR("add_output(*): unknown subsystem '%s'", k);
[1991]305    error++;
306   }
307  // DMX:
308  } else if ( strcmp(k, "channel") == 0 ) {
309   channel  = atoi(v);
310   if ( channel < 0 || channel > 65535 ) {
311    ROAR_ERR("add_output(*): Invalide channel (not within 0..65535): %i", channel);
312    channel = -1;
313    error++;
[1919]314   }
[1991]315  } else if ( strcmp(k, "universe") == 0 ) {
316   universe = atoi(v);
317   if ( universe < 0 || universe > 255 ) {
318    ROAR_ERR("add_output(*): Invalide universe (not within 0..255): %i", universe);
319    universe = -1;
320    error++;
321   }
322
[2115]323  } else if ( strcmp(k, "name") == 0 ) {
324   if ( streams_set_name(stream, v) == -1 ) {
325    ROAR_ERR("add_output(*): Can not set Stream name");
326    error++;
327   }
[1991]328
[1032]329  } else if ( strcmp(k, "meta") == 0 ) {
330   streams_set_flag(stream, ROAR_FLAG_META);
[1117]331  } else if ( strcmp(k, "sync") == 0 ) {
332   sync = 1;
[1221]333  } else if ( strcmp(k, "primary") == 0 ) {
334   prim = 1;
335
336  } else if ( strcmp(k, "cleanmeta") == 0 ) {
337   streams_set_flag(stream, ROAR_FLAG_CLEANMETA);
338  } else if ( strcmp(k, "autoconf") == 0 ) {
[1531]339   streams_set_flag(stream, ROAR_FLAG_AUTOCONF);
[938]340  } else {
341   ROAR_ERR("add_output(*): unknown option '%s'", k);
[1991]342   error++;
343  }
344
345  if ( error ) {
[938]346   streams_delete(stream);
[982]347   if ( prim ) alive = 0;
[1208]348#ifdef ROAR_DRIVER_CODEC
349   if ( to_free != NULL )
350    free(to_free);
351#endif
[938]352   return -1;
353  }
354
355  k = strtok(NULL, ",");
356 }
357
[1919]358 if ( streams_set_dir(stream, dir, 1) == -1 ) {
359  streams_delete(stream);
360  return -1;
361 }
362
[1208]363#ifdef ROAR_DRIVER_CODEC
364 if ( to_free != NULL )
365  free(to_free);
366#endif
367
[941]368 if ( codec == ROAR_CODEC_ALAW || codec == ROAR_CODEC_MULAW )
369  s->info.bits = 8; // needed to open OSS driver, will be overriden by codecfilter
370
[938]371 s->info.codec = codec;
372 ROAR_STREAM_SERVER(s)->codec_orgi = codec;
[933]373
[1145]374 if ( driver_openvio(&(ss->vio), &(ss->driver_id), drv, dev, &(s->info), -1) == -1 ) {
[1581]375  ss->driver_id = -1; // don't close a driver not opened...
376  memset(&(ss->vio), 0, sizeof(struct roar_vio_calls));
[933]377  streams_delete(stream);
[938]378  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
[982]379  if ( prim ) alive = 0;
[933]380  return -1;
381 }
382
[1528]383 roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAMID, &stream); // ignore errors here
384 roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAM,   s); // ignore errors here
385
[1221]386 if ( blocks != -1 )
387  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLOCKS, &blocks);
388
[1522]389 if ( blocksize != -1 )
390  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLKSIZE, &blocksize);
391
[1991]392 // TODO: we shoudld *really* check for errors here...
393 if ( channel != -1 ) {
394  tu16 = channel;
395  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXSCHAN, &tu16);
396 }
397 if ( universe != -1 ) {
398  tu16 = universe;
399  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXUNIV, &tu16);
400 }
401
[1156]402 ROAR_DBG("add_output(*): ss->driver_id=%i", ss->driver_id);
403
[938]404 streams_set_fh(stream, -1); // update some internal structures
405
[2087]406 if ( q > -1e6 ) {
407  ROAR_DBG("add_output(*): setting q=%f", q);
408  streams_ctl(stream, ROAR_CODECFILTER_CTL_SET_Q|ROAR_STREAM_CTL_TYPE_FLOAT, &q);
409 }
410
[933]411 client_stream_add(g_source_client, stream);
412
[1200]413 if ( prim ) {
[961]414  streams_mark_primary(stream);
[1200]415  s->pos_rel_id = stream;
416 }
[961]417
[1120]418 if ( sync ) {
[1117]419  streams_set_flag(stream, ROAR_FLAG_SYNC);
[1120]420 } else {
421  streams_reset_flag(stream, ROAR_FLAG_SYNC);
422 }
[1117]423
[1926]424 if ( f_mmap )
425  streams_set_flag(stream, ROAR_FLAG_MMAP);
426
[933]427 return 0;
[932]428}
429
[1993]430
431// SLP:
432void register_slp_callback(SLPHandle hslp, SLPError errcode, void * cookie) {
433 /* return the error code in the cookie */
434 *(SLPError*)cookie = errcode;
435}
436
437int register_slp (int unreg, char * sockname) {
438#ifdef ROAR_HAVE_LIBSLP
439 static int regged = 0;
440 static char * sn = NULL;
441 SLPError err;
442 SLPError callbackerr;
443 SLPHandle hslp;
444 char addr[1024];
445 char attr[1024] = "";
[2017]446 char * location;
[1993]447
448 if ( sockname != NULL )
449  sn = sockname;
450
[2016]451 snprintf(addr, sizeof(addr), ROAR_SLP_URL_TYPE "://%s", sn);
[1993]452
453 err = SLPOpen("en", SLP_FALSE, &hslp);
454
455 if (err != SLP_OK) {
456  ROAR_ERR("Error opening slp handle: Error #%i", err);
457  return -1;
458 }
459
460 if (!unreg) {
[2017]461
462  if ( SLPEscape(g_config->location, &location, SLP_FALSE) != SLP_OK ) {
463   ROAR_ERR("Error using SLPEscape() on server location, really bad!");
464   SLPClose(hslp);
465   return -1;
466  }
467
[1995]468  snprintf(attr, sizeof(attr), "(wave-rate=%i),(wave-channels=%i),(wave-bits=%i),"
[2017]469                               "(light-channels=%i),(location=%s)",
[1995]470           g_sa->rate, g_sa->channels, g_sa->bits,
[2017]471           g_light_state.channels,
472           location
[1995]473          );
474
[1993]475  /* Register a service with SLP */
476  err = SLPReg(hslp,
477               addr,
478               SLP_LIFETIME_MAXIMUM,
479               0,
480               attr,
481               SLP_TRUE,
482               register_slp_callback,
483               &callbackerr);
[1994]484  regged = 1;
485 } else if ( unreg && regged ) {
486  err = SLPDereg(hslp, addr, register_slp_callback, &callbackerr);
487  regged = 0;
488 } else {
489  SLPClose(hslp);
490  return -1;
491 }
[1993]492
[1994]493 /* err may contain an error code that occurred as the slp library    */
494 /* _prepared_ to make the call.                                     */
495 if ( err != SLP_OK ) {
496  ROAR_ERR("Error (de)registering service with slp: Error #%i", err);
497  return -1;
498 }
499
500 /* callbackerr may contain an error code (that was assigned through */
501 /* the callback cookie) that occurred as slp packets were sent on    */
502 /* the wire */
503 if (callbackerr != SLP_OK) {
504  ROAR_ERR("Error (de)registering service with slp: Error #%i", callbackerr);
505  return -1;
[1993]506 }
507
508 SLPClose(hslp);
509 return 0;
510#else
511 return -1;
512#endif
513}
514
515
516// MAIN:
517
[1503]518#ifdef ROAR_HAVE_MAIN_ARGS
[0]519int main (int argc, char * argv[]) {
[1503]520#else
521int main (void) {
522#endif
523#ifdef ROAR_HAVE_MAIN_ARGS
[0]524 int i;
525 char * k;
[1503]526#endif
[1494]527#ifdef ROAR_SUPPORT_LISTEN
[905]528 char user_sock[80]  = {0};
[1494]529#endif
[1609]530 struct roar_audio_info sa, max_sa;
531 struct roard_config config;
[1486]532#ifdef ROAR_HAVE_FORK
[905]533 int    daemon       = 0;
[1486]534#endif
[905]535 int    realtime     = 0;
536 int    sysclocksync = 0;
[1207]537 char * driver    = NULL;
538 char * device    = NULL;
[1503]539#ifdef ROAR_HAVE_MAIN_ARGS
[1207]540 char * opts      = NULL;
[1503]541#endif
[60]542// char * server = ROAR_DEFAULT_SOCK_GLOBAL;
[1494]543#ifdef ROAR_SUPPORT_LISTEN
[1207]544 int      port    = ROAR_DEFAULT_PORT;
[1494]545#endif
[0]546 int               drvid;
[550]547 char * s_drv     = "cf";
[1110]548 char * s_dev     = NULL;
[444]549 char * s_con     = NULL;
550 char * s_opt     = NULL;
551 int    s_prim    = 0;
[1207]552 char * o_drv     = getenv("ROAR_DRIVER");
553 char * o_dev     = getenv("ROAR_DEVICE");
[932]554 char * o_opts    = NULL;
[961]555 int    o_prim    = 0;
[1145]556 int    o_count   = 0;
[1923]557 int    light_channels = LIGHT_CHANNELS_DEFAULT;
[450]558 char * sock_grp  = ROAR_DEFAULT_SOCKGRP;
[444]559 char * sock_user = NULL;
[1494]560#ifdef ROAR_SUPPORT_LISTEN
[517]561 int    sock_type = ROAR_SOCKET_TYPE_UNKNOWN;
[1494]562#endif
[1993]563#ifdef ROAR_HAVE_LIBSLP
564 int    reg_slp   = 0;
565#endif
[1486]566#ifdef ROAR_HAVE_CHROOT
[444]567 char * chrootdir = NULL;
[1486]568#endif
569#if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID)
[444]570 int    setids    = 0;
[1486]571#endif
572#ifdef ROAR_HAVE_UNIX
[1011]573 char * env_roar_proxy_backup;
[1486]574#endif
575#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
[446]576 struct group   * grp  = NULL;
[1486]577#endif
578#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
[446]579 struct passwd  * pwd  = NULL;
[1486]580#endif
581#ifdef ROAR_HAVE_GETSERVBYNAME
[446]582 struct servent * serv = NULL;
[1486]583#endif
[0]584 DRIVER_USERDATA_T drvinst;
[39]585 struct roar_client * self = NULL;
[508]586#ifdef ROAR_HAVE_LIBDNET
587 char decnethost[80];
588#endif
[2104]589#ifdef SUPPORT_PIDFILE
590 struct roar_vio_calls pidfile_vio;
591#endif
[0]592
593 g_standby       =  0;
[920]594 g_autostandby   =  0;
[982]595 alive           =  1;
[1494]596#ifdef ROAR_SUPPORT_LISTEN
[1155]597 g_no_listen     =  0;
[1494]598 g_listen_socket = -1;
599#else
600 g_terminate     =  1;
601#endif
[0]602
603 sa.bits     = ROAR_BITS_DEFAULT;
604 sa.channels = ROAR_CHANNELS_DEFAULT;
605 sa.rate     = ROAR_RATE_DEFAULT;
606 sa.codec    = ROAR_CODEC_DEFAULT;
607
[1609]608 g_sa        = &sa;
609 g_max_sa    = &max_sa;
610
611 memcpy(g_max_sa, g_sa, sizeof(max_sa));
612
613 g_config = &config;
614
615 if ( init_config() == -1 ) {
616  ROAR_ERR("Can not init default config!");
617  return 1;
618 }
[0]619
[1924]620 if ( midi_init_config() == -1 ) {
621  ROAR_ERR("Can not init MIDI config!");
622  return 1;
623 }
[60]624
[1494]625#ifdef ROAR_SUPPORT_LISTEN
[1753]626#ifdef ROAR_HAVE_GETUID
[1486]627 if ( getuid() != 0 && getenv("HOME") != NULL ) {
628  snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER);
[60]629  server = user_sock;
630 }
[1753]631#endif
[60]632
[279]633 if ( getenv("ROAR_SERVER") != NULL )
634  server = getenv("ROAR_SERVER");
[1494]635#endif
[279]636
[63]637 if ( clients_init() == -1 ) {
638  ROAR_ERR("Can not init clients!");
639  return 1;
640 }
641
642 if ( streams_init() == -1 ) {
643  ROAR_ERR("Can not init streams!");
644  return 1;
645 }
646
[64]647 if ( (g_self_client = clients_new()) == -1 ) {
648  ROAR_ERR("Can not create self client!");
649  return 1;
650 }
651
[0]652 if ( sources_init() == -1 ) {
653  ROAR_ERR("Can not init sources!");
654  return 1;
655 }
656
[64]657 if ( (sources_set_client(g_self_client)) == -1 ) {
658  ROAR_ERR("Can not init set source client!");
659  return 1;
660 }
661
[1503]662#ifdef ROAR_HAVE_MAIN_ARGS
[0]663 for (i = 1; i < argc; i++) {
664  k = argv[i];
665
666  if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) {
667   usage();
668   return 0;
669
[2109]670  } else if ( strcmp(k, "--start") == 0 ) {
671   // this is a no op
[579]672  } else if ( strcmp(k, "--restart") == 0 ) {
[1494]673#ifdef ROAR_SUPPORT_LISTEN
[2109]674   if ( restart_server(server, 1) == -1 ) {
[579]675    ROAR_WARN("Can not terminate old server (not running at %s?), tring to continue anyway", server);
676   }
[1494]677#else
678   ROAR_ERR("--restart not supported");
679#endif
[2109]680  } else if ( strcmp(k, "--shutdown") == 0 ) {
681#ifdef ROAR_SUPPORT_LISTEN
682   if ( restart_server(server, 1) == -1 ) {
683    ROAR_WARN("Can not terminate old server (not running at %s?)", server);
684    return 1;
685   }
686   return 0;
687#else
688   ROAR_ERR("--shutdown not supported");
689   return 1;
690#endif
691  } else if ( strcmp(k, "--stop") == 0 ) {
692#ifdef ROAR_SUPPORT_LISTEN
[2111]693   if ( restart_server(server, 0) == -1 ) {
[2109]694    ROAR_WARN("Can not stop old server (not running at %s?)", server);
695    return 1;
696   }
697   return 0;
698#else
699   ROAR_ERR("--stop not supported");
700   return 1;
701#endif
702
[579]703
[775]704  } else if ( strcmp(k, "--demon") == 0 || strcmp(k, "--daemon") == 0 ) {
[1486]705#ifdef ROAR_HAVE_FORK
[775]706   daemon = 1;
[1486]707#else
708   ROAR_ERR("--daemon not supported");
709#endif
[71]710  } else if ( strcmp(k, "--terminate") == 0 ) {
711   g_terminate = 1;
[905]712  } else if ( strcmp(k, "--sysclocksync") == 0 ) {
713   sysclocksync = 1000;
[275]714  } else if ( strcmp(k, "--realtime") == 0 ) {
[276]715   realtime++;
[444]716  } else if ( strcmp(k, "--chroot") == 0 ) {
[1486]717#ifdef ROAR_HAVE_CHROOT
[444]718   chrootdir = argv[++i];
[1486]719#else
720   ROAR_ERR("--chroot not supported");
721   i++;
722#endif
[444]723  } else if ( strcmp(k, "--setgid") == 0 ) {
[1486]724#ifdef ROAR_HAVE_SETGID
[444]725   setids |= R_SETGID;
[1486]726#else
727   ROAR_ERR("--setgid not supported");
728#endif
[444]729  } else if ( strcmp(k, "--setuid") == 0 ) {
[1486]730#ifdef ROAR_HAVE_SETUID
[444]731   setids |= R_SETUID;
[1486]732#else
733   ROAR_ERR("--setuid not supported");
734#endif
[2017]735  } else if ( strcmp(k, "--location") == 0 ) {
736   g_config->location = argv[++i];
[2104]737  } else if ( strcmp(k, "--pidfile") == 0 ) {
738#ifdef SUPPORT_PIDFILE
739   pidfile = argv[++i];
740#else
741   ROAR_ERR("--pidfile not supported");
742   i++;
743#endif
[68]744
[280]745  } else if ( strcmp(k, "--list-cf") == 0 ) {
746   print_codecfilterlist();
747   return 0;
748
[0]749  } else if ( strcmp(k, "-R") == 0 || strcmp(k, "--rate") == 0 ) {
750   sa.rate = atoi(argv[++i]);
751  } else if ( strcmp(k, "-B") == 0 || strcmp(k, "--bits") == 0 ) {
752   sa.bits = atoi(argv[++i]);
753  } else if ( strcmp(k, "-C") == 0 || strcmp(k, "--chans") == 0 ) {
754   sa.channels = atoi(argv[++i]);
755
756  } else if ( strcmp(k, "-d") == 0 || strcmp(k, "--driver") == 0 ) {
757   driver = argv[++i];
758   if ( strcmp(driver, "list") == 0 ) {
[974]759    ROAR_WARN("The option is obsolete, use --list-driver!");
[0]760    print_driverlist();
[973]761    return 0;
[0]762   }
763  } else if ( strcmp(k, "-D") == 0 || strcmp(k, "--device") == 0 ) {
764   device = argv[++i];
765  } else if ( strcmp(k, "-dO") == 0 ) {
766   opts = argv[++i];
[973]767  } else if ( strcmp(k, "--list-driver") == 0 ) {
768   print_driverlist();
769   return 0;
[0]770
[932]771  } else if ( strcmp(k, "-o") == 0 || strcmp(k, "--odriver") == 0 ) {
772   o_drv  = argv[++i];
773  } else if ( strcmp(k, "-O") == 0 || strcmp(k, "--odevice") == 0 ) {
774   o_dev  = argv[++i];
775  } else if ( strcmp(k, "-oO") == 0 ) {
776   o_opts = argv[++i];
[961]777  } else if ( strcmp(k, "-oP") == 0 ) {
778   o_prim = 1;
[932]779  } else if ( strcmp(k, "-oN") == 0 ) {
[1145]780   if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 )
781    o_count++;
782
[961]783   o_drv  = o_dev = o_opts = NULL;
784   o_prim = 0;
[932]785
[0]786  } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) {
[550]787   s_drv = argv[++i];
788  } else if ( strcmp(k, "-S") == 0 ) {
[1110]789   s_dev = argv[++i];
[0]790  } else if ( strcmp(k, "-sO") == 0 ) {
791   s_opt = argv[++i];
792  } else if ( strcmp(k, "-sC") == 0 ) {
793   s_con = argv[++i];
794  } else if ( strcmp(k, "-sP") == 0 ) {
795   s_prim = 1;
[1110]796  } else if ( strcmp(k, "-sN") == 0 ) {
797   if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
798    ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
799   }
800   s_opt = s_dev = s_con = NULL;
801   s_drv = "cf";
802   s_prim = 0;
[0]803
[1923]804  } else if ( strcmp(k, "--light-channels") == 0 ) {
805   light_channels = atoi(argv[++i]);
806
[1924]807  } else if ( strcmp(k, "--midi-no-console") == 0 ) {
808   midi_config.init_cb = 0;
809  } else if ( strcmp(k, "--midi-console") == 0 ) {
810   midi_config.console_dev = argv[++i];
811
[0]812  } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--port") == 0 ) {
[447]813   // This is only usefull in INET not UNIX mode.
[1494]814#ifdef ROAR_SUPPORT_LISTEN
[447]815   if ( *server == '/' )
816    server = ROAR_DEFAULT_HOST;
817
[446]818   errno = 0;
819   if ( (port = atoi(argv[++i])) < 1 ) {
[1486]820#ifdef ROAR_HAVE_GETSERVBYNAME
[446]821    if ( (serv = getservbyname(argv[i], "tcp")) == NULL ) {
822     ROAR_ERR("Unknown service: %s: %s", argv[i], strerror(errno));
823     return 1;
824    }
825    // NOTE: we need to use ROAR_NET2HOST16() here even if s_port is of type int!
826    ROAR_DBG("main(*): serv = {s_name='%s', s_aliases={...}, s_port=%i, s_proto='%s'}",
827            serv->s_name, ROAR_NET2HOST16(serv->s_port), serv->s_proto);
828    port = ROAR_NET2HOST16(serv->s_port);
[1486]829#else
830    ROAR_ERR("invalite port number: %s", argv[i]);
831    return 1;
832#endif
[446]833   }
[1494]834#endif
[1115]835  } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) {
[1494]836#ifdef ROAR_SUPPORT_LISTEN
[0]837   server = argv[++i];
[1494]838#endif
[518]839
[573]840  } else if ( strcmp(k, "-t") == 0 || strcmp(k, "--tcp") == 0 ) {
[1494]841#ifdef ROAR_SUPPORT_LISTEN
[518]842   if ( sock_type != ROAR_SOCKET_TYPE_TCP && sock_type != ROAR_SOCKET_TYPE_TCP6 )
843    sock_type = ROAR_SOCKET_TYPE_TCP;
844
845   if ( *server == '/' )
846    server = ROAR_DEFAULT_HOST;
[1494]847#endif
[518]848
849  } else if ( strcmp(k, "-4") == 0 ) {
[1494]850#ifdef ROAR_SUPPORT_LISTEN
[517]851   sock_type = ROAR_SOCKET_TYPE_TCP;
[447]852   if ( *server == '/' )
853    server = ROAR_DEFAULT_HOST;
[1494]854#endif
[518]855  } else if ( strcmp(k, "-6") == 0 ) {
[1494]856#ifdef ROAR_SUPPORT_LISTEN
[519]857#ifdef PF_INET6
[518]858   sock_type = ROAR_SOCKET_TYPE_TCP6;
859   if ( *server == '/' )
860    server = ROAR_DEFAULT_HOST;
[519]861#else
862    ROAR_ERR("No IPv6 support compiled in!");
863    return 1;
864#endif
[1494]865#endif
[518]866
[573]867  } else if ( strcmp(k, "-u") == 0 || strcmp(k, "--unix") == 0 ) {
[1494]868#ifdef ROAR_SUPPORT_LISTEN
[62]869   // ignore this case as it is the default behavor.
[517]870   sock_type = ROAR_SOCKET_TYPE_UNIX;
[1494]871#endif
[518]872
[573]873  } else if ( strcmp(k, "-n") == 0 || strcmp(k, "--decnet") == 0 ) {
[1494]874#ifdef ROAR_SUPPORT_LISTEN
[508]875#ifdef ROAR_HAVE_LIBDNET
876    port   = ROAR_DEFAULT_NUM;
877    strcpy(decnethost, ROAR_DEFAULT_LISTEN_OBJECT);
878    server = decnethost;
[517]879    sock_type = ROAR_SOCKET_TYPE_DECNET;
[508]880#else
881    ROAR_ERR("No DECnet support compiled in!");
882    return 1;
883#endif
[1494]884#endif
[518]885
[1993]886  } else if ( strcmp(k, "--slp") == 0 ) {
887#ifdef ROAR_HAVE_LIBSLP
888   reg_slp = 1;
889#else
890    ROAR_ERR("No OpenSLP support compiled in!");
891    return 1;
892#endif
893
[60]894  } else if ( strcmp(k, "-G") == 0 ) {
[444]895   sock_grp  = argv[++i];
896  } else if ( strcmp(k, "-U") == 0 ) {
897   sock_user = argv[++i];
[0]898
[68]899  } else if ( strcmp(k, "--no-listen") == 0 ) {
[1494]900#ifdef ROAR_SUPPORT_LISTEN
[1787]901   server      = "";
[548]902   g_terminate = 1;
[1155]903   g_no_listen = 1;
[1494]904#endif
[68]905  } else if ( strcmp(k, "--client-fh") == 0 ) {
906   if ( clients_set_fh(clients_new(), atoi(argv[++i])) == -1 ) {
907    ROAR_ERR("main(*): Can not set client's fh");
908    return 1;
909   }
[501]910  } else if ( strcmp(k, "--close-fh") == 0 ) {
[1486]911#ifdef ROAR_HAVE_IO_POSIX
[501]912   close(atoi(argv[++i]));
[1486]913#else
914   i++;
915   ROAR_WARN("can not close file handle %s (closing not supported)", argv[i]);
916#endif
[68]917
[920]918  } else if ( strcmp(k, "--standby") == 0 ) {
919   g_standby = 1;
920  } else if ( strcmp(k, "--auto-standby") == 0 ) {
921   g_autostandby = 1;
[0]922  } else {
923   usage();
924   return 1;
925  }
926
927 }
[1503]928#endif
[0]929
[1110]930 if ( s_dev != NULL ) {
931  if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
932   ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
933  }
934 }
935
[1145]936 add_output(o_drv, o_dev, o_opts, o_prim, o_count);
[932]937
[0]938 ROAR_DBG("Server config: rate=%i, bits=%i, chans=%i", sa.rate, sa.bits, sa.channels);
939
[1819]940 if ( midi_init() == -1 ) {
[281]941  ROAR_ERR("Can not initialize MIDI subsystem");
[1819]942 }
943
944 if ( light_init(light_channels) == -1 ) {
945  ROAR_ERR("Can not initialize light control subsystem");
946 }
[281]947
[1494]948#ifdef ROAR_SUPPORT_LISTEN
[68]949 if ( *server != 0 ) {
[517]950  if ( (g_listen_socket = roar_socket_listen(sock_type, server, port)) == -1 ) {
[1486]951#ifdef ROAR_HAVE_UNIX
[286]952   if ( *server == '/' ) {
[1011]953    if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) {
954     env_roar_proxy_backup = strdup(env_roar_proxy_backup);
955     unsetenv("ROAR_PROXY");
956    }
[286]957    if ( (i = roar_socket_connect(server, port)) != -1 ) {
958     close(i);
959     ROAR_ERR("Can not open listen socket!");
960     return 1;
961    } else {
962     unlink(server);
[517]963     if ( (g_listen_socket = roar_socket_listen(sock_type, server, port)) == -1 ) {
[286]964      ROAR_ERR("Can not open listen socket!");
965      return 1;
966     }
967    }
[1011]968    if ( env_roar_proxy_backup != NULL ) {
969     setenv("ROAR_PROXY", env_roar_proxy_backup, 0);
970     free(env_roar_proxy_backup);
971    }
[1486]972#else
973   if (0) { // noop
974#endif
[286]975   } else {
976    ROAR_ERR("Can not open listen socket!");
977    return 1;
978   }
[68]979  }
[0]980
[1486]981#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
[523]982  if ( (grp = getgrnam(sock_grp)) == NULL ) {
983   ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno));
984  }
[1486]985#endif
986#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
[523]987  if ( sock_user || (setids & R_SETUID) ) {
988   if ( (pwd = getpwnam(sock_user)) == NULL ) {
989    ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno));
990   }
991  }
[1486]992#endif
[523]993
[1516]994#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_UNIX)
[68]995  if ( *server == '/' ) {
[523]996   if ( grp ) {
[444]997    if ( pwd ) {
[1691]998     if ( chown(server, pwd->pw_uid, grp->gr_gid) == -1 )
999      return 1;
[444]1000    } else {
[1691]1001     if ( chown(server, -1, grp->gr_gid) == -1 )
1002      return 1;
[444]1003    }
[1753]1004#ifdef ROAR_HAVE_GETUID
[68]1005    if ( getuid() == 0 )
[1691]1006     if ( chmod(server, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1 )
1007      return 1;
[1753]1008#endif
[68]1009   }
[60]1010  }
[1486]1011#endif
[60]1012 }
[1494]1013#endif
[60]1014
[0]1015 if ( output_buffer_init(&sa) == -1 ) {
1016  ROAR_ERR("Can not init output buffer!");
1017  return 1;
1018 }
1019
[1145]1020 if ( driver == NULL ) {
1021  driver = "null";
1022 } else {
1023  ROAR_WARN("Usage of old driver interface. use -o not -d!");
1024 }
1025
[0]1026 if ( driver_open(&drvinst, &drvid, driver, device, &sa) == -1 ) {
1027  ROAR_ERR("Can not open output driver!");
1028  return 1;
1029 }
1030
[44]1031 if ( samples_init() == -1 ) {
1032  ROAR_ERR("Can not init samples!");
1033  return 1;
1034 }
1035
1036
[1486]1037 // we should handle this on microcontrollers, too.
[1753]1038#if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_TARGET_WIN32)
[0]1039 signal(SIGINT,  on_sig_int);
[285]1040 signal(SIGCHLD, on_sig_chld);
[2112]1041 signal(SIGUSR1, on_sig_usr1);
[0]1042 signal(SIGPIPE, SIG_IGN);  // ignore broken pipes
[1486]1043#endif
[0]1044
[275]1045 if ( realtime ) {
[278]1046#ifdef DEBUG
1047  ROAR_WARN("compiled with -DDEBUG but realtime is enabled: for real realtime support compiel without -DDEBUG");
1048#endif
1049
[1486]1050#ifdef ROAR_HAVE_NICE
[275]1051  errno = 0;
[276]1052  nice(-5*realtime); // -5 for each --realtime
[1486]1053  if ( errno ) {
1054   ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
1055  }
1056#else
1057  ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
1058#endif
[277]1059/*
[276]1060#ifdef __linux__
[277]1061  if ( ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0)) == -1 )
1062   ROAR_WARN("Can not set io priority: %s", strerror(errno));
[276]1063#endif
[277]1064*/
[275]1065 }
1066
[1486]1067#ifdef ROAR_HAVE_SETGID
[444]1068 if ( setids & R_SETGID ) {
1069  if ( setgroups(0, (const gid_t *) NULL) == -1 ) {
1070   ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno));
1071  }
[523]1072  if ( !grp || setgid(grp->gr_gid) == -1 ) {
[444]1073   ROAR_ERR("Can not set GroupID: %s", strerror(errno));
1074  }
1075 }
[1486]1076#endif
[444]1077
[0]1078
[39]1079 clients_set_pid(g_self_client, getpid());
[1753]1080#ifdef ROAR_HAVE_GETUID
[440]1081 clients_set_uid(g_self_client, getuid());
[1753]1082#endif
1083#ifdef ROAR_HAVE_GETGID
[440]1084 clients_set_gid(g_self_client, getgid());
[1753]1085#endif
[39]1086 clients_get(g_self_client, &self);
[37]1087
[39]1088 if ( self == NULL ) {
1089  ROAR_ERR("Can not get self client!");
1090  return 1;
1091 }
1092
[775]1093 strcpy(self->name, "RoarAudio daemon internal");
[68]1094
[1486]1095#ifdef ROAR_HAVE_FORK
[775]1096 if ( daemon ) {
[68]1097  close(ROAR_STDIN );
1098  close(ROAR_STDOUT);
1099  close(ROAR_STDERR);
[1753]1100
[68]1101  if ( fork() )
[1486]1102   ROAR_U_EXIT(0);
[1753]1103
1104#ifdef ROAR_HAVE_SETSID
1105  setsid();
1106#endif
[1046]1107  clients_set_pid(g_self_client, getpid()); // reset pid as it changed
[68]1108 }
[1486]1109#endif
[68]1110
[2104]1111#ifdef SUPPORT_PIDFILE
[2106]1112 if ( pidfile != NULL ) {
1113  if ( roar_vio_open_file(&pidfile_vio, pidfile, O_WRONLY|O_CREAT, 0644) == -1 ) {
1114   ROAR_ERR("Can not write pidfile: %s", pidfile);
1115  } else {
1116   roar_vio_printf(&pidfile_vio, "%i\n", getpid());
1117   roar_vio_close(&pidfile_vio);
1118  }
[2104]1119 }
1120#endif
1121
[1486]1122#ifdef ROAR_HAVE_CHROOT
[444]1123 if (chrootdir) {
1124  if ( chroot(chrootdir) == -1 ) {
1125   ROAR_ERR("Can not chroot to %s: %s", chrootdir, strerror(errno));
1126   return 2;
1127  }
1128  if ( chdir("/") == -1 ) {
1129   ROAR_ERR("Can not chdir to /: %s", strerror(errno));
1130   return 2;
1131  }
1132 }
[1486]1133#endif
[444]1134
[1486]1135#ifdef ROAR_HAVE_SETUID
[444]1136 if ( setids & R_SETUID ) {
1137  if ( !pwd || setuid(pwd->pw_uid) == -1 ) {
1138   ROAR_ERR("Can not set UserID: %s", strerror(errno));
1139   return 3;
1140  }
[1753]1141#ifdef ROAR_HAVE_GETUID
[444]1142  clients_set_uid(g_self_client, getuid());
[1753]1143#endif
[444]1144 }
[1486]1145#endif
[444]1146
[1993]1147 // Register with OpenSLP:
[2028]1148#ifdef ROAR_HAVE_LIBSLP
[1993]1149 if ( reg_slp ) {
1150  register_slp(0, server);
1151 }
[2028]1152#endif
[1993]1153
[0]1154 // start main loop...
[905]1155 main_loop(drvid, drvinst, &sa, sysclocksync);
[0]1156
1157 // clean up.
1158 clean_quit_prep();
1159 driver_close(drvinst, drvid);
1160 output_buffer_free();
1161
1162 return 0;
1163}
1164
[574]1165void cleanup_listen_socket (int terminate) {
[1993]1166 // Deregister from SLP:
[2028]1167#ifdef ROAR_HAVE_LIBSLP
[1993]1168 register_slp(1, NULL);
[2028]1169#endif
[580]1170
[1494]1171#ifdef ROAR_SUPPORT_LISTEN
[580]1172 if ( g_listen_socket != -1 ) {
[1486]1173#ifdef ROAR_HAVE_IO_POSIX
[580]1174  close(g_listen_socket);
[1486]1175#endif // #else is useless because we are in void context.
[60]1176
[580]1177  g_listen_socket = -1;
[576]1178
[1486]1179#ifdef ROAR_HAVE_UNIX
[580]1180  if ( *server == '/' )
1181   unlink(server);
[1486]1182#endif
[580]1183 }
[60]1184
[1494]1185#endif
1186
[574]1187 if ( terminate )
1188  g_terminate = 1;
1189}
1190
1191void clean_quit_prep (void) {
1192 cleanup_listen_socket(0);
[60]1193
[0]1194 sources_free();
1195 streams_free();
1196 clients_free();
[282]1197 midi_cb_stop(); // stop console beep
[281]1198 midi_free();
[1819]1199 light_free();
[2104]1200
1201#ifdef SUPPORT_PIDFILE
1202 if ( pidfile != NULL )
1203  unlink(pidfile);
1204#endif
[0]1205}
1206
1207void clean_quit (void) {
1208 clean_quit_prep();
1209// driver_close(drvinst, drvid);
1210// output_buffer_free();
1211 exit(0);
1212}
1213
1214//ll
Note: See TracBrowser for help on using the repository browser.