source: roaraudio/roard/roard.c @ 2325:2854f65ae3e0

Last change on this file since 2325:2854f65ae3e0 was 2291:d3f351907764, checked in by phi, 15 years ago

playback streams have set the meta flag by default now

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