source: roaraudio/roard/roard.c @ 4083:a322327332a6

Last change on this file since 4083:a322327332a6 was 4058:fc24cc9422bc, checked in by phi, 14 years ago

use const, added descriptions

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