source: roaraudio/roard/roard.c @ 4788:482fc1a96c7a

Last change on this file since 4788:482fc1a96c7a was 4788:482fc1a96c7a, checked in by phi, 13 years ago

Added simple authfile support to roard (pr1)

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