source: roaraudio/roard/roard.c @ 2123:3b76214d6b28

Last change on this file since 2123:3b76214d6b28 was 2115:16ddc6566cb2, checked in by phi, 15 years ago

added support to set name for output streams

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