source: roaraudio/roard/roard.c @ 2251:d555bf49b46d

Last change on this file since 2251:d555bf49b46d was 2234:5c84620cf44d, checked in by phi, 15 years ago

make it possible to set subsystem=raw

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