source: roaraudio/roard/roard.c @ 4101:42b7ee5d2f76

Last change on this file since 4101:42b7ee5d2f76 was 4101:42b7ee5d2f76, checked in by phi, 14 years ago

some work to support counters

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