source: roaraudio/roard/roard.c @ 4739:605b086a1801

Last change on this file since 4739:605b086a1801 was 4739:605b086a1801, checked in by phi, 13 years ago

some work to avoid compiler warnings

File size: 75.5 KB
RevLine 
[0]1//roard.c:
2
[668]3/*
[4708]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
[668]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
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[668]23 *
24 */
25
[0]26#include "roard.h"
27
[4722]28enum action {
29 START,
30 STOP,
31 RESTART,
32 RESTART_RETRY,
33 SHUTDOWN
34};
35
[1494]36#ifdef ROAR_SUPPORT_LISTEN
[2530]37char * server[ROAR_MAX_LISTEN_SOCKETS];
[1494]38#endif
[60]39
[2104]40#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_FS_POSIX)
41#define SUPPORT_PIDFILE
42char * pidfile = NULL;
43#endif
44
[2530]45#if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID)
[3374]46int    setids    = 0;
47#endif
48
49#ifdef ROAR_HAVE_LIBX11
50char * x11display = NULL;
[2530]51#endif
52
[4141]53int add_output (char * drv, char * dev, char * opts, int prim, int count);
54
[4324]55void dbg_notify_cb(struct roar_notify_core * core, struct roar_event * event, void * userdata) {
56 char buf[1024] = "";
[4338]57 char estr[1024] = "/* ROAR_??? */";
58 char ttstr[1024] = "/* ROAR_OT_??? */";
59 const char * ttname;
60 uint32_t ev = ROAR_EVENT_GET_TYPE(event);
61 int i;
62
63 ttname = roar_ot2str(event->target_type);
64 if ( ttname != NULL ) {
65  snprintf(ttstr, sizeof(ttstr)-1, "/* ROAR_OT_%s */", ttname);
66  buf[sizeof(ttstr)-1] = 0;
67  for (i = 0; ttstr[i] != 0; i++)
68   if ( islower(ttstr[i]) )
69    ttstr[i] = toupper(ttstr[i]);
70 }
71
72 if ( ev == ROAR_NOTIFY_SPECIAL ) {
73  snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_SPECIAL */");
74 } else if ( ROAR_NOTIFY_IS_CMD(ev) ) {
[4345]75  if ( command_get_name(ROAR_NOTIFY_EVENT2CMD(ev), &ttname) == -1 ) {
76   snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_CMD2EVENT(%i) */", ROAR_NOTIFY_EVENT2CMD(ev));
77  } else {
78   snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_CMD2EVENT(ROAR_CMD_%s) */", ttname);
79   for (i = 0; estr[i] != 0; i++)
80    if ( islower(estr[i]) )
81     estr[i] = toupper(estr[i]);
82  }
[4338]83 } else if ( ROAR_NOTIFY_IS_EGRP(ev) ) {
84  snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_EGRP2EVENT(%i) */", ROAR_NOTIFY_EVENT2EGRP(ev));
85 } else if ( ROAR_NOTIFY_IS_OE(ev) ) {
86  switch (ev) {
[4418]87   // OE basics:
[4338]88   case ROAR_OE_BASICS_CHANGE_STATE:
89     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_BASICS_CHANGE_STATE */");
90    break;
91   case ROAR_OE_BASICS_CHANGE_FLAGS:
92     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_BASICS_CHANGE_FLAGS */");
93    break;
[4345]94   case ROAR_OE_BASICS_NEW:
95     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_BASICS_NEW */");
96    break;
97   case ROAR_OE_BASICS_DELETE:
98     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_BASICS_DELETE */");
99    break;
[4418]100   // OE Streams:
101   case ROAR_OE_STREAM_CHANGE_VOLUME:
102     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_STREAM_CHANGE_VOLUME */");
103    break;
104   case ROAR_OE_STREAM_XRUN:
105     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_STREAM_XRUN */");
106    break;
107   // OE Default:
[4338]108   default:
109     snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_OE2EVENT(%i) */", ROAR_NOTIFY_EVENT2OE(ev));
110    break;
111  }
112 } else if ( ROAR_NOTIFY_IS_USER(ev) ) {
113  snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_USER2EVENT(%i) */", ROAR_NOTIFY_EVENT2USER(ev));
114 }
115
116 buf[sizeof(estr)-1] = 0;
[4324]117
118 if ( event->flags & ROAR_EVENT_FLAG_PROXYEVENT ) {
[4338]119  snprintf(buf, sizeof(buf)-1, ".event_proxy=0x%.8x%s, ", (int)event->event_proxy, estr);
[4324]120  buf[sizeof(buf)-1] = 0;
121 }
122
[4418]123 ROAR_INFO("dbg_notify_cb(core=%p, event=%p{.flags=0x%.8x, event=0x%.8x%s, %s.emitter=%i, .target=%i, .target_type=%i%s, .arg0=%i, .arg1=%i, .arg2=%p}, userdata=%p) = (void)",
124           0 /* always print: minlevel = 0 */,
[4324]125           core, event,
126           (int)event->flags,
127           (int)event->event,
[4338]128           (event->flags & ROAR_EVENT_FLAG_PROXYEVENT ? "" : estr),
[4324]129           buf,
130           event->emitter,
131           event->target,
132           event->target_type,
[4338]133           ttstr,
[4324]134           event->arg0,
135           event->arg1,
136           event->arg2,
137           userdata);
138}
139
140void dbg_notify_cb_register (void) {
141 struct roar_event event;
142
143 memset(&event, 0, sizeof(event));
144
145 event.event = ROAR_EGRP_ANY_EVENT;
146
147 event.emitter = -1;
148 event.target = -1;
149 event.target_type = -1;
150
151 roar_notify_core_subscribe(NULL, &event, dbg_notify_cb, NULL);
152}
153
[1503]154#ifdef ROAR_HAVE_MAIN_ARGS
[0]155void usage (void) {
156 printf("Usage: roard [OPTIONS]...\n\n");
157
[68]158 printf("Misc Options:\n\n");
159 printf(
[775]160        " --daemon              - Bring the server into background after init\n"
[2970]161        " --verbose             - Be more verbose, can be used multiple times\n"
[71]162        " --terminate           - Terminate after last client quited\n"
[2109]163        " --start               - No op parameter (starting roard is default operation)\n"
[274]164        " --restart             - Trys to stop an old instance and start a new with new settings\n"
[2109]165        " --stop                - Stops a running roard (provide --pidfile!)\n"
166        " --shutdown            - Terminates a running roard (provide --pidfile!)\n"
[276]167        " --realtime            - Trys to get realtime priority,\n"
168        "                         give multible times for being more realtime\n"
[4245]169        " --memlock LEVEL       - Set default memory locking level to LEVEL\n"
[444]170        " --chroot DIR          - chroots to the given dir\n"
171        " --setgid              - GroupID to the audio group as specified via -G\n"
172        " --setuid              - UserID to the audio user as specified via -U\n"
[905]173        " --sysclocksync        - calculate exact sample rate using the system clock\n"
[2017]174        " --location  LOC       - Set lion readable location of server\n"
[4421]175        " --description  DESC   - Set lion readable description of server\n"
[2104]176#ifdef SUPPORT_PIDFILE
177        " --pidfile PIDFILE     - Write a pidfile at PIDFILE\n"
178#endif
[3688]179#ifdef ROAR_HAVE_SYSLOG
180        " --log-syslog          - Log Warnings, Errors, ... to syslog\n"
181#endif
[68]182       );
183
[4482]184 printf("\nAuth Options:\n\n");
185 printf(
186        " --guest-acclev ACCLEV - Sets the access level for guest access to ACCLEV\n"
187        " --trust-acclev ACCLEV - Sets the access level for trust-authed\n"
188        "                         connections to ACCLEV\n"
189        " --trust-root          - Trust root user\n"
190        " --no-trust-root       - Don't trust root user\n"
191       );
192
[3356]193 printf("\nPlugin Options:\n\n");
194 printf(
195        " --plugin-load FILE    - Load plugin FILE\n"
196       );
197
[68]198 printf("\nAudio Options:\n\n");
[0]199 printf(
200        " -R  --rate   RATE     - Set server rate\n"
201        " -B  --bits   BITS     - Set server bits\n"
202        " -C  --chans  CHANNELS - Set server channels\n"
[3963]203        " --aiprofile  PROFILE  - Use the given audio profile\n"
[0]204       );
205
[2339]206 printf("\nStream Options:\n\n");
207 printf(
208        " --stream-flags D=F    - Set default flags for stream directions\n"
[4012]209        "                         D is the stream direction and F is a comma separated\n"
[2339]210        "                         list of flags in form +flag or -flag to set or unset\n"
211        "                         a flag as default or remove it from the default\n"
212       );
213
[932]214 printf("\nOutput Options:\n\n");
[974]215 printf(" -o  --odriver DRV     - Set the driver, use '--list-driver' to get a list\n");
[932]216 printf(" -O  --odevice DEV     - Set the device\n");
217 printf(" -oO OPTS              - Set output options\n");
218 printf(" -oN                   - Adds another output\n");
[961]219 printf(" -oP                   - Mark output as primary\n");
[4225]220#ifdef ROAR_DRIVER_DEFAULT
221 printf(" --list-driver         - List all drivers (default driver: %s)\n", ROAR_DRIVER_DEFAULT);
222#else
223 printf(" --list-driver         - List all drivers (default driver: (autodetect))\n");
224#endif
[932]225
[2485]226#ifndef ROAR_WITHOUT_DCOMP_SOURCES
[0]227 printf("\nSource Options:\n\n");
228 printf(" -s  --source DRV      - Use DRV as input driver\n"
229        " -S           DEV      - Use DEV as input device\n"
230        " -sO          OPTS     - Use OPTS as input options\n"
[1512]231        " -sN                   - Adds another source\n"
[0]232        " -sP                   - Make souce as primary\n"
233       );
[2270]234 printf(" --list-sources        - List all sources\n");
[2485]235#endif
[0]236
[4358]237#ifndef ROAR_WITHOUT_DCOMP_MIXER
238 printf("\nHardware Mixer Options:\n\n");
239 printf(" -m  --mixer  DRV      - Use DRV as mixer driver\n"
240        " -M           DEV      - Use DEV as mixer device\n"
241        " -mO          OPTS     - Use OPTS as mixer options\n"
242        " -mN                   - Adds another mixer\n"
243        " -mP                   - Make mixer as primary\n"
244       );
245 printf(" --list-mixers         - List all mixers\n");
246#endif
247
[280]248 printf("\nCodec Filter Options:\n\n");
249 printf(" --list-cf             - List all codec filter\n"
250       );
[0]251
[2500]252#ifndef ROAR_WITHOUT_DCOMP_MIDI
[1923]253 printf("\nMIDI Options:\n\n");
[1924]254 printf(" --midi-no-console     - Disable console based MIDI synth\n"
[2444]255        " --midi-console-enable - Enables the console based MIDI synth\n"
[1924]256        " --midi-console DEV    - Set device for MIDI console\n"
[2489]257#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
[2451]258        " --ssynth-enable       - Enable simple software synth\n"
259        " --ssynth-disable      - Disable simple software synth\n"
[2489]260#endif
[1924]261       );
[2500]262#endif
[1923]263
[2494]264#ifndef ROAR_WITHOUT_DCOMP_LIGHT
[1923]265 printf("\nLight Control Options:\n\n");
266 printf(" --light-channels NUM  - Sets the number of channels for Light control (default: %i)\n",
267                                  LIGHT_CHANNELS_DEFAULT
268       );
[2494]269#endif
[1923]270
[2725]271#ifndef ROAR_WITHOUT_DCOMP_RDTCS
[3339]272 printf("\nRadio Data and Transmitter Control System Options:\n\n");
[2725]273 printf(" --rds-pi   PI         - Sets the RDS Programme Identification (PI)\n"
274        " --rds-ps   PS         - Sets the RDS Programme Service Name (PS)\n"
275        " --rds-pty  PTY        - Sets the RDS Programme Type (PTY)\n"
276        " --rds-tp              - Sets the RDS Traffic Programme (TP) flag\n"
277        " --rds-ct              - Enables sending of RDS Clock Time (CT)\n"
278       );
279#endif
280
[3374]281#ifdef ROAR_HAVE_LIBX11
282 printf("\nX11 Options:\n\n");
283 printf(
284        " --x11-display DISPLAY - Set display for X11\n"
285        " --display DISPLAY     - Set display for X11\n"
286       );
287#endif
288
[0]289 printf("\nServer Options:\n\n");
290 printf(" -t  --tcp             - Use TCP listen socket\n"
[3992]291#ifdef ROAR_HAVE_UNIX
[0]292        " -u  --unix            - Use UNIX Domain listen socket (default)\n"
[3992]293#endif
[508]294#ifdef ROAR_HAVE_LIBDNET
295        " -n  --decnet          - use DECnet listen socket\n"
296#endif
[518]297        " -4                    - Use IPv4 connections (implies -t)\n"
[3837]298#ifdef AF_INET6
[518]299        " -6                    - Use IPv6 connections (implies -t)\n"
300#endif
301#ifdef IPV6_ADDRFORM
302        " -64                   - Try to downgrade sockets from IPv6 into IPv4,\n"
[4012]303        "                         this is normaly not useful.\n"
[518]304#endif
[0]305        " -p  --port            - TCP Port to bind to\n"
306        " -b  --bind            - IP/Hostname to bind to\n"
[1115]307        "     --sock            - Filename for UNIX Domain Socket\n"
[2530]308        "     --proto PROTO     - Use PROTO as protocol on Socket\n"
[3252]309        "     --proto-dir DIR   - Set direction parameter for protocol\n"
310        "     --proto-rate RATE - Set sample rate parameter for protocol\n"
311        "     --proto-bits BITS - Set bits per sample parameter for protocol\n"
312        "     --proto-codec E   - Set codec parameter for protocol\n"
[4012]313        "     --proto-chans C   - Set number of channels parameter for protocol\n"
[3954]314        "     --proto-aiprofile PROFILE\n"
315        "                       - Sets the audio profile for socket\n"
[3956]316        "     --proto-profile P - Set profile for listen socket\n"
[3127]317        "     --list-proto      - List supported protocols\n"
[3956]318        "     --list-profiles   - List supported profiles for --proto-profile\n"
[2530]319        "     --new-sock        - Parameters for new socket follows\n"
[1993]320#ifdef ROAR_HAVE_LIBSLP
321        "     --slp             - Enable OpenSLP support\n"
322#endif
[3373]323#ifdef ROAR_HAVE_LIBX11
324        "     --x11             - Enable X11 support\n"
325#endif
[3039]326        " --jumbo-mtu MTU       - Sets the MTU for Jumbo Packets\n"
[450]327        " -G  GROUP             - Sets the group for the UNIX Domain Socket, (default: %s)\n"
[2737]328        "                         You need the permissions to change the GID\n"
[444]329        " -U  USER              - Sets the user for the UNIX Domain Socket, (default: do not set)\n"
[2737]330        "                         You need the permissions to change the UID (normaly only root has)\n"
[548]331        " --no-listen           - Do not listen for new clients\n"
[4012]332        "                         (only useful for relaing, impleys --terminate)\n"
[274]333        " --client-fh           - Comunicate with a client over this handle\n"
[4012]334        "                         (only useful for relaing)\n"
[920]335        " --close-fh            - Closes the given fh\n"
336        " --standby             - Start in standby state\n"
337        " --auto-standby        - Automatical goes into standby if there are no streams\n",
[2755]338#ifdef ROAR_DEFAULT_SOCKGRP
[450]339        ROAR_DEFAULT_SOCKGRP
[2755]340#else
341        "(none)"
342#endif
[0]343       );
344// printf("\n Options:\n\n");
345 printf("\n");
346}
[3127]347
348static void list_proto (void) {
349 printf("  Protocol Flag Subsys - Description\n");
350 printf("------------------------------------------------------\n");
351 printf("  roar          WM LRX - RoarAudio native protocol\n");
352#if !defined(ROAR_WITHOUT_DCOMP_EMUL_ESD) && defined(ROAR_HAVE_H_ESD)
353 printf("  esd           W      - EsounD emulation\n");
354#endif
[3603]355#ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE
[3257]356 printf("  simple        WM LRX - PulseAudio simple protocol\n");
[3597]357#endif
[3684]358#ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND
359 printf("  rsound        W      - RSound emulation\n");
360#endif
[3981]361#ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY
362 printf("  rplay         W      - RPlay emulation\n");
363#endif
[4703]364#ifndef ROAR_WITHOUT_DCOMP_EMUL_GOPHER
365 printf("  gopher               - The Internet Gopher Protocol\n");
366#endif
[3127]367}
368
[1503]369#endif
[0]370
[4101]371#define _pmsg(format, args...) roar_debug_msg(type, __LINE__, __FILE__, ROAR_DBG_PREFIX, format, ## args)
372#define _pmsgc(group, counter, name) _pmsg("  Counter %-10s: %llu", (name), (long long unsigned int)counters_get(group, counter))
373void counters_print(int type, int force) {
374 if ( type != ROAR_DEBUG_TYPE_INFO || force || (ROAR_DBG_INFOVAR) >= ROAR_DBG_INFO_INFO ) {
375  _pmsg("--- Counter Listing ---");
376  _pmsg(" Current:");
377  _pmsgc(cur, clients, "Clients");
378  _pmsgc(cur, streams, "Streams");
379  _pmsg(" Total:");
380  _pmsgc(sum, clients, "Clients");
381  _pmsgc(sum, streams, "Streams");
382  _pmsg("--- End of Counter Listing ---");
383 }
384}
385#undef _pmsgc
386#undef _pmsg
387
[2109]388int restart_server (char * server, int terminate) {
[579]389 struct roar_connection con;
[2111]390#ifdef ROAR_HAVE_KILL
391 char buf[80];
392 ssize_t l;
393 struct roar_vio_calls fh;
394 pid_t pid;
395 int ok;
396
[4055]397 ROAR_INFO("restart_server(server='%s', terminate=%i): trying to restart server", ROAR_DBG_INFO_INFO, server, terminate);
398
[2111]399 if ( pidfile != NULL ) {
400  if ( roar_vio_open_file(&fh, pidfile, O_RDONLY, 0644) == -1 ) {
401   ROAR_WARN("restart_server(*): Can not read pidfile: %s", pidfile);
402  } else {
403   l = roar_vio_read(&fh, buf, 80);
404   roar_vio_close(&fh);
405   if ( l > 0 ) {
406    buf[l-1] = 0;
407    buf[79]  = 0;
408    pid = atoi(buf);
409    if ( terminate ) {
[2113]410     ok = kill(pid, SIGUSR1);
[2111]411    } else {
412     ok = kill(pid, SIGINT);
413    }
414    if ( ok == 0 ) {
415     return 0;
416    } else {
417     ROAR_WARN("restart_server(*): Can not kill roard by pidfile");
418    }
419   } else {
420    ROAR_WARN("restart_server(*): Can not find a PID in the pidfile");
421   }
422  }
423 }
424#endif
[2109]425
[4722]426 if ( roar_simple_connect(&con, server, "roard") == -1 ) {
[579]427  return -1;
428 }
429
[2109]430 if ( roar_terminate(&con, terminate) == -1 ) {
[579]431  return -1;
432 }
433
434 return roar_disconnect(&con);
435}
436
[444]437#define R_SETUID 1
438#define R_SETGID 2
439
[1609]440int init_config (void) {
441 int i;
442
443 memset(g_config, 0, sizeof(struct roard_config));
444
445 for (i = 0; i < ROAR_DIR_DIRIDS; i++) {
446  g_config->streams[i].mixer_channels = 1;
447  g_config->streams[i].mixer.rpg_mul  = 1;
448  g_config->streams[i].mixer.rpg_div  = 1;
449  g_config->streams[i].mixer.scale    = 65535;
450  g_config->streams[i].mixer.mixer[0] = g_config->streams[i].mixer.scale;
451 }
452
[2291]453 g_config->streams[ROAR_DIR_PLAY    ].flags = ROAR_FLAG_META;
[2413]454 g_config->streams[ROAR_DIR_OUTPUT  ].flags = ROAR_FLAG_PASSMIXER;
[2264]455 g_config->streams[ROAR_DIR_FILTER  ].flags = ROAR_FLAG_SYNC;
[1899]456 g_config->streams[ROAR_DIR_MIDI_OUT].flags = ROAR_FLAG_SYNC;
[2160]457 g_config->streams[ROAR_DIR_BIDIR   ].flags = ROAR_FLAG_ANTIECHO;
[1899]458
[4442]459 g_config->location    = CONF_DEF_STRING;
460 g_config->description = CONF_DEF_STRING;
[2017]461
[4245]462 g_config->memlock_level = -1;
463
[1609]464 return 0;
465}
466
[2530]467#ifdef ROAR_SUPPORT_LISTEN
468int init_listening (void) {
469 int i;
470
[3128]471 memset(g_listen, 0, sizeof(g_listen));
472
[2530]473 for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
[3128]474  g_listen[i].proto  = ROAR_PROTO_ROARAUDIO;
[2530]475  server[i]          = NULL;
476 }
477
478 return 0;
479}
480
[3731]481int get_listen(struct roard_listen ** sock, char *** sockname) {
[3730]482 int i;
483
484 if ( sock == NULL )
485  return -1;
486
487 for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
[3802]488  if ( ! g_listen[i].used ) {
[3730]489   server[i] = NULL;
[3731]490   *sock = &(g_listen[i]);
[3730]491
[3733]492   if ( sockname != NULL )
[3730]493    *sockname = &(server[i]);
[3733]494
495   return 0;
[3730]496  }
497 }
498
499 return -1;
500}
501
[3956]502#ifdef ROAR_SUPPORT_LISTEN
503static struct _listen_profile {
504 const char * name;
505 int          type;
506 int          port;
507 const char * sockaddr;
508 int          proto;
509 int          dir;
510 const char * aiprofile;
511 const char * desc;
512} _g_listen_profiles[] = {
513 // RoarAudio:
[3992]514#ifdef ROAR_HAVE_UNIX
[4058]515 {"roar-usock",     ROAR_SOCKET_TYPE_UNIX,   0,                 "~/" ROAR_DEFAULT_SOCK_USER,
516                    ROAR_PROTO_ROARAUDIO, -1, NULL,
517                    "RoarAudio default user profile"},
518 {"roar-gsock",     ROAR_SOCKET_TYPE_UNIX,   0,                 ROAR_DEFAULT_SOCK_GLOBAL,
519                    ROAR_PROTO_ROARAUDIO, -1, NULL,
520                    "RoarAudio default global profile"},
[3992]521#endif
522#ifdef ROAR_HAVE_IPV4
[4058]523 {"roar-tcp",       ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_PORT, ROAR_DEFAULT_INET4_HOST,
524                    ROAR_PROTO_ROARAUDIO, -1, NULL,
525                    "RoarAudio local TCP profile"},
526 {"roar-tcp-pub",   ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_PORT, ROAR_NET_INET4_ANYHOST,
527                    ROAR_PROTO_ROARAUDIO, -1, NULL,
528                    "RoarAudio network TCP profile"},
[3992]529#endif
530#ifdef ROAR_HAVE_LIBDNET
[4058]531 {"roar-dnet",      ROAR_SOCKET_TYPE_DECNET, 0,                 ROAR_DEFAULT_LISTEN_OBJECT,
532                    ROAR_PROTO_ROARAUDIO, -1, NULL,
533                    "RoarAudio default DECnet"},
[3992]534#endif
535#ifdef ROAR_HAVE_UNIX
[4058]536 {"roar-abstract",  ROAR_SOCKET_TYPE_UNIX,   0,                 "+abstract",        ROAR_PROTO_ROARAUDIO, -1, NULL,
537                    "RoarAudio abstract namespace profile"},
[3992]538#endif
[3956]539
540 // EsounD:
[3992]541#if !defined(ROAR_WITHOUT_DCOMP_EMUL_ESD) && defined(ROAR_HAVE_H_ESD)
542#ifdef ROAR_HAVE_UNIX
[4058]543 {"esd-unix",       ROAR_SOCKET_TYPE_UNIX,   0,                 ROAR_DEFAULT_ESD_GSOCK,
544                    ROAR_PROTO_ESOUND,    -1, NULL,
545                    "EsounD default local profile"},
[3992]546#endif
547#ifdef ROAR_HAVE_IPV4
[4058]548 {"esd-tcp",        ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_ESD_PORT, ROAR_NET_INET4_LOCALHOST,
549                    ROAR_PROTO_ESOUND,    -1, NULL,
550                    "EsounD local TCP profile"},
551 {"esd-tcp-pub",    ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_ESD_PORT, ROAR_NET_INET4_ANYHOST,
552                    ROAR_PROTO_ESOUND,    -1, NULL,
553                    "EsounD network TCP profile"},
[3992]554#endif
555#endif
[3956]556
557 // RSound:
[3992]558#ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND
559#ifdef ROAR_HAVE_UNIX
[4058]560 {"rsound-unix",    ROAR_SOCKET_TYPE_UNIX,   0,                 ROAR_DEFAULT_RSOUND_GSOCK,
561                    ROAR_PROTO_RSOUND,    -1, NULL,
562                    "RSound default local profile"},
[3992]563#endif
564#ifdef ROAR_HAVE_IPV4
[4058]565 {"rsound-tcp",     ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_RSOUND_PORT, ROAR_NET_INET4_LOCALHOST,
566                    ROAR_PROTO_RSOUND,    -1, NULL,
567                    "RSound local TCP profile"},
568 {"rsound-tcp-pub", ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_RSOUND_PORT, ROAR_NET_INET4_ANYHOST,
569                    ROAR_PROTO_RSOUND,    -1, NULL,
570                    "RSound network TCP profile"},
[3992]571#endif
572#ifdef ROAR_HAVE_LIBDNET
[4058]573 {"rsound-dnet",    ROAR_SOCKET_TYPE_DECNET, 0,                 ROAR_DEFAULT_RSOUND_OBJECT,
574                    ROAR_PROTO_RSOUND,    -1, NULL,
575                    "RSound DECnet profile"},
[3992]576#endif
577#endif
[3957]578
579 // PulseAudio Simple:
[3992]580#ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE
581#ifdef ROAR_HAVE_IPV4
[4058]582 {"pas-play-tcp",   ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_PA_PORT, ROAR_NET_INET4_ANYHOST,
583                    ROAR_PROTO_SIMPLE, ROAR_DIR_PLAY, "default",
584                    "PulseAudio Simple TCP play profile"},
585 {"pas-mon-tcp",    ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_PA_PORT, ROAR_NET_INET4_ANYHOST,
586                    ROAR_PROTO_SIMPLE, ROAR_DIR_MONITOR, "default",
587                    "PulseAudio Simple TCP monitor profile"},
[3992]588#endif
589#endif
[3987]590
591 // RPlay:
[3992]592#ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY
593#ifdef ROAR_HAVE_IPV4
[4058]594 {"rplay-tcp",      ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_RPLAY_PORT, ROAR_NET_INET4_LOCALHOST,
595                    ROAR_PROTO_RPLAY,     -1, NULL,
596                    "RPlay local TCP profile"},
597 {"rplay-tcp-pub",  ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_RPLAY_PORT, ROAR_NET_INET4_ANYHOST,
598                    ROAR_PROTO_RPLAY,     -1, NULL,
599                    "RPlay network TCP profile"},
[3992]600#endif
601#endif
[3987]602
[4710]603// Gopher:
604#ifndef ROAR_WITHOUT_DCOMP_EMUL_GOPHER
605 {"gopher-tcp",     ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_GOPHER_PORT, ROAR_NET_INET4_LOCALHOST,
606                    ROAR_PROTO_GOPHER,    -1, NULL,
607                    "Gopher local TCP profile"},
608 {"gopher-tcp-pub", ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_GOPHER_PORT, ROAR_NET_INET4_ANYHOST,
609                    ROAR_PROTO_GOPHER,    -1, NULL,
610                    "Gopher network TCP profile"},
611#endif
612
[3987]613 // End of List:
[3956]614 {NULL, -1, -1, NULL, -1, -1, NULL, NULL}
615};
616
617void listen_listen_profiles (void) {
618 struct _listen_profile * p;
619 char * type;
620 int i;
[3987]621 char port[8];
[3956]622
[3990]623 printf("Name           Type    Address          Port    Protocol  Dir        Audio Profile - Description\n");
[3956]624 printf("------------------------------------------------------------------------------------------------\n");
625      //roar-tcp-pub 0.0.0.0       16002   RoarAudio unknown    (null) - (null)
626
627 for (i = 0; (p = &(_g_listen_profiles[i]))->name != NULL; i++) {
628  switch (p->type) {
629   case ROAR_SOCKET_TYPE_UNIX:   type = "UNIX";   break;
630   case ROAR_SOCKET_TYPE_TCP:    type = "TCP";    break;
631   case ROAR_SOCKET_TYPE_DECNET: type = "DECnet"; break;
632   default:
633     type = "unknown";
634    break;
635  }
[3987]636
637  if ( p->port ) {
[4049]638   snprintf(port, sizeof(port)-1, "%i", p->port);
639   port[sizeof(port)-1] = 0;
[3987]640  } else {
641   strcpy(port, "(none)");
642  }
643
644  printf("%-14s %-7s %-16s %-7s %-9s %-10s %-13s - %s\n",
[3956]645           p->name,
646           type,
[3987]647           p->sockaddr, port,
[3956]648           roar_proto2str(p->proto),
[3957]649           p->dir == -1 ? "(none)" : roar_dir2str(p->dir), p->aiprofile == NULL ? "(none)" : p->aiprofile,
[3956]650           p->desc == NULL ? "" : p->desc);
651 }
652}
653
654int get_listen_profile (const char * name,
655                        int * port, char ** sockaddr, int * type,
656                        int * proto,
657                        int * dir, struct roar_audio_info * info) {
658 static char buf[1024];
659 struct _listen_profile * p;
660 int i;
661
662 for (i = 0; (p = &(_g_listen_profiles[i]))->name != NULL; i++) {
663  if ( !strcasecmp(p->name, name) ) {
664   *port     = p->port;
665
[3959]666   if ( p->type == ROAR_SOCKET_TYPE_UNIX && p->sockaddr[0] != '+' ) {
667    roar_env_render_path_r(buf, sizeof(buf), p->sockaddr);
668   } else {
669    strncpy(buf, p->sockaddr, sizeof(buf));
670   }
[3956]671   *sockaddr = buf;
[4642]672   *type     = p->type;
[3956]673
674   *proto    = p->proto;
675   *dir      = p->dir;
676
677   if ( p->aiprofile != NULL ) {
678    if ( roar_profile2info(info, p->aiprofile) == -1 ) {
679     ROAR_ERR("Unknown audio profile: %s", p->aiprofile);
680     return -1;
681    }
682   }
683   return 0;
684  }
685 }
686
687 return -1;
688}
689#endif
690
[3252]691int add_listen (char * addr, int port, int sock_type, char * user, char * group, int proto, int dir, struct roar_audio_info * info) {
[2530]692#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
693 struct group   * grp  = NULL;
694#endif
695#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
696 struct passwd  * pwd  = NULL;
697#endif
698#ifdef ROAR_HAVE_UNIX
699 char * env_roar_proxy_backup;
700#endif
701 int    sockid = -1;
[3907]702#ifdef ROAR_HAVE_UNIX
[2530]703 int    sock;
[3907]704#endif
[2530]705 int    i;
706
[4055]707 ROAR_INFO("add_listen(addr='%s', port=%i, sock_type=%i, user='%s', group='%s', proto=%s(%i), dir=%s(%i), info={.rate=%u, .bits=%u, .channels=%u, .codec=%s(%u)}): trying to add listen socket",
708            ROAR_DBG_INFO_INFO,
709            addr, port, sock_type, user, group, roar_proto2str(proto), proto, roar_dir2str(dir), dir,
710            info->rate, info->bits, info->channels, roar_codec2str(info->codec), info->codec);
711
[2530]712 if ( *addr != 0 ) {
713  for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
[3802]714   if ( ! g_listen[i].used ) {
[2530]715    sockid = i;
716    break;
717   }
718  }
719
720  if ( sockid == -1 )
721   return -1;
722
[3128]723  g_listen[sockid].proto = proto;
[2530]724
725  ROAR_DBG("add_listen(*): proto=0x%.4x", proto);
726
[3802]727  if ( roar_vio_open_socket_listen(&(g_listen[sockid].sock), sock_type, addr, port) == -1 ) {
[2530]728#ifdef ROAR_HAVE_UNIX
729   if ( *addr == '/' ) {
730    if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) {
731     env_roar_proxy_backup = strdup(env_roar_proxy_backup);
732     unsetenv("ROAR_PROXY");
733    }
734    if ( (sock = roar_socket_connect(addr, port)) != -1 ) {
735     close(sock);
[3040]736     ROAR_ERR("Can not open listen socket: Socket allready in use");
[4641]737     return -1;
[2530]738    } else {
739     unlink(addr);
[3802]740     if ( roar_vio_open_socket_listen(&(g_listen[sockid].sock), sock_type, addr, port) == -1 ) {
[3040]741      ROAR_ERR("Can not open listen socket: %s", strerror(errno));
[4641]742      return -1;
[2530]743     }
744    }
745    if ( env_roar_proxy_backup != NULL ) {
746     setenv("ROAR_PROXY", env_roar_proxy_backup, 0);
747     free(env_roar_proxy_backup);
748    }
749#else
750   if (0) { // noop
751#endif
752   } else {
[3041]753    ROAR_ERR("Can not open listen socket: %s", strerror(errno));
[4641]754    return -1;
[2530]755   }
756  }
757
[4641]758  ROAR_DBG("add_listen(*) = ?");
759
[2530]760#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
[2753]761  if ( group != NULL ) {
762   if ( (grp = getgrnam(group)) == NULL ) {
763    ROAR_ERR("Can not get GID for group %s: %s", group, strerror(errno));
764   }
[2530]765  }
766#endif
[4641]767
768  ROAR_DBG("add_listen(*) = ?");
769
[2530]770#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
[2752]771  if ( user ) {
[2530]772   if ( (pwd = getpwnam(user)) == NULL ) {
773    ROAR_ERR("Can not get UID for user %s: %s", user, strerror(errno));
774   }
775  }
776#endif
777
[4641]778  ROAR_DBG("add_listen(*) = ?");
779
[2530]780#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_UNIX)
781  if ( *addr == '/' ) {
[2753]782   if ( grp || pwd ) {
783     if ( chown(addr, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 )
[4641]784      return -1;
[2753]785   }
[2530]786#ifdef ROAR_HAVE_GETUID
[2753]787   if ( grp ) {
[2530]788    if ( getuid() == 0 )
789     if ( chmod(addr, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1 )
[4641]790      return -1;
[2753]791   }
[2530]792#endif
793  }
794#endif
795 }
796
[4641]797 ROAR_DBG("add_listen(*) = ?");
798
[2736]799 // in case we opened the listening socket correctly.
[3256]800 if ( dir == -1 )
801  dir = ROAR_DIR_PLAY;
802
[3252]803 g_listen[sockid].inst.stpl.dir = dir;
804 memcpy(&(g_listen[sockid].inst.stpl.info), info, sizeof(struct roar_audio_info));
[3256]805
806 switch (dir) {
807  case ROAR_DIR_PLAY:
808  case ROAR_DIR_RECORD:
809  case ROAR_DIR_MONITOR:
810  case ROAR_DIR_FILTER:
811  case ROAR_DIR_BIDIR:
812    if ( !g_listen[sockid].inst.stpl.info.rate )
813     g_listen[sockid].inst.stpl.info.rate = g_sa->rate;
814
815    if ( !g_listen[sockid].inst.stpl.info.bits )
816     g_listen[sockid].inst.stpl.info.bits = g_sa->bits;
817
818    if ( !g_listen[sockid].inst.stpl.info.channels )
819     g_listen[sockid].inst.stpl.info.channels = g_sa->channels;
820
821    if ( !g_listen[sockid].inst.stpl.info.codec )
822     g_listen[sockid].inst.stpl.info.codec = g_sa->codec;
823   break;
824 }
825
[3802]826 g_listen[sockid].used = 1;
827 server[sockid]        = addr;
828
[2530]829 return 0;
830}
831#endif
832
[2339]833int update_stream_flags (char * str) {
834 int    dir;
835 char * flags;
836 char * k;
837 int    op;
838 int    flag;
839
840 if ( (flags = strstr(str, "=")) == NULL )
841  return -1;
842
843 *flags = 0;
844  flags++;
845
846 if ( (dir = roar_str2dir(str)) == -1 )
847  return -1;
848
849 while (flags != NULL) {
850  k = flags;
851  flags = strstr(flags, ",");
852
853  if ( flags != NULL )
854   *(flags++) = 0;
855
856  switch (*k) {
[2340]857   case '+': k++; op = ROAR_SET_FLAG;   break;
858   case '-': k++; op = ROAR_RESET_FLAG; break;
[2339]859   default:
[2340]860     op = ROAR_SET_FLAG;
[2339]861  }
862
863  flag = 0;
864
865  if ( !strcmp(k, "sync") ) {
866   flag = ROAR_FLAG_SYNC;
867  } else if ( !strcmp(k, "meta") ) {
868   flag = ROAR_FLAG_META;
869  } else if ( !strcmp(k, "cleanmeta") ) {
870   flag = ROAR_FLAG_CLEANMETA;
871  } else if ( !strcmp(k, "pause") ) {
872   flag = ROAR_FLAG_PAUSE;
873  } else if ( !strcmp(k, "mute") ) {
874   flag = ROAR_FLAG_MUTE;
875  } else if ( !strcmp(k, "antiecho") ) {
876   flag = ROAR_FLAG_ANTIECHO;
[2413]877  } else if ( !strcmp(k, "passmixer") ) {
878   flag = ROAR_FLAG_PASSMIXER;
[2339]879  } else {
880   return -1;
881  }
882
883  g_config->streams[dir].flags |= flag;
884
[2340]885  if ( op == ROAR_RESET_FLAG )
[2339]886   g_config->streams[dir].flags -= flag;
887 }
888
889 return 0;
890}
891
[4140]892#ifdef ROAR_DRIVER_DEFAULT
893#define add_default_output add_output
894#else
895int add_default_output (char * drv, char * dev, char * opts, int prim, int count) {
[4141]896 char * drvs[] = {
[4189]897  // operating system depended things:
898#ifdef __OpenBSD__
899  /* OpenBSD use sndio natively, this check is discusses with upstream (See ML archive August 2010) */
900  "sndio",
901#endif
[4144]902  // native and pseudo-native interfaces:
903  "oss", "alsa", "sndio", "wmm",
904  // sound libs:
905  "ao", "portaudio",
906  // other sound systems:
907  "esd", "rsound", "pulsesimple", "roar",
908  // specal buildins:
909  "sysclock", "null",
910  // terminator:
[4140]911  NULL
912 };
913 int i;
914 int ret;
[4144]915 int _alive;
[4140]916
917 if ( drv != NULL )
918  return add_output(drv, dev, opts, prim, count);
919
920 if ( dev != NULL ) {
[4141]921  ROAR_WARN("add_default_output(drv=(none), dev='%s', opts='%s', prim=%i, count=%i): It's not recommended to use device name without driver name.", dev, opts, prim, count);
[4140]922 }
923
924 for (i = 0; drvs[i] != NULL; i++) {
[4141]925  ROAR_INFO("add_default_output(*): trying driver %s", ROAR_DBG_INFO_INFO, drvs[i]);
[4144]926  _alive = alive; // save global alive setting
927
[4140]928  ret = add_output(drvs[i], dev, opts, prim, count);
929  if ( ret != -1 )
930   return ret;
[4144]931
932  alive = _alive; // restore global alive setting
[4141]933  ROAR_INFO("add_default_output(*): Driver %s faild to load", ROAR_DBG_INFO_VERBOSE, drvs[i]);
[4140]934 }
935
936 return -1;
937}
938#endif
939
[1145]940int add_output (char * drv, char * dev, char * opts, int prim, int count) {
[933]941 int stream;
942 struct roar_stream * s;
943 struct roar_stream_server * ss;
[938]944 char * k, * v;
[1208]945#ifdef ROAR_DRIVER_CODEC
946 char * to_free = NULL;
947#endif
[1926]948 int sync = 0, f_mmap = 0;
[1522]949 int32_t blocks = -1, blocksize = -1;
[1920]950 int dir = ROAR_DIR_OUTPUT;
[1991]951 int error = 0;
952 // DMX:
953 int32_t channel  = -1;
954 int32_t universe = -1;
955 uint16_t tu16;
[2085]956 float q = -32e6;
[933]957
[4055]958 ROAR_INFO("add_output(drv='%s', dev='%s', opts='%s', prim=%i, count=%i): trying to add output driver", ROAR_DBG_INFO_INFO, drv, dev, opts, prim, count);
[933]959
[1145]960 if ( drv == NULL && count == 0 ) {
[4141]961#ifdef ROAR_DRIVER_DEFAULT
[1145]962  drv  = ROAR_DRIVER_DEFAULT;
963  prim = 1;
964  sync = 1;
[1208]965
966#ifdef ROAR_DRIVER_CODEC
967  if ( opts == NULL ) {
968   opts = to_free = strdup("codec=" ROAR_DRIVER_CODEC);
969  }
970#endif
[4141]971#else
972  ROAR_ERR("add_output(*): Can not find default driver");
973  return -1;
974#endif
[1145]975 }
976
[1227]977 if ( opts == NULL && count == 0 ) {
978  sync = 1;
979  prim = 1; // if ( prim == 0 ) prim = 1; -> prim allways = 1
980 }
981
[2785]982 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
983
[933]984 if ( (stream = streams_new()) == -1 ) {
[938]985  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
[982]986  if ( prim ) alive = 0;
[933]987  return -1;
988 }
989
[2785]990 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
991
[933]992 streams_get(stream, &ss);
993 s = ROAR_STREAM(ss);
994
[2785]995 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
996
[2511]997 memset(&(s->info), 0xFF, sizeof(struct roar_audio_info)); // set everything to -1
[933]998
999 s->pos_rel_id = -1;
1000// s->info.codec = codec;
1001
[2785]1002 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
1003
[2788]1004 if ( opts == NULL ) {
1005  k = NULL;
1006 } else {
1007  k = strtok(opts, ",");
1008 }
[2786]1009
1010 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s'): initial k='%s'(%p)", drv, dev, opts, k, k);
1011
[938]1012 while (k != NULL) {
1013//  ROAR_WARN("add_output(*): opts: %s", k);
1014
1015  if ( (v = strstr(k, "=")) != NULL ) {
1016   *v++ = 0;
1017  }
1018
1019  ROAR_DBG("add_output(*): opts: k='%s', v='%s'", k, v);
1020  if ( strcmp(k, "rate") == 0 ) {
1021   s->info.rate = atoi(v);
1022  } else if ( strcmp(k, "channels") == 0 ) {
1023   s->info.channels = atoi(v);
1024  } else if ( strcmp(k, "bits") == 0 ) {
1025   s->info.bits = atoi(v);
1026  } else if ( strcmp(k, "codec") == 0 ) {
[2511]1027   if ( (s->info.codec = roar_str2codec(v)) == -1 ) {
[938]1028    ROAR_ERR("add_output(*): unknown codec '%s'", v);
[1991]1029    error++;
[938]1030   }
[2085]1031  } else if ( strcmp(k, "q") == 0 ) {
1032   q = atof(v);
[1221]1033  } else if ( strcmp(k, "blocks") == 0 ) {
1034   blocks = atoi(v);
[1522]1035  } else if ( strcmp(k, "blocksize") == 0 ) {
1036   blocksize = atoi(v);
[1926]1037  } else if ( strcmp(k, "mmap") == 0 ) {
1038   f_mmap = 1;
[1919]1039  } else if ( strcmp(k, "subsystem") == 0 ) {
1040   if ( !strcasecmp(v, "wave") || !strcasecmp(v, "waveform") ) {
[1920]1041    dir = ROAR_DIR_OUTPUT;
[2494]1042#ifndef ROAR_WITHOUT_DCOMP_MIDI
[1919]1043   } else if ( !strcasecmp(v, "midi") ) {
1044    dir = ROAR_DIR_MIDI_OUT;
[2494]1045#endif
1046#ifndef ROAR_WITHOUT_DCOMP_LIGHT
[1919]1047   } else if ( !strcasecmp(v, "light") ) {
1048    dir = ROAR_DIR_LIGHT_OUT;
[2494]1049#endif
1050#ifndef ROAR_WITHOUT_DCOMP_RAW
[2234]1051   } else if ( !strcasecmp(v, "raw") ) {
1052    dir = ROAR_DIR_RAW_OUT;
[2494]1053#endif
[2681]1054   } else if ( !strcasecmp(v, "complex") ) {
1055    dir = ROAR_DIR_COMPLEX_OUT;
[1919]1056   } else {
[2494]1057    ROAR_ERR("add_output(*): unknown/unsupported subsystem '%s'", k);
[1991]1058    error++;
1059   }
1060  // DMX:
1061  } else if ( strcmp(k, "channel") == 0 ) {
1062   channel  = atoi(v);
1063   if ( channel < 0 || channel > 65535 ) {
1064    ROAR_ERR("add_output(*): Invalide channel (not within 0..65535): %i", channel);
1065    channel = -1;
1066    error++;
[1919]1067   }
[1991]1068  } else if ( strcmp(k, "universe") == 0 ) {
1069   universe = atoi(v);
1070   if ( universe < 0 || universe > 255 ) {
1071    ROAR_ERR("add_output(*): Invalide universe (not within 0..255): %i", universe);
1072    universe = -1;
1073    error++;
1074   }
1075
[2115]1076  } else if ( strcmp(k, "name") == 0 ) {
1077   if ( streams_set_name(stream, v) == -1 ) {
1078    ROAR_ERR("add_output(*): Can not set Stream name");
1079    error++;
1080   }
[1991]1081
[1032]1082  } else if ( strcmp(k, "meta") == 0 ) {
1083   streams_set_flag(stream, ROAR_FLAG_META);
[1117]1084  } else if ( strcmp(k, "sync") == 0 ) {
1085   sync = 1;
[1221]1086  } else if ( strcmp(k, "primary") == 0 ) {
1087   prim = 1;
1088
1089  } else if ( strcmp(k, "cleanmeta") == 0 ) {
1090   streams_set_flag(stream, ROAR_FLAG_CLEANMETA);
1091  } else if ( strcmp(k, "autoconf") == 0 ) {
[1531]1092   streams_set_flag(stream, ROAR_FLAG_AUTOCONF);
[2413]1093  } else if ( strcmp(k, "recsource") == 0 ) {
1094   streams_set_flag(stream, ROAR_FLAG_RECSOURCE);
1095  } else if ( strcmp(k, "passmixer") == 0 ) {
1096   streams_set_flag(stream, ROAR_FLAG_PASSMIXER);
[938]1097  } else {
1098   ROAR_ERR("add_output(*): unknown option '%s'", k);
[1991]1099   error++;
1100  }
1101
1102  if ( error ) {
[938]1103   streams_delete(stream);
[982]1104   if ( prim ) alive = 0;
[1208]1105#ifdef ROAR_DRIVER_CODEC
1106   if ( to_free != NULL )
1107    free(to_free);
1108#endif
[938]1109   return -1;
1110  }
1111
1112  k = strtok(NULL, ",");
1113 }
1114
[2785]1115 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
1116
[2511]1117 // set audio info...
1118 switch (dir) {
1119  case ROAR_DIR_LIGHT_OUT:
1120    switch (s->info.codec) {
1121     case ROAR_CODEC_DMX512:
1122     case -1:
1123       if ( s->info.rate == -1 )
1124        s->info.rate = ROAR_OUTPUT_CFREQ;
1125
1126       s->info.channels =   0;
1127       s->info.bits     =   8;
1128       s->info.codec    = ROAR_CODEC_DMX512; // in case codec == -1
1129      break;
1130    }
1131   break;
1132  case ROAR_DIR_MIDI_OUT:
1133    switch (s->info.codec) {
1134     case ROAR_CODEC_MIDI:
1135     case -1:
1136       if ( s->info.rate == -1 )
1137        s->info.rate    = ROAR_MIDI_TICKS_PER_BEAT;
1138
1139       s->info.channels = ROAR_MIDI_CHANNELS_DEFAULT;
1140       s->info.bits     = ROAR_MIDI_BITS;
1141       s->info.codec    = ROAR_CODEC_MIDI; // in case codec == -1
1142      break;
1143    }
1144   break;
1145  case ROAR_DIR_RAW_OUT:
1146    if ( s->info.rate == -1 )
1147     s->info.rate = 0;
1148    if ( s->info.bits == -1 )
1149     s->info.bits = 0;
1150    if ( s->info.channels == -1 )
1151     s->info.channels = 0;
1152    if ( s->info.codec == -1 )
1153     s->info.codec = 0;
1154   break;
1155 }
1156
1157 if ( s->info.rate == -1 )
1158  s->info.rate = g_sa->rate;
1159 if ( s->info.bits == -1 )
1160  s->info.bits = g_sa->bits;
1161 if ( s->info.channels == -1 )
1162  s->info.channels = g_sa->channels;
1163 if ( s->info.codec == -1 )
1164  s->info.codec = g_sa->codec;
1165
1166 ROAR_DBG("add_output(*): s->info = {.rate=%i, .bits=%i, .channels=%i, .codec=%i}", s->info.rate, s->info.bits, s->info.channels, s->info.codec);
1167
[1919]1168 if ( streams_set_dir(stream, dir, 1) == -1 ) {
1169  streams_delete(stream);
1170  return -1;
1171 }
1172
[1208]1173#ifdef ROAR_DRIVER_CODEC
1174 if ( to_free != NULL )
1175  free(to_free);
1176#endif
1177
[2511]1178 if ( s->info.codec == ROAR_CODEC_ALAW || s->info.codec == ROAR_CODEC_MULAW )
[941]1179  s->info.bits = 8; // needed to open OSS driver, will be overriden by codecfilter
1180
[2511]1181 ROAR_STREAM_SERVER(s)->codec_orgi = s->info.codec;
[933]1182
[2364]1183 if ( driver_openvio(&(ss->vio), &(ss->driver_id), drv, dev, &(s->info), -1, ss) == -1 ) {
[1581]1184  ss->driver_id = -1; // don't close a driver not opened...
1185  memset(&(ss->vio), 0, sizeof(struct roar_vio_calls));
[933]1186  streams_delete(stream);
[938]1187  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
[982]1188  if ( prim ) alive = 0;
[933]1189  return -1;
1190 }
1191
[1528]1192 roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAMID, &stream); // ignore errors here
1193 roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAM,   s); // ignore errors here
1194
[1221]1195 if ( blocks != -1 )
1196  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLOCKS, &blocks);
1197
[1522]1198 if ( blocksize != -1 )
1199  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLKSIZE, &blocksize);
1200
[1991]1201 // TODO: we shoudld *really* check for errors here...
1202 if ( channel != -1 ) {
1203  tu16 = channel;
1204  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXSCHAN, &tu16);
1205 }
1206 if ( universe != -1 ) {
1207  tu16 = universe;
1208  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXUNIV, &tu16);
1209 }
1210
[1156]1211 ROAR_DBG("add_output(*): ss->driver_id=%i", ss->driver_id);
1212
[938]1213 streams_set_fh(stream, -1); // update some internal structures
1214
[2087]1215 if ( q > -1e6 ) {
1216  ROAR_DBG("add_output(*): setting q=%f", q);
1217  streams_ctl(stream, ROAR_CODECFILTER_CTL_SET_Q|ROAR_STREAM_CTL_TYPE_FLOAT, &q);
1218 }
1219
[2490]1220 client_stream_add(g_self_client, stream);
[933]1221
[1200]1222 if ( prim ) {
[961]1223  streams_mark_primary(stream);
[1200]1224  s->pos_rel_id = stream;
1225 }
[961]1226
[1120]1227 if ( sync ) {
[1117]1228  streams_set_flag(stream, ROAR_FLAG_SYNC);
[1120]1229 } else {
1230  streams_reset_flag(stream, ROAR_FLAG_SYNC);
1231 }
[1117]1232
[1926]1233 if ( f_mmap )
1234  streams_set_flag(stream, ROAR_FLAG_MMAP);
1235
[2511]1236 ROAR_DBG("add_output(*): s->info = {.rate=%i, .bits=%i, .channels=%i, .codec=%i}", s->info.rate, s->info.bits, s->info.channels, s->info.codec);
[933]1237 return 0;
[932]1238}
1239
[4358]1240#ifndef ROAR_WITHOUT_DCOMP_MIXER
1241int add_hwmixer (char * drv, char * dev, char * opts, int prim, int count) {
[4381]1242 char * basename = NULL;
1243 char * subnames = NULL;
1244 char * k, * v;
[4360]1245 int basestream = streams_new();
1246 int ret;
[4381]1247 int error = 0;
[4360]1248//int hwmixer_open(int basestream, char * drv, char * dev, int fh, char * basename, char * subnames) {
1249
[4369]1250 if ( basestream == -1 )
1251  return -1;
1252
[4382]1253 client_stream_add(g_self_client, basestream);
[4369]1254
[4381]1255 if ( opts == NULL ) {
1256  k = NULL;
1257 } else {
1258  k = strtok(opts, ",");
1259 }
1260
1261 while (k != NULL) {
1262//  ROAR_WARN("add_output(*): opts: %s", k);
1263
1264  if ( (v = strstr(k, "=")) != NULL ) {
1265   *v++ = 0;
1266  }
1267
1268  if ( strcmp(k, "primary") == 0 ) {
1269   prim = 1;
1270
1271  } else if ( strcmp(k, "name") == 0 ) {
1272   basename = v;
1273  } else if ( strcmp(k, "subs") == 0 ) {
1274   subnames = v;
1275
1276  } else if ( strcmp(k, "autoconf") == 0 ) {
1277   streams_set_flag(basestream, ROAR_FLAG_AUTOCONF);
1278  } else if ( strcmp(k, "passmixer") == 0 ) {
1279   streams_set_flag(basestream, ROAR_FLAG_PASSMIXER);
1280  } else {
1281   ROAR_ERR("add_hwmixer(*): unknown option '%s'", k);
1282   error++;
1283  }
1284
1285  if ( error ) {
1286   streams_delete(basestream);
1287   if ( prim ) alive = 0;
1288   return -1;
1289  }
1290
1291  k = strtok(NULL, ",");
1292 }
1293
[4360]1294 if ( prim ) {
1295  streams_mark_primary(basestream);
1296 }
1297
[4381]1298 ret = hwmixer_open(basestream, drv, dev, -1, basename, subnames);
[4360]1299
1300 if ( ret == -1 ) {
1301  streams_delete(basestream);
1302 }
1303
1304 return ret == -1 ? -1 : 0;
[4358]1305}
1306#endif
1307
[3373]1308// X11:
1309#ifdef ROAR_HAVE_LIBX11
1310int register_x11 (int unreg, char * sockname) {
1311 struct roar_x11_connection * x11con = NULL;
1312 int ret = 0;
1313
[4103]1314 if ( (x11con = roar_x11_connect(x11display)) == NULL ) {
[4155]1315  ROAR_ERR("Can not connect to X11 server for %sregistering", unreg ? "un" : "");
[3373]1316  return -1;
[4103]1317 }
[3373]1318
1319 if ( unreg ) {
[4103]1320  if ( roar_x11_delete_prop(x11con, "ROAR_SERVER") == -1 ) {
[3373]1321   ret = -1;
[4103]1322   ROAR_ERR("Error while unregistereing from X11", ROAR_DBG_INFO_INFO);
1323  } else {
1324   ROAR_INFO("Successfully unregistered from X11", ROAR_DBG_INFO_INFO);
1325  }
[3373]1326 } else {
[4103]1327  if ( roar_x11_set_prop(x11con, "ROAR_SERVER", sockname) == -1 ) {
[3373]1328   ret = -1;
[4103]1329   ROAR_ERR("Error while registereing to X11", ROAR_DBG_INFO_INFO);
1330  } else {
1331   ROAR_INFO("Successfully registered to X11", ROAR_DBG_INFO_INFO);
1332  }
[3373]1333 }
1334
1335 roar_x11_disconnect(x11con);
1336
1337 return ret;
1338}
1339#endif
[1993]1340
1341// SLP:
1342void register_slp_callback(SLPHandle hslp, SLPError errcode, void * cookie) {
1343 /* return the error code in the cookie */
1344 *(SLPError*)cookie = errcode;
1345}
1346
1347int register_slp (int unreg, char * sockname) {
1348#ifdef ROAR_HAVE_LIBSLP
1349 static int regged = 0;
1350 static char * sn = NULL;
1351 SLPError err;
1352 SLPError callbackerr;
1353 SLPHandle hslp;
1354 char addr[1024];
1355 char attr[1024] = "";
[2017]1356 char * location;
[4421]1357 char * description;
[4577]1358 char * standards;
[1993]1359
1360 if ( sockname != NULL )
1361  sn = sockname;
1362
[3076]1363 snprintf(addr, sizeof(addr), ROAR_SLP_URL_TYPE_ROAR "://%s", sn);
[1993]1364
1365 err = SLPOpen("en", SLP_FALSE, &hslp);
1366
1367 if (err != SLP_OK) {
1368  ROAR_ERR("Error opening slp handle: Error #%i", err);
1369  return -1;
1370 }
1371
1372 if (!unreg) {
[2017]1373
1374  if ( SLPEscape(g_config->location, &location, SLP_FALSE) != SLP_OK ) {
1375   ROAR_ERR("Error using SLPEscape() on server location, really bad!");
1376   SLPClose(hslp);
1377   return -1;
1378  }
1379
[4421]1380  if ( SLPEscape(g_config->description, &description, SLP_FALSE) != SLP_OK ) {
1381   ROAR_ERR("Error using SLPEscape() on server location, really bad!");
1382   SLPClose(hslp);
1383   return -1;
1384  }
1385
[4577]1386  standards = stds_string();
1387
1388  if ( standards == NULL ) {
1389   if ( (standards = roar_mm_malloc(1)) == NULL ) {
1390    SLPClose(hslp);
1391    return -1;
1392   }
1393   standards[0] = 0;
1394  }
1395
[1995]1396  snprintf(attr, sizeof(attr), "(wave-rate=%i),(wave-channels=%i),(wave-bits=%i),"
[2494]1397#ifndef ROAR_WITHOUT_DCOMP_LIGHT
1398                               "(light-channels=%i),"
1399#endif
[4577]1400                               "(standards=%s),"
[4421]1401                               "(location=%s),(description=%s)",
[1995]1402           g_sa->rate, g_sa->channels, g_sa->bits,
[2494]1403#ifndef ROAR_WITHOUT_DCOMP_LIGHT
[2017]1404           g_light_state.channels,
[2494]1405#endif
[4577]1406           standards,
[4421]1407           location, description
[1995]1408          );
1409
[4577]1410  roar_mm_free(standards);
1411
[1993]1412  /* Register a service with SLP */
1413  err = SLPReg(hslp,
1414               addr,
1415               SLP_LIFETIME_MAXIMUM,
1416               0,
1417               attr,
1418               SLP_TRUE,
1419               register_slp_callback,
1420               &callbackerr);
[1994]1421  regged = 1;
1422 } else if ( unreg && regged ) {
1423  err = SLPDereg(hslp, addr, register_slp_callback, &callbackerr);
1424  regged = 0;
1425 } else {
1426  SLPClose(hslp);
1427  return -1;
1428 }
[1993]1429
[1994]1430 /* err may contain an error code that occurred as the slp library    */
1431 /* _prepared_ to make the call.                                     */
1432 if ( err != SLP_OK ) {
1433  ROAR_ERR("Error (de)registering service with slp: Error #%i", err);
1434  return -1;
1435 }
1436
1437 /* callbackerr may contain an error code (that was assigned through */
1438 /* the callback cookie) that occurred as slp packets were sent on    */
1439 /* the wire */
1440 if (callbackerr != SLP_OK) {
1441  ROAR_ERR("Error (de)registering service with slp: Error #%i", callbackerr);
1442  return -1;
[1993]1443 }
1444
1445 SLPClose(hslp);
1446 return 0;
1447#else
1448 return -1;
1449#endif
1450}
1451
[4481]1452static int auth_setup (enum roard_client_acclev none_acclev,
1453                       enum roard_client_acclev trust_acclev, int trust_root, uid_t trust_uid, gid_t trust_gid) {
1454 union auth_typeunion * key;
1455 size_t i;
1456
[4482]1457 // Info:
1458 // if a authlevel is <= ACCLEV_IDENTED we do not need to add this to the keyring
1459 // as ACCLEV_IDENTED is already gained if IDENTIFY call was done correctly.
[4481]1460
[4482]1461 if ( !(none_acclev <= ACCLEV_IDENTED) ) {
1462  if ( auth_addkey_anonymous(none_acclev) == -1 )
1463   return -1;
1464 }
[4481]1465
[4482]1466 if ( !(trust_acclev <= ACCLEV_IDENTED) ) {
1467  if ( (key = auth_regkey_simple(ROAR_AUTH_T_TRUST, trust_acclev)) == NULL )
1468   return -1;
[4481]1469
[4482]1470  // zerosize all counters.
1471  memset(key, 0, sizeof(union auth_typeunion));
[4481]1472
[4482]1473  i = 0;
1474
1475  if ( trust_uid != -1 )
1476   key->trust.uids[i++] = trust_uid;
[4481]1477
1478#ifdef ROAR_ROOT_UID
[4482]1479  if ( trust_root )
1480   key->trust.uids[i++] = ROAR_ROOT_UID;
[4481]1481#endif
1482
[4482]1483  key->trust.uids_len = i;
[4481]1484
[4482]1485  i = 0;
[4481]1486
[4482]1487  if ( trust_gid != -1 )
1488   key->trust.gids[i++] = trust_gid;
[4481]1489
[4482]1490  key->trust.gids_len = i;
1491 }
[4481]1492
1493 return 0;
1494}
1495
[1993]1496
1497// MAIN:
1498
[4053]1499#define _CKHAVEARGS(x) if ( (i + (x)) >= argc ) { \
1500                        ROAR_ERR("Option %s requires more arguments. See --help for more details.", k); \
1501                        return 70; \
1502                       }
[4052]1503
[1503]1504#ifdef ROAR_HAVE_MAIN_ARGS
[0]1505int main (int argc, char * argv[]) {
[1503]1506#else
1507int main (void) {
1508#endif
1509#ifdef ROAR_HAVE_MAIN_ARGS
[4722]1510 enum action action = START;
[0]1511 int i;
1512 char * k;
[1503]1513#endif
[2787]1514#if defined(ROAR_SUPPORT_LISTEN) && defined(ROAR_HAVE_GETUID)
[905]1515 char user_sock[80]  = {0};
[1494]1516#endif
[1609]1517 struct roar_audio_info sa, max_sa;
1518 struct roard_config config;
[1486]1519#ifdef ROAR_HAVE_FORK
[905]1520 int    daemon       = 0;
[1486]1521#endif
[905]1522 int    realtime     = 0;
1523 int    sysclocksync = 0;
[1207]1524 char * driver    = NULL;
1525 char * device    = NULL;
[1503]1526#ifdef ROAR_HAVE_MAIN_ARGS
[1207]1527 char * opts      = NULL;
[1503]1528#endif
[60]1529// char * server = ROAR_DEFAULT_SOCK_GLOBAL;
[1494]1530#ifdef ROAR_SUPPORT_LISTEN
[2530]1531 int    port       = ROAR_DEFAULT_PORT;
1532 char * sock_addr  = NULL;
1533 int    sock_proto = ROAR_PROTO_ROARAUDIO;
[3252]1534 int    sock_dir   = -1;
1535 struct roar_audio_info sock_info = {0, 0, 0, 0};
[1494]1536#endif
[0]1537 int               drvid;
[2486]1538#ifndef ROAR_WITHOUT_DCOMP_SOURCES
[550]1539 char * s_drv     = "cf";
[1110]1540 char * s_dev     = NULL;
[444]1541 char * s_con     = NULL;
1542 char * s_opt     = NULL;
1543 int    s_prim    = 0;
[2486]1544#endif
[1207]1545 char * o_drv     = getenv("ROAR_DRIVER");
1546 char * o_dev     = getenv("ROAR_DEVICE");
[932]1547 char * o_opts    = NULL;
[961]1548 int    o_prim    = 0;
[1145]1549 int    o_count   = 0;
[4358]1550#ifndef ROAR_WITHOUT_DCOMP_MIXER
1551 char * m_drv     = NULL;
1552 char * m_dev     = NULL;
1553 char * m_opts    = NULL;
1554 int    m_prim    = 0;
1555 int    m_count   = 0;
1556#endif
[4481]1557 enum roard_client_acclev none_acclev  = ACCLEV_ALL;
1558 enum roard_client_acclev trust_acclev = ACCLEV_ALL;
1559 int                      trust_root   = 1;
[2494]1560#ifndef ROAR_WITHOUT_DCOMP_LIGHT
[1923]1561 int    light_channels = LIGHT_CHANNELS_DEFAULT;
[2494]1562#endif
[2751]1563#ifdef ROAR_DEFAULT_SOCKGRP
[450]1564 char * sock_grp  = ROAR_DEFAULT_SOCKGRP;
[2751]1565#else
1566 char * sock_grp  = NULL;
1567#endif
[444]1568 char * sock_user = NULL;
[1494]1569#ifdef ROAR_SUPPORT_LISTEN
[517]1570 int    sock_type = ROAR_SOCKET_TYPE_UNKNOWN;
[1494]1571#endif
[1993]1572#ifdef ROAR_HAVE_LIBSLP
1573 int    reg_slp   = 0;
1574#endif
[3373]1575#ifdef ROAR_HAVE_LIBX11
1576 int    reg_x11   = 0;
1577#endif
[1486]1578#ifdef ROAR_HAVE_CHROOT
[444]1579 char * chrootdir = NULL;
[1486]1580#endif
1581#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
[446]1582 struct group   * grp  = NULL;
[1486]1583#endif
1584#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
[446]1585 struct passwd  * pwd  = NULL;
[1486]1586#endif
1587#ifdef ROAR_HAVE_GETSERVBYNAME
[446]1588 struct servent * serv = NULL;
[1486]1589#endif
[0]1590 DRIVER_USERDATA_T drvinst;
[39]1591 struct roar_client * self = NULL;
[508]1592#ifdef ROAR_HAVE_LIBDNET
1593 char decnethost[80];
1594#endif
[2104]1595#ifdef SUPPORT_PIDFILE
1596 struct roar_vio_calls pidfile_vio;
1597#endif
[0]1598
[2784]1599 ROAR_DBG("main(*): starting roard...");
1600
[0]1601 g_standby       =  0;
[920]1602 g_autostandby   =  0;
[982]1603 alive           =  1;
[1494]1604#ifdef ROAR_SUPPORT_LISTEN
[1155]1605 g_no_listen     =  0;
[1494]1606#else
1607 g_terminate     =  1;
1608#endif
[0]1609
[2970]1610 g_verbose       = ROAR_DBG_INFO_NONE;
1611
[0]1612 sa.bits     = ROAR_BITS_DEFAULT;
1613 sa.channels = ROAR_CHANNELS_DEFAULT;
1614 sa.rate     = ROAR_RATE_DEFAULT;
1615 sa.codec    = ROAR_CODEC_DEFAULT;
1616
[1609]1617 g_sa        = &sa;
1618 g_max_sa    = &max_sa;
1619
1620 memcpy(g_max_sa, g_sa, sizeof(max_sa));
1621
[4101]1622 counters_init();
1623
[1609]1624 g_config = &config;
1625
1626 if ( init_config() == -1 ) {
1627  ROAR_ERR("Can not init default config!");
1628  return 1;
1629 }
[0]1630
[2968]1631 // load config
1632 roar_libroar_get_config();
1633
[4323]1634 // init notify core:
1635 // TODO: reconsider number of lists.
1636 if ( roar_notify_core_new_global(-1) == -1 ) {
1637  ROAR_ERR("Can not init notify core!");
1638  return 1;
1639 }
1640
[4324]1641 if ( roar_notify_core_register_proxy(NULL, roar_notify_proxy_std, NULL) == -1 ) {
1642  ROAR_ERR("Can not init notify core!");
1643  return 1;
1644 }
1645
1646#ifdef DEBUG
[4418]1647 // enable early in case we have DEBUG set.
[4324]1648 dbg_notify_cb_register();
1649#endif
1650
[4469]1651 if ( auth_init() == -1 ) {
1652  ROAR_ERR("Can not init auth subsystem!");
1653  return 1;
1654 }
1655
[2530]1656#ifdef ROAR_SUPPORT_LISTEN
1657 if ( init_listening() == -1 ) {
1658  ROAR_ERR("Can not init listening sockets!");
1659  return 1;
1660 }
1661#endif
1662
[2500]1663#ifndef ROAR_WITHOUT_DCOMP_MIDI
[1924]1664 if ( midi_init_config() == -1 ) {
1665  ROAR_ERR("Can not init MIDI config!");
1666  return 1;
1667 }
[2500]1668#endif
[60]1669
[2489]1670#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
[2451]1671 if ( ssynth_init_config() == -1 ) {
1672  ROAR_ERR("Can not init ssynth config!");
1673  return 1;
1674 }
[2489]1675#endif
[2451]1676
[2718]1677#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1678 if ( rdtcs_init_config() == -1 ) {
1679  ROAR_ERR("Can not init RDTCS config!");
1680  return 1;
1681 }
1682#endif
1683
[3354]1684 if ( plugins_preinit() == -1 ) {
1685  ROAR_ERR("Can not pre-init plugins!");
1686  return 1;
1687 }
1688
[1494]1689#ifdef ROAR_SUPPORT_LISTEN
[2767]1690#ifndef ROAR_TARGET_WIN32
[2530]1691 sock_addr = ROAR_DEFAULT_SOCK_GLOBAL;
[2767]1692#else
1693 sock_addr = ROAR_DEFAULT_HOST;
1694#endif
1695
[1753]1696#ifdef ROAR_HAVE_GETUID
[1486]1697 if ( getuid() != 0 && getenv("HOME") != NULL ) {
[3959]1698/*
[1486]1699  snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER);
[3959]1700*/
1701  roar_env_render_path_r(user_sock, sizeof(user_sock), "~/" ROAR_DEFAULT_SOCK_USER);
[2530]1702  sock_addr = user_sock;
[3959]1703  ROAR_DBG("main(*): setting sock_addr='%s'", sock_addr);
[60]1704 }
[1753]1705#endif
[60]1706
[279]1707 if ( getenv("ROAR_SERVER") != NULL )
[2530]1708  sock_addr = getenv("ROAR_SERVER");
[1494]1709#endif
[279]1710
[63]1711 if ( clients_init() == -1 ) {
1712  ROAR_ERR("Can not init clients!");
1713  return 1;
1714 }
1715
1716 if ( streams_init() == -1 ) {
1717  ROAR_ERR("Can not init streams!");
1718  return 1;
1719 }
1720
[64]1721 if ( (g_self_client = clients_new()) == -1 ) {
1722  ROAR_ERR("Can not create self client!");
1723  return 1;
1724 }
1725
[2485]1726#ifndef ROAR_WITHOUT_DCOMP_SOURCES
[0]1727 if ( sources_init() == -1 ) {
1728  ROAR_ERR("Can not init sources!");
1729  return 1;
1730 }
1731
[64]1732 if ( (sources_set_client(g_self_client)) == -1 ) {
1733  ROAR_ERR("Can not init set source client!");
1734  return 1;
1735 }
[2485]1736#endif
[64]1737
[1503]1738#ifdef ROAR_HAVE_MAIN_ARGS
[0]1739 for (i = 1; i < argc; i++) {
1740  k = argv[i];
1741
1742  if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) {
1743   usage();
1744   return 0;
1745
[2109]1746  } else if ( strcmp(k, "--start") == 0 ) {
1747   // this is a no op
[4722]1748   action = START;
[579]1749  } else if ( strcmp(k, "--restart") == 0 ) {
[4722]1750   action = RESTART;
[1494]1751#ifdef ROAR_SUPPORT_LISTEN
[2530]1752   if ( restart_server(sock_addr, 1) == -1 ) {
[4722]1753    ROAR_WARN("Can not terminate old server (not running at %s?), will retry later.", sock_addr);
1754    action = RESTART_RETRY;
[579]1755   }
[1494]1756#else
1757   ROAR_ERR("--restart not supported");
1758#endif
[2109]1759  } else if ( strcmp(k, "--shutdown") == 0 ) {
[4722]1760   action = SHUTDOWN;
[2109]1761  } else if ( strcmp(k, "--stop") == 0 ) {
[4722]1762   action = STOP;
[2109]1763
[579]1764
[775]1765  } else if ( strcmp(k, "--demon") == 0 || strcmp(k, "--daemon") == 0 ) {
[1486]1766#ifdef ROAR_HAVE_FORK
[775]1767   daemon = 1;
[1486]1768#else
1769   ROAR_ERR("--daemon not supported");
1770#endif
[2970]1771  } else if ( strcmp(k, "--verbose") == 0 ) {
1772   g_verbose++;
[71]1773  } else if ( strcmp(k, "--terminate") == 0 ) {
1774   g_terminate = 1;
[905]1775  } else if ( strcmp(k, "--sysclocksync") == 0 ) {
1776   sysclocksync = 1000;
[275]1777  } else if ( strcmp(k, "--realtime") == 0 ) {
[276]1778   realtime++;
[4245]1779  } else if ( strcmp(k, "--memlock") == 0 ) {
1780   _CKHAVEARGS(1);
1781   g_config->memlock_level = memlock_str2level(argv[++i]);
[444]1782  } else if ( strcmp(k, "--chroot") == 0 ) {
[4052]1783   _CKHAVEARGS(1);
[1486]1784#ifdef ROAR_HAVE_CHROOT
[444]1785   chrootdir = argv[++i];
[1486]1786#else
1787   ROAR_ERR("--chroot not supported");
1788   i++;
1789#endif
[444]1790  } else if ( strcmp(k, "--setgid") == 0 ) {
[1486]1791#ifdef ROAR_HAVE_SETGID
[444]1792   setids |= R_SETGID;
[1486]1793#else
1794   ROAR_ERR("--setgid not supported");
1795#endif
[444]1796  } else if ( strcmp(k, "--setuid") == 0 ) {
[1486]1797#ifdef ROAR_HAVE_SETUID
[444]1798   setids |= R_SETUID;
[1486]1799#else
1800   ROAR_ERR("--setuid not supported");
1801#endif
[2017]1802  } else if ( strcmp(k, "--location") == 0 ) {
[4052]1803   _CKHAVEARGS(1);
[2017]1804   g_config->location = argv[++i];
[4421]1805  } else if ( strcmp(k, "--description") == 0 ) {
1806   _CKHAVEARGS(1);
1807   g_config->description = argv[++i];
[2104]1808  } else if ( strcmp(k, "--pidfile") == 0 ) {
[4052]1809   _CKHAVEARGS(1);
[2104]1810#ifdef SUPPORT_PIDFILE
1811   pidfile = argv[++i];
1812#else
1813   ROAR_ERR("--pidfile not supported");
1814   i++;
1815#endif
[3688]1816  } else if ( strcmp(k, "--log-syslog") == 0 ) {
1817#ifdef ROAR_HAVE_SYSLOG
1818   roar_debug_set_stderr_mode(ROAR_DEBUG_MODE_SYSLOG);
1819#else
1820   ROAR_ERR("--log-syslog not supported");
1821#endif
1822
[68]1823
[3356]1824  } else if ( strcmp(k, "--plugin-load") == 0 ) {
[4052]1825   _CKHAVEARGS(1);
[3356]1826   if ( plugins_load(argv[++i]) == -1 ) {
1827    ROAR_ERR("Can not load plugin");
1828   }
1829
[4482]1830  } else if ( strcmp(k, "--guest-acclev") == 0 ) {
1831   _CKHAVEARGS(1);
1832   none_acclev = clients_str2acclev(argv[++i]);
1833  } else if ( strcmp(k, "--trust-acclev") == 0 ) {
1834   _CKHAVEARGS(1);
1835   trust_acclev = clients_str2acclev(argv[++i]);
1836  } else if ( strcmp(k, "--trust-root") == 0 ) {
1837   trust_root = 1;
1838  } else if ( strcmp(k, "--no-trust-root") == 0 ) {
1839   trust_root = 0;
1840
[280]1841  } else if ( strcmp(k, "--list-cf") == 0 ) {
1842   print_codecfilterlist();
1843   return 0;
1844
[0]1845  } else if ( strcmp(k, "-R") == 0 || strcmp(k, "--rate") == 0 ) {
[4052]1846   _CKHAVEARGS(1);
[0]1847   sa.rate = atoi(argv[++i]);
1848  } else if ( strcmp(k, "-B") == 0 || strcmp(k, "--bits") == 0 ) {
[4052]1849   _CKHAVEARGS(1);
[0]1850   sa.bits = atoi(argv[++i]);
1851  } else if ( strcmp(k, "-C") == 0 || strcmp(k, "--chans") == 0 ) {
[4052]1852   _CKHAVEARGS(1);
[0]1853   sa.channels = atoi(argv[++i]);
1854
[3962]1855  } else if ( strcmp(k, "--aiprofile") == 0 ) {
[4052]1856   _CKHAVEARGS(1);
[3962]1857   if ( roar_profile2info(&sa, argv[++i]) == -1 ) {
1858    ROAR_ERR("Unknown audio profile: %s", argv[i]);
1859    return 1;
1860   }
1861   sa.codec    = ROAR_CODEC_DEFAULT;
1862
[2339]1863  } else if ( strcmp(k, "--stream-flags") == 0 ) {
[4052]1864   _CKHAVEARGS(1);
[2339]1865   if ( update_stream_flags(argv[++i]) == -1 ) {
1866    ROAR_ERR("Can not set stream flags");
1867    return 1;
1868   }
1869
[0]1870  } else if ( strcmp(k, "-d") == 0 || strcmp(k, "--driver") == 0 ) {
[4052]1871   _CKHAVEARGS(1);
[0]1872   driver = argv[++i];
1873   if ( strcmp(driver, "list") == 0 ) {
[974]1874    ROAR_WARN("The option is obsolete, use --list-driver!");
[0]1875    print_driverlist();
[973]1876    return 0;
[0]1877   }
1878  } else if ( strcmp(k, "-D") == 0 || strcmp(k, "--device") == 0 ) {
[4052]1879   _CKHAVEARGS(1);
[0]1880   device = argv[++i];
1881  } else if ( strcmp(k, "-dO") == 0 ) {
[4052]1882   _CKHAVEARGS(1);
[0]1883   opts = argv[++i];
[973]1884  } else if ( strcmp(k, "--list-driver") == 0 ) {
1885   print_driverlist();
1886   return 0;
[0]1887
[932]1888  } else if ( strcmp(k, "-o") == 0 || strcmp(k, "--odriver") == 0 ) {
[4052]1889   _CKHAVEARGS(1);
[932]1890   o_drv  = argv[++i];
1891  } else if ( strcmp(k, "-O") == 0 || strcmp(k, "--odevice") == 0 ) {
[4052]1892   _CKHAVEARGS(1);
[932]1893   o_dev  = argv[++i];
1894  } else if ( strcmp(k, "-oO") == 0 ) {
[4052]1895   _CKHAVEARGS(1);
[932]1896   o_opts = argv[++i];
[961]1897  } else if ( strcmp(k, "-oP") == 0 ) {
1898   o_prim = 1;
[932]1899  } else if ( strcmp(k, "-oN") == 0 ) {
[4722]1900   if ( action == START || action == RESTART ) {
1901    if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 )
1902     o_count++;
[1145]1903
[4722]1904    o_drv  = o_dev = o_opts = NULL;
1905    o_prim = 0;
1906   }
[932]1907
[0]1908  } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) {
[4052]1909   _CKHAVEARGS(1);
[2485]1910#ifndef ROAR_WITHOUT_DCOMP_SOURCES
[550]1911   s_drv = argv[++i];
[2485]1912#else
1913   ROAR_ERR("main(*): No support for sources compiled in");
[4052]1914   i++;
[2485]1915#endif
[550]1916  } else if ( strcmp(k, "-S") == 0 ) {
[4052]1917   _CKHAVEARGS(1);
[2485]1918#ifndef ROAR_WITHOUT_DCOMP_SOURCES
[1110]1919   s_dev = argv[++i];
[2485]1920#else
1921   ROAR_ERR("main(*): No support for sources compiled in");
[4052]1922   i++;
[2485]1923#endif
[0]1924  } else if ( strcmp(k, "-sO") == 0 ) {
[4052]1925   _CKHAVEARGS(1);
[2485]1926#ifndef ROAR_WITHOUT_DCOMP_SOURCES
[0]1927   s_opt = argv[++i];
[2485]1928#else
1929   ROAR_ERR("main(*): No support for sources compiled in");
[4052]1930   i++;
[2485]1931#endif
[0]1932  } else if ( strcmp(k, "-sC") == 0 ) {
[4052]1933   _CKHAVEARGS(1);
[2485]1934#ifndef ROAR_WITHOUT_DCOMP_SOURCES
[0]1935   s_con = argv[++i];
[2485]1936#else
1937   ROAR_ERR("main(*): No support for sources compiled in");
[4052]1938   i++;
[2485]1939#endif
[0]1940  } else if ( strcmp(k, "-sP") == 0 ) {
[2485]1941#ifndef ROAR_WITHOUT_DCOMP_SOURCES
[0]1942   s_prim = 1;
[2485]1943#else
1944   ROAR_ERR("main(*): No support for sources compiled in");
1945#endif
[1110]1946  } else if ( strcmp(k, "-sN") == 0 ) {
[2485]1947#ifndef ROAR_WITHOUT_DCOMP_SOURCES
[1110]1948   if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
1949    ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
1950   }
1951   s_opt = s_dev = s_con = NULL;
1952   s_drv = "cf";
1953   s_prim = 0;
[2485]1954#else
1955   ROAR_ERR("main(*): No support for sources compiled in");
1956#endif
[2270]1957  } else if ( strcmp(k, "--list-sources") == 0 ) {
[2485]1958#ifndef ROAR_WITHOUT_DCOMP_SOURCES
[2270]1959   print_sourcelist();
1960   return 0;
[2485]1961#else
1962   ROAR_ERR("main(*): No support for sources compiled in");
[2504]1963   return 1;
[2485]1964#endif
[0]1965
[4358]1966  } else if ( strcmp(k, "-m") == 0 || strcmp(k, "--mixer") == 0 ) {
1967   _CKHAVEARGS(1);
1968#ifndef ROAR_WITHOUT_DCOMP_MIXER
1969   m_drv  = argv[++i];
1970#else
1971   ROAR_ERR("main(*): No support for mixer compiled in");
1972   return 1;
1973#endif
1974  } else if ( strcmp(k, "-M") == 0 ) {
1975   _CKHAVEARGS(1);
1976#ifndef ROAR_WITHOUT_DCOMP_MIXER
1977   m_dev  = argv[++i];
1978#else
1979   ROAR_ERR("main(*): No support for mixer compiled in");
1980   return 1;
1981#endif
1982  } else if ( strcmp(k, "-mO") == 0 ) {
1983   _CKHAVEARGS(1);
1984#ifndef ROAR_WITHOUT_DCOMP_MIXER
1985   m_opts = argv[++i];
1986#else
1987   ROAR_ERR("main(*): No support for mixer compiled in");
1988   return 1;
1989#endif
1990  } else if ( strcmp(k, "-mP") == 0 ) {
1991#ifndef ROAR_WITHOUT_DCOMP_MIXER
1992   m_prim = 1;
1993#else
1994   ROAR_ERR("main(*): No support for mixer compiled in");
1995   return 1;
1996#endif
1997  } else if ( strcmp(k, "-mN") == 0 ) {
1998#ifndef ROAR_WITHOUT_DCOMP_MIXER
1999   if ( add_hwmixer(m_drv, m_dev, m_opts, m_prim, m_count) != -1 )
2000    m_count++;
2001
2002   m_drv  = o_dev = o_opts = NULL;
2003   m_prim = 0;
2004#else
2005   ROAR_ERR("main(*): No support for mixer compiled in");
2006   return 1;
2007#endif
[4360]2008  } else if ( strcmp(k, "--list-mixers") == 0 ) {
2009#ifndef ROAR_WITHOUT_DCOMP_MIXER
2010   print_hwmixerlist();
2011   return 0;
2012#else
2013   ROAR_ERR("main(*): No support for mixer compiled in");
2014   return 1;
2015#endif
[4358]2016
[1923]2017  } else if ( strcmp(k, "--light-channels") == 0 ) {
[4052]2018   _CKHAVEARGS(1);
[2494]2019#ifndef ROAR_WITHOUT_DCOMP_LIGHT
[1923]2020   light_channels = atoi(argv[++i]);
[2494]2021#else
2022   ROAR_WARN("main(*): no light subsystem compiled in");
[4052]2023   i++;
[2494]2024#endif
[1923]2025
[2725]2026  } else if ( strcmp(k, "--rds-pi") == 0 ) {
[4052]2027   _CKHAVEARGS(1);
[2725]2028#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2029   g_rdtcs.rds.pi = atoi(argv[++i]);
2030#else
2031   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
[4052]2032   i++;
[2725]2033#endif
[2728]2034  } else if ( strcmp(k, "--rds-ps") == 0 ) {
[4052]2035   _CKHAVEARGS(1);
[2728]2036#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2037   if ( rdtcs_rds_set_ps(argv[++i]) == -1 ) {
[2729]2038    ROAR_ERR("Can not set RDS PS to '%s' (longer than 8 chars?)", argv[i]);
[2728]2039    return 1;
2040   }
2041#else
2042   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
[4052]2043   i++;
[2728]2044#endif
2045  } else if ( strcmp(k, "--rds-pty") == 0 ) {
[4052]2046   _CKHAVEARGS(1);
[2728]2047#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2048   if ( rdtcs_rds_set_pty(argv[++i]) == -1 ) {
[2729]2049    ROAR_ERR("Can not set RDS PTY to '%s'", argv[i]);
[2728]2050    return 1;
2051   }
2052#else
2053   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
[4052]2054   i++;
[2728]2055#endif
2056  } else if ( strcmp(k, "--rds-tp") == 0 ) {
2057#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2058   if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_TP, 0) == -1 ) {
2059    ROAR_ERR("Can not set RDS TP flag");
2060    return 1;
2061   }
2062#else
2063   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
2064#endif
2065  } else if ( strcmp(k, "--rds-ct") == 0 ) {
2066#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2067   if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_CT, 0) == -1 ) {
2068    ROAR_ERR("Can not set RDS CT flag");
2069    return 1;
2070   }
2071#else
2072   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
2073#endif
2074
[2725]2075
[1924]2076  } else if ( strcmp(k, "--midi-no-console") == 0 ) {
[2487]2077#ifndef ROAR_WITHOUT_DCOMP_CB
[1924]2078   midi_config.init_cb = 0;
[2487]2079#else
2080   // no warning here as this is the disable option
2081#endif
[2444]2082  } else if ( strcmp(k, "--midi-console-enable") == 0 ) {
[2487]2083#ifndef ROAR_WITHOUT_DCOMP_CB
[2444]2084   midi_config.init_cb = 1;
[2487]2085#else
2086   ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in");
2087#endif
[1924]2088  } else if ( strcmp(k, "--midi-console") == 0 ) {
[4052]2089   _CKHAVEARGS(1);
[2487]2090#ifndef ROAR_WITHOUT_DCOMP_CB
[1924]2091   midi_config.console_dev = argv[++i];
[2444]2092   midi_config.init_cb = 1;
[2487]2093#else
2094   ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in");
[4052]2095   i++;
[2487]2096#endif
[1924]2097
[2451]2098  } else if ( strcmp(k, "--ssynth-enable") == 0 ) {
[2489]2099#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
[2451]2100   ssynth_conf.enable = 1;
[2489]2101#else
2102   ROAR_ERR("main(*): No support for ssynth compiled in");
2103#endif
[2451]2104  } else if ( strcmp(k, "--ssynth-disable") == 0 ) {
[2489]2105#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
[2451]2106   ssynth_conf.enable = 0;
[2489]2107#else
2108   // we can safely ignore the disable
2109#endif
[2451]2110
[3374]2111  } else if ( strcmp(k, "--x11-display") == 0 || strcmp(k, "--display") == 0 ) {
[4052]2112   _CKHAVEARGS(1);
[3374]2113#ifdef ROAR_HAVE_LIBX11
2114   x11display = argv[++i];
2115#else
2116   ROAR_ERR("No X11 support compiled in!");
2117   return 1;
2118#endif
2119
2120
[0]2121  } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--port") == 0 ) {
[4052]2122   _CKHAVEARGS(1);
[4012]2123   // This is only useful in INET not UNIX mode.
[1494]2124#ifdef ROAR_SUPPORT_LISTEN
[2530]2125   if ( *sock_addr == '/' )
2126    sock_addr = ROAR_DEFAULT_HOST;
[447]2127
[446]2128   errno = 0;
2129   if ( (port = atoi(argv[++i])) < 1 ) {
[1486]2130#ifdef ROAR_HAVE_GETSERVBYNAME
[446]2131    if ( (serv = getservbyname(argv[i], "tcp")) == NULL ) {
2132     ROAR_ERR("Unknown service: %s: %s", argv[i], strerror(errno));
2133     return 1;
2134    }
2135    // NOTE: we need to use ROAR_NET2HOST16() here even if s_port is of type int!
2136    ROAR_DBG("main(*): serv = {s_name='%s', s_aliases={...}, s_port=%i, s_proto='%s'}",
2137            serv->s_name, ROAR_NET2HOST16(serv->s_port), serv->s_proto);
2138    port = ROAR_NET2HOST16(serv->s_port);
[1486]2139#else
2140    ROAR_ERR("invalite port number: %s", argv[i]);
2141    return 1;
2142#endif
[446]2143   }
[1494]2144#endif
[1115]2145  } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) {
[4052]2146   _CKHAVEARGS(1);
[1494]2147#ifdef ROAR_SUPPORT_LISTEN
[2530]2148   sock_addr = argv[++i];
[4052]2149#else
2150   i++;
[2530]2151#endif
2152
2153  } else if ( strcmp(k, "--proto") == 0 ) {
2154#ifdef ROAR_SUPPORT_LISTEN
[2549]2155   if ( (sock_proto = roar_str2proto(argv[++i])) == -1 ) {
[2530]2156    ROAR_ERR("Unknown protocol: %s", argv[i]);
2157    return 1;
2158   }
[1494]2159#endif
[3252]2160  } else if ( strcmp(k, "--proto-dir") == 0 ) {
[4052]2161   _CKHAVEARGS(1);
[3252]2162#ifdef ROAR_SUPPORT_LISTEN
2163   if ( (sock_dir = roar_str2dir(argv[++i])) == -1 ) {
2164    ROAR_ERR("Unknown stream direction: %s", argv[i]);
2165    return 1;
2166   }
[4052]2167#else
2168   i++;
[3252]2169#endif
2170  } else if ( strcmp(k, "--proto-rate") == 0 ) {
[4052]2171   _CKHAVEARGS(1);
[3252]2172#ifdef ROAR_SUPPORT_LISTEN
2173   sock_info.rate = atoi(argv[++i]);
[4052]2174#else
2175   i++;
[3252]2176#endif
2177  } else if ( strcmp(k, "--proto-bits") == 0 ) {
[4052]2178   _CKHAVEARGS(1);
[3252]2179#ifdef ROAR_SUPPORT_LISTEN
2180   sock_info.bits = atoi(argv[++i]);
[4052]2181#else
2182   i++;
[3252]2183#endif
2184  } else if ( strcmp(k, "--proto-chans") == 0 ) {
[4052]2185   _CKHAVEARGS(1);
[3252]2186#ifdef ROAR_SUPPORT_LISTEN
2187   sock_info.channels = atoi(argv[++i]);
[4052]2188#else
2189   i++;
[3252]2190#endif
2191  } else if ( strcmp(k, "--proto-codec") == 0 ) {
[4052]2192   _CKHAVEARGS(1);
[3252]2193#ifdef ROAR_SUPPORT_LISTEN
2194   if ( (sock_info.codec = roar_str2codec(argv[++i])) == -1 ) {
2195    ROAR_ERR("Unknown codec: %s", argv[i]);
2196    return 1;
2197   }
[4052]2198#else
2199   i++;
[3252]2200#endif
[3954]2201  } else if ( strcmp(k, "--proto-aiprofile") == 0 ) {
[4052]2202   _CKHAVEARGS(1);
[3954]2203#ifdef ROAR_SUPPORT_LISTEN
2204   if ( roar_profile2info(&sock_info, argv[++i]) == -1 ) {
2205    ROAR_ERR("Unknown audio profile: %s", argv[i]);
2206    return 1;
2207   }
[4052]2208#else
2209   i++;
[3954]2210#endif
[3956]2211  } else if ( strcmp(k, "--list-profiles") == 0 ) {
2212#ifdef ROAR_SUPPORT_LISTEN
2213   listen_listen_profiles();
2214   return 0;
2215#endif
2216  } else if ( strcmp(k, "--proto-profile") == 0 ) {
[4052]2217   _CKHAVEARGS(1);
[3956]2218#ifdef ROAR_SUPPORT_LISTEN
2219   if ( get_listen_profile(argv[++i], &port, &sock_addr, &sock_type, &sock_proto, &sock_dir, &sock_info) == -1 ) {
2220    ROAR_ERR("Unknown listen profile: %s", argv[i]);
2221    return 1;
2222   }
[4052]2223#else
2224   i++;
[3956]2225#endif
[3252]2226
2227
[3127]2228  } else if ( strcmp(k, "--list-proto") == 0 ) {
2229   list_proto();
2230   return 0;
[518]2231
[573]2232  } else if ( strcmp(k, "-t") == 0 || strcmp(k, "--tcp") == 0 ) {
[1494]2233#ifdef ROAR_SUPPORT_LISTEN
[518]2234   if ( sock_type != ROAR_SOCKET_TYPE_TCP && sock_type != ROAR_SOCKET_TYPE_TCP6 )
2235    sock_type = ROAR_SOCKET_TYPE_TCP;
2236
[2530]2237   if ( *sock_addr == '/' )
2238    sock_addr = ROAR_DEFAULT_HOST;
[1494]2239#endif
[518]2240
2241  } else if ( strcmp(k, "-4") == 0 ) {
[1494]2242#ifdef ROAR_SUPPORT_LISTEN
[517]2243   sock_type = ROAR_SOCKET_TYPE_TCP;
[2530]2244   if ( *sock_addr == '/' )
2245    sock_addr = ROAR_DEFAULT_HOST;
[1494]2246#endif
[518]2247  } else if ( strcmp(k, "-6") == 0 ) {
[1494]2248#ifdef ROAR_SUPPORT_LISTEN
[3837]2249#ifdef AF_INET6
[518]2250   sock_type = ROAR_SOCKET_TYPE_TCP6;
[2530]2251   if ( *sock_addr == '/' )
2252    sock_addr = ROAR_DEFAULT_HOST;
[519]2253#else
2254    ROAR_ERR("No IPv6 support compiled in!");
2255    return 1;
2256#endif
[1494]2257#endif
[518]2258
[573]2259  } else if ( strcmp(k, "-u") == 0 || strcmp(k, "--unix") == 0 ) {
[1494]2260#ifdef ROAR_SUPPORT_LISTEN
[62]2261   // ignore this case as it is the default behavor.
[517]2262   sock_type = ROAR_SOCKET_TYPE_UNIX;
[1494]2263#endif
[518]2264
[573]2265  } else if ( strcmp(k, "-n") == 0 || strcmp(k, "--decnet") == 0 ) {
[1494]2266#ifdef ROAR_SUPPORT_LISTEN
[508]2267#ifdef ROAR_HAVE_LIBDNET
2268    port   = ROAR_DEFAULT_NUM;
2269    strcpy(decnethost, ROAR_DEFAULT_LISTEN_OBJECT);
[2530]2270    sock_addr = decnethost;
[517]2271    sock_type = ROAR_SOCKET_TYPE_DECNET;
[508]2272#else
2273    ROAR_ERR("No DECnet support compiled in!");
2274    return 1;
2275#endif
[1494]2276#endif
[2530]2277  } else if ( strcmp(k, "--new-sock") == 0 ) {
2278#ifdef ROAR_SUPPORT_LISTEN
[4722]2279   if ( action == START || action == RESTART ) {
2280    if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) {
2281     ROAR_ERR("Can not open listen socket!");
2282     return 1;
2283    }
[2530]2284   }
2285#endif
[518]2286
[1993]2287  } else if ( strcmp(k, "--slp") == 0 ) {
2288#ifdef ROAR_HAVE_LIBSLP
2289   reg_slp = 1;
2290#else
[3373]2291   ROAR_ERR("No OpenSLP support compiled in!");
2292   return 1;
[1993]2293#endif
2294
[3373]2295  } else if ( strcmp(k, "--x11") == 0 ) {
2296#ifdef ROAR_HAVE_LIBX11
2297   reg_x11 = 1;
2298#else
2299   ROAR_ERR("No X11 support compiled in!");
2300   return 1;
2301#endif
2302
2303
[3039]2304  } else if ( strcmp(k, "--jumbo-mtu") == 0 ) {
[4052]2305   _CKHAVEARGS(1);
[3039]2306   g_config->jumbo_mtu = atoi(argv[++i]);
2307
[60]2308  } else if ( strcmp(k, "-G") == 0 ) {
[4052]2309   _CKHAVEARGS(1);
[444]2310   sock_grp  = argv[++i];
2311  } else if ( strcmp(k, "-U") == 0 ) {
[4052]2312   _CKHAVEARGS(1);
[444]2313   sock_user = argv[++i];
[0]2314
[68]2315  } else if ( strcmp(k, "--no-listen") == 0 ) {
[1494]2316#ifdef ROAR_SUPPORT_LISTEN
[2530]2317   sock_addr   = "";
[548]2318   g_terminate = 1;
[1155]2319   g_no_listen = 1;
[1494]2320#endif
[68]2321  } else if ( strcmp(k, "--client-fh") == 0 ) {
[4052]2322   _CKHAVEARGS(1);
[3737]2323   if ( clients_new_from_fh(atoi(argv[++i]), ROAR_PROTO_ROARAUDIO, ROAR_BYTEORDER_NETWORK, 1) == -1 ) {
[68]2324    ROAR_ERR("main(*): Can not set client's fh");
2325    return 1;
2326   }
[501]2327  } else if ( strcmp(k, "--close-fh") == 0 ) {
[4052]2328   _CKHAVEARGS(1);
[1486]2329#ifdef ROAR_HAVE_IO_POSIX
[501]2330   close(atoi(argv[++i]));
[1486]2331#else
2332   i++;
2333   ROAR_WARN("can not close file handle %s (closing not supported)", argv[i]);
2334#endif
[68]2335
[920]2336  } else if ( strcmp(k, "--standby") == 0 ) {
2337   g_standby = 1;
2338  } else if ( strcmp(k, "--auto-standby") == 0 ) {
2339   g_autostandby = 1;
[0]2340  } else {
2341   usage();
2342   return 1;
2343  }
2344
2345 }
[1503]2346#endif
[0]2347
[4722]2348#ifdef ROAR_HAVE_MAIN_ARGS
2349 switch (action) {
2350  case START:
2351    // NO-OP.
2352   break;
2353  case RESTART:
2354    // NO-OP, done before.
2355   break;
2356  case STOP:
2357#ifdef ROAR_SUPPORT_LISTEN
2358    if ( restart_server(sock_addr, 0) == -1 ) {
2359     ROAR_WARN("Can not stop old server (not running at %s?)", sock_addr);
2360     return 1;
2361    }
2362    return 0;
2363#else
2364    ROAR_ERR("--stop not supported");
2365    return 1;
2366#endif
2367   break;
2368  case SHUTDOWN:
2369#ifdef ROAR_SUPPORT_LISTEN
2370    if ( restart_server(sock_addr, 1) == -1 ) {
2371     ROAR_WARN("Can not terminate old server (not running at %s?)", sock_addr);
2372     return 1;
2373    }
2374    return 0;
2375#else
2376    ROAR_ERR("--shutdown not supported");
2377    return 1;
2378#endif
2379   break;
2380  case RESTART_RETRY:
2381#ifdef ROAR_SUPPORT_LISTEN
2382    if ( restart_server(sock_addr, 1) == -1 ) {
2383     ROAR_WARN("Can not terminate old server (again) (not running at %s?), tring to continue anyway", sock_addr);
2384     action = RESTART;
2385    }
2386#endif
2387   break;
2388 }
2389#endif
2390
[4418]2391#ifndef DEBUG
2392 // notify dbg if requested, if in DEBUG mode
2393 // do not able because it got enabled early.
2394 if ( g_verbose >= 4 )
2395  dbg_notify_cb_register();
2396#endif
2397
[4358]2398#ifndef ROAR_WITHOUT_DCOMP_MIXER
2399 if ( m_drv != NULL ) {
2400  if ( add_hwmixer(m_drv, m_dev, m_opts, m_prim, m_count) == -1 ) {
2401   ROAR_ERR("main(*): adding mixer '%s' via '%s' failed!", m_dev, m_drv);
2402  }
2403 }
2404#endif
2405
[2485]2406#ifndef ROAR_WITHOUT_DCOMP_SOURCES
[1110]2407 if ( s_dev != NULL ) {
2408  if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
2409   ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
2410  }
2411 }
[2485]2412#endif
[1110]2413
[4141]2414 add_default_output(o_drv, o_dev, o_opts, o_prim, o_count);
[932]2415
[4055]2416 ROAR_INFO("Server config: rate=%i, bits=%i, chans=%i", ROAR_DBG_INFO_NOTICE, sa.rate, sa.bits, sa.channels);
[0]2417
[2945]2418 if ( waveform_init() == -1 ) {
2419  ROAR_ERR("Can not initialize Waveform subsystem");
2420  return 1;
2421 }
2422
[2500]2423#ifndef ROAR_WITHOUT_DCOMP_MIDI
[1819]2424 if ( midi_init() == -1 ) {
[281]2425  ROAR_ERR("Can not initialize MIDI subsystem");
[1819]2426 }
[2500]2427#endif
[1819]2428
[2489]2429#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
[2451]2430 if ( ssynth_init() == -1 ) {
2431  ROAR_ERR("Can not initialize ssynth subsystem");
2432 }
[2489]2433#endif
[2451]2434
[2494]2435#ifndef ROAR_WITHOUT_DCOMP_LIGHT
[1819]2436 if ( light_init(light_channels) == -1 ) {
2437  ROAR_ERR("Can not initialize light control subsystem");
2438 }
[2494]2439#endif
[281]2440
[2718]2441#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2442 if ( rdtcs_init() == -1 ) {
2443  ROAR_ERR("Can not initialize RDTCS subsystem");
2444 }
2445#endif
2446
[3354]2447 if ( plugins_init() == -1 ) {
2448  ROAR_ERR("Can not initialize plugins");
2449 }
2450
[1494]2451#ifdef ROAR_SUPPORT_LISTEN
[3760]2452 if ( !g_no_listen ) {
2453  if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) {
2454   ROAR_ERR("Can not open listen socket!");
2455   return 1;
2456  }
[60]2457 }
[1494]2458#endif
[60]2459
[0]2460 if ( output_buffer_init(&sa) == -1 ) {
2461  ROAR_ERR("Can not init output buffer!");
2462  return 1;
2463 }
2464
[1145]2465 if ( driver == NULL ) {
2466  driver = "null";
2467 } else {
[4225]2468  ROAR_ERR("Usage of old driver interface. use -o not -d!");
2469  ROAR_WARN("-d will be removed within the next releases");
[1145]2470 }
2471
[0]2472 if ( driver_open(&drvinst, &drvid, driver, device, &sa) == -1 ) {
2473  ROAR_ERR("Can not open output driver!");
2474  return 1;
2475 }
2476
[44]2477 if ( samples_init() == -1 ) {
2478  ROAR_ERR("Can not init samples!");
2479  return 1;
2480 }
2481
2482
[1486]2483 // we should handle this on microcontrollers, too.
[1753]2484#if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_TARGET_WIN32)
[0]2485 signal(SIGINT,  on_sig_int);
[2732]2486 signal(SIGTERM, on_sig_term);
[285]2487 signal(SIGCHLD, on_sig_chld);
[2112]2488 signal(SIGUSR1, on_sig_usr1);
[0]2489 signal(SIGPIPE, SIG_IGN);  // ignore broken pipes
[1486]2490#endif
[0]2491
[4245]2492 if ( g_config->memlock_level == -1 ) {
2493  g_config->memlock_level = MEMLOCK_DEFAULT;
2494 }
2495
2496 if ( memlock_set_level(g_config->memlock_level) == -1 ) {
2497  ROAR_WARN("Can not set memory locking level to target level.");
2498 }
2499
[275]2500 if ( realtime ) {
[278]2501#ifdef DEBUG
[4246]2502  ROAR_WARN("compiled with -DDEBUG but realtime is enabled: for real realtime support compile without -DDEBUG");
[278]2503#endif
2504
[1486]2505#ifdef ROAR_HAVE_NICE
[4739]2506  // this stupid error check is because type of returned data of nice() changed
2507  // too often. On some systems it may return 0/-1, on some new nice value or
2508  // mixed forms of both.
[275]2509  errno = 0;
[4739]2510  (void)nice(-5*realtime); // -5 for each --realtime
[1486]2511  if ( errno ) {
2512   ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
2513  }
2514#else
2515  ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
2516#endif
[277]2517/*
[276]2518#ifdef __linux__
[277]2519  if ( ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0)) == -1 )
2520   ROAR_WARN("Can not set io priority: %s", strerror(errno));
[276]2521#endif
[277]2522*/
[275]2523 }
2524
[2756]2525#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
[444]2526 if ( setids & R_SETGID ) {
[2754]2527  if ( sock_grp == NULL ) {
2528   ROAR_ERR("Can not set GID if no groupname is supplied");
2529   return 1;
2530  }
[2584]2531  if ( (grp = getgrnam(sock_grp)) == NULL ) {
2532   ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno));
2533   return 1;
2534  }
[444]2535  if ( setgroups(0, (const gid_t *) NULL) == -1 ) {
2536   ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno));
2537  }
[523]2538  if ( !grp || setgid(grp->gr_gid) == -1 ) {
[444]2539   ROAR_ERR("Can not set GroupID: %s", strerror(errno));
2540  }
2541 }
[1486]2542#endif
[444]2543
[0]2544
[39]2545 clients_set_pid(g_self_client, getpid());
[1753]2546#ifdef ROAR_HAVE_GETUID
[440]2547 clients_set_uid(g_self_client, getuid());
[1753]2548#endif
2549#ifdef ROAR_HAVE_GETGID
[440]2550 clients_set_gid(g_self_client, getgid());
[1753]2551#endif
[39]2552 clients_get(g_self_client, &self);
[37]2553
[39]2554 if ( self == NULL ) {
2555  ROAR_ERR("Can not get self client!");
2556  return 1;
2557 }
2558
[775]2559 strcpy(self->name, "RoarAudio daemon internal");
[68]2560
[2815]2561 if ( roar_nnode_free(&(self->nnode)) == -1 )
2562  return 1;
2563
2564 // not fully correct but ok as workaorund
2565 // so tools assume that roard runs on the same machine as
2566 // they in case they use AF_UNIX:
2567 if ( roar_nnode_new(&(self->nnode), ROAR_SOCKET_TYPE_UNIX) == -1 )
2568  return 1;
2569
[1486]2570#ifdef ROAR_HAVE_FORK
[775]2571 if ( daemon ) {
[3613]2572#ifdef ROAR_HAVE_SYSLOG
2573  roar_debug_set_stderr_mode(ROAR_DEBUG_MODE_SYSLOG);
2574#else
[3609]2575  roar_debug_set_stderr_fh(-1);
[3613]2576#endif
[3609]2577
[68]2578  close(ROAR_STDIN );
2579  close(ROAR_STDOUT);
2580  close(ROAR_STDERR);
[1753]2581
[68]2582  if ( fork() )
[1486]2583   ROAR_U_EXIT(0);
[1753]2584
2585#ifdef ROAR_HAVE_SETSID
2586  setsid();
2587#endif
[1046]2588  clients_set_pid(g_self_client, getpid()); // reset pid as it changed
[68]2589 }
[1486]2590#endif
[68]2591
[2757]2592#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
2593 // early test for UID as we need this for the pidfile and the setuid()
2594 if ( sock_user != NULL ) {
2595  if ( (pwd = getpwnam(sock_user)) == NULL ) {
2596   ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno));
2597   return 1;
2598  }
2599 }
2600#endif
2601
[4423]2602 ROAR_INFO("Process ID: %i", ROAR_DBG_INFO_INFO, (int)getpid());
2603
[2104]2604#ifdef SUPPORT_PIDFILE
[2106]2605 if ( pidfile != NULL ) {
2606  if ( roar_vio_open_file(&pidfile_vio, pidfile, O_WRONLY|O_CREAT, 0644) == -1 ) {
2607   ROAR_ERR("Can not write pidfile: %s", pidfile);
2608  } else {
2609   roar_vio_printf(&pidfile_vio, "%i\n", getpid());
2610   roar_vio_close(&pidfile_vio);
2611  }
[2765]2612#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
[2759]2613  if ( pwd || grp ) {
2614   if ( chown(pidfile, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 ) {
2615    ROAR_WARN("Can not change ownership of pidfile: %s: %s", pidfile, strerror(errno));
2616   }
2617  }
2618  if ( chmod(pidfile, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1 ) {
2619   ROAR_WARN("Can not change permissions of pidfile: %s: %s", pidfile, strerror(errno));
2620  }
[2765]2621#endif
[2104]2622 }
2623#endif
2624
[1486]2625#ifdef ROAR_HAVE_CHROOT
[444]2626 if (chrootdir) {
2627  if ( chroot(chrootdir) == -1 ) {
2628   ROAR_ERR("Can not chroot to %s: %s", chrootdir, strerror(errno));
2629   return 2;
2630  }
2631  if ( chdir("/") == -1 ) {
2632   ROAR_ERR("Can not chdir to /: %s", strerror(errno));
2633   return 2;
2634  }
2635 }
[1486]2636#endif
[444]2637
[2756]2638#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
[444]2639 if ( setids & R_SETUID ) {
[2752]2640  if ( sock_user == NULL ) {
2641   ROAR_ERR("Can not set UID if no username is supplied");
2642   return 1;
2643  }
[444]2644  if ( !pwd || setuid(pwd->pw_uid) == -1 ) {
2645   ROAR_ERR("Can not set UserID: %s", strerror(errno));
2646   return 3;
2647  }
[1753]2648#ifdef ROAR_HAVE_GETUID
[444]2649  clients_set_uid(g_self_client, getuid());
[1753]2650#endif
[444]2651 }
[1486]2652#endif
[444]2653
[4481]2654 // setup auth:
[4690]2655#if defined(ROAR_HAVE_GETUID) && defined(ROAR_HAVE_GETGID)
[4481]2656 if ( auth_setup(none_acclev, trust_acclev, trust_root, getuid(), getgid()) == -1 ) {
[4690]2657#else
2658 if ( auth_setup(none_acclev, trust_acclev, trust_root, -1, -1) == -1 ) {
2659#endif
[4481]2660  ROAR_ERR("Can not set up auth. Bad.");
2661  alive = 0;
2662 }
2663
[1993]2664 // Register with OpenSLP:
[2028]2665#ifdef ROAR_HAVE_LIBSLP
[1993]2666 if ( reg_slp ) {
[2530]2667  register_slp(0, sock_addr);
[1993]2668 }
[2028]2669#endif
[1993]2670
[3373]2671#ifdef ROAR_HAVE_LIBX11
2672 if ( reg_x11 ) {
2673  register_x11(0, sock_addr);
2674 }
2675#endif
2676
[4103]2677 ROAR_INFO("Startup complet", ROAR_DBG_INFO_INFO);
2678
[0]2679 // start main loop...
[4055]2680 ROAR_INFO("Entering main loop", ROAR_DBG_INFO_INFO);
[905]2681 main_loop(drvid, drvinst, &sa, sysclocksync);
[4055]2682 ROAR_INFO("Left main loop", ROAR_DBG_INFO_INFO);
[0]2683
2684 // clean up.
2685 clean_quit_prep();
2686 driver_close(drvinst, drvid);
2687 output_buffer_free();
2688
[4323]2689 roar_notify_core_free(NULL);
2690
[4055]2691 ROAR_INFO("Exiting, no error", ROAR_DBG_INFO_INFO);
[0]2692 return 0;
2693}
2694
[574]2695void cleanup_listen_socket (int terminate) {
[2530]2696 int i;
2697
[4055]2698 ROAR_DBG("cleanup_listen_socket(terminate=%i) = (void)?", terminate);
2699
2700 ROAR_INFO("Cleaning up listen sockets", ROAR_DBG_INFO_INFO);
2701
[1993]2702 // Deregister from SLP:
[2028]2703#ifdef ROAR_HAVE_LIBSLP
[1993]2704 register_slp(1, NULL);
[2028]2705#endif
[580]2706
[3373]2707#ifdef ROAR_HAVE_LIBX11
2708 register_x11(1, NULL);
2709#endif
2710
[1494]2711#ifdef ROAR_SUPPORT_LISTEN
[2530]2712 for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
[3802]2713  if ( g_listen[i].used  ) {
2714   roar_vio_close(&(g_listen[i].sock));
[60]2715
[3802]2716   g_listen[i].used = 0;
[576]2717
[1486]2718#ifdef ROAR_HAVE_UNIX
[2530]2719   if ( server[i] != NULL )
2720    if ( *(server[i]) == '/' )
2721     unlink(server[i]);
[1486]2722#endif
[2530]2723  }
[580]2724 }
[60]2725
[1494]2726#endif
2727
[574]2728 if ( terminate )
2729  g_terminate = 1;
2730}
2731
2732void clean_quit_prep (void) {
2733 cleanup_listen_socket(0);
[60]2734
[3354]2735 plugins_free();
2736
[2485]2737#ifndef ROAR_WITHOUT_DCOMP_SOURCES
[0]2738 sources_free();
[2485]2739#endif
[0]2740 streams_free();
2741 clients_free();
[2489]2742#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
[2451]2743 ssynth_free();
[2489]2744#endif
[2487]2745#ifndef ROAR_WITHOUT_DCOMP_CB
[282]2746 midi_cb_stop(); // stop console beep
[2487]2747#endif
[2500]2748#ifndef ROAR_WITHOUT_DCOMP_MIDI
[281]2749 midi_free();
[2500]2750#endif
[2494]2751#ifndef ROAR_WITHOUT_DCOMP_LIGHT
[1819]2752 light_free();
[2494]2753#endif
[2718]2754#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2755 rdtcs_free();
2756#endif
[2104]2757
[2945]2758 waveform_free();
2759
[2104]2760#ifdef SUPPORT_PIDFILE
2761 if ( pidfile != NULL )
2762  unlink(pidfile);
2763#endif
[4469]2764
2765 auth_free();
[0]2766}
2767
2768void clean_quit (void) {
[4055]2769 ROAR_INFO("Shuting down", ROAR_DBG_INFO_INFO);
2770
[4101]2771 counters_print(ROAR_DEBUG_TYPE_INFO, 0);
2772
[0]2773 clean_quit_prep();
2774// driver_close(drvinst, drvid);
2775// output_buffer_free();
[4055]2776
[4323]2777 roar_notify_core_free(NULL);
2778
[4055]2779 ROAR_INFO("Exiting, no error", ROAR_DBG_INFO_INFO);
[0]2780 exit(0);
2781}
2782
2783//ll
Note: See TracBrowser for help on using the repository browser.