source: roaraudio/roard/roard.c @ 5257:27194d561c16

Last change on this file since 5257:27194d561c16 was 5257:27194d561c16, checked in by phi, 13 years ago

fixed most warnings in roard

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