source: roaraudio/roard/roard.c @ 2444:0f46be0063a6

Last change on this file since 2444:0f46be0063a6 was 2444:0f46be0063a6, checked in by phi, 15 years ago

added --midi-console-enable and reenable console in case a dev is given

File size: 34.2 KB
Line 
1//roard.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27#ifdef ROAR_SUPPORT_LISTEN
28char * server = ROAR_DEFAULT_SOCK_GLOBAL; // global server address
29#endif
30
31#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_FS_POSIX)
32#define SUPPORT_PIDFILE
33char * pidfile = NULL;
34#endif
35
36#ifdef ROAR_HAVE_MAIN_ARGS
37void usage (void) {
38 printf("Usage: roard [OPTIONS]...\n\n");
39
40 printf("Misc Options:\n\n");
41 printf(
42        " --daemon              - Bring the server into background after init\n"
43        " --terminate           - Terminate after last client quited\n"
44        " --start               - No op parameter (starting roard is default operation)\n"
45        " --restart             - Trys to stop an old instance and start a new with new settings\n"
46        " --stop                - Stops a running roard (provide --pidfile!)\n"
47        " --shutdown            - Terminates a running roard (provide --pidfile!)\n"
48        " --realtime            - Trys to get realtime priority,\n"
49        "                         give multible times for being more realtime\n"
50        " --chroot DIR          - chroots to the given dir\n"
51        " --setgid              - GroupID to the audio group as specified via -G\n"
52        " --setuid              - UserID to the audio user as specified via -U\n"
53        " --sysclocksync        - calculate exact sample rate using the system clock\n"
54        " --location  LOC       - Set lion readable location of server\n"
55#ifdef SUPPORT_PIDFILE
56        " --pidfile PIDFILE     - Write a pidfile at PIDFILE\n"
57#endif
58       );
59
60 printf("\nAudio Options:\n\n");
61 printf(
62        " -R  --rate   RATE     - Set server rate\n"
63        " -B  --bits   BITS     - Set server bits\n"
64        " -C  --chans  CHANNELS - Set server channels\n"
65       );
66
67 printf("\nStream Options:\n\n");
68 printf(
69        " --stream-flags D=F    - Set default flags for stream directions\n"
70        "                         D is the stream direction and F is a comma seperated\n"
71        "                         list of flags in form +flag or -flag to set or unset\n"
72        "                         a flag as default or remove it from the default\n"
73       );
74
75 printf("\nDriver Options: (obsolete, do not use, Use Ouput Options)\n\n");
76 printf(" -d  --driver DRV      - Set the driver (default: %s)\n", ROAR_DRIVER_DEFAULT);
77 printf(" -D  --device DEV      - Set the device\n");
78 printf(" -dO OPTS              - Set output options\n");
79 printf(" --list-driver         - List all drivers\n");
80
81 printf("\nOutput Options:\n\n");
82 printf(" -o  --odriver DRV     - Set the driver, use '--list-driver' to get a list\n");
83 printf(" -O  --odevice DEV     - Set the device\n");
84 printf(" -oO OPTS              - Set output options\n");
85 printf(" -oN                   - Adds another output\n");
86 printf(" -oP                   - Mark output as primary\n");
87
88 printf("\nSource Options:\n\n");
89 printf(" -s  --source DRV      - Use DRV as input driver\n"
90        " -S           DEV      - Use DEV as input device\n"
91        " -sO          OPTS     - Use OPTS as input options\n"
92        " -sN                   - Adds another source\n"
93        " -sP                   - Make souce as primary\n"
94       );
95 printf(" --list-sources        - List all sources\n");
96
97 printf("\nCodec Filter Options:\n\n");
98 printf(" --list-cf             - List all codec filter\n"
99       );
100
101 printf("\nMIDI Options:\n\n");
102 printf(" --midi-no-console     - Disable console based MIDI synth\n"
103        " --midi-console-enable - Enables the console based MIDI synth\n"
104        " --midi-console DEV    - Set device for MIDI console\n"
105       );
106
107 printf("\nLight Control Options:\n\n");
108 printf(" --light-channels NUM  - Sets the number of channels for Light control (default: %i)\n",
109                                  LIGHT_CHANNELS_DEFAULT
110       );
111
112 printf("\nServer Options:\n\n");
113 printf(" -t  --tcp             - Use TCP listen socket\n"
114        " -u  --unix            - Use UNIX Domain listen socket (default)\n"
115#ifdef ROAR_HAVE_LIBDNET
116        " -n  --decnet          - use DECnet listen socket\n"
117#endif
118        " -4                    - Use IPv4 connections (implies -t)\n"
119#ifdef PF_INET6
120        " -6                    - Use IPv6 connections (implies -t)\n"
121#endif
122#ifdef IPV6_ADDRFORM
123        " -64                   - Try to downgrade sockets from IPv6 into IPv4,\n"
124        "                         this is normaly not usefull.\n"
125#endif
126        " -p  --port            - TCP Port to bind to\n"
127        " -b  --bind            - IP/Hostname to bind to\n"
128        "     --sock            - Filename for UNIX Domain Socket\n"
129#ifdef ROAR_HAVE_LIBSLP
130        "     --slp             - Enable OpenSLP support\n"
131#endif
132        " -G  GROUP             - Sets the group for the UNIX Domain Socket, (default: %s)\n"
133        "                         You need the permittions to change the GID\n"
134        " -U  USER              - Sets the user for the UNIX Domain Socket, (default: do not set)\n"
135        "                         You need the permittions to change the UID (normaly only root has)\n"
136        " --no-listen           - Do not listen for new clients\n"
137        "                         (only usefull for relaing, impleys --terminate)\n"
138        " --client-fh           - Comunicate with a client over this handle\n"
139        "                         (only usefull for relaing)\n"
140        " --close-fh            - Closes the given fh\n"
141        " --standby             - Start in standby state\n"
142        " --auto-standby        - Automatical goes into standby if there are no streams\n",
143        ROAR_DEFAULT_SOCKGRP
144       );
145// printf("\n Options:\n\n");
146 printf("\n");
147}
148#endif
149
150int restart_server (char * server, int terminate) {
151 struct roar_connection con;
152#ifdef ROAR_HAVE_KILL
153 char buf[80];
154 ssize_t l;
155 struct roar_vio_calls fh;
156 pid_t pid;
157 int ok;
158
159 if ( pidfile != NULL ) {
160  if ( roar_vio_open_file(&fh, pidfile, O_RDONLY, 0644) == -1 ) {
161   ROAR_WARN("restart_server(*): Can not read pidfile: %s", pidfile);
162  } else {
163   l = roar_vio_read(&fh, buf, 80);
164   roar_vio_close(&fh);
165   if ( l > 0 ) {
166    buf[l-1] = 0;
167    buf[79]  = 0;
168    pid = atoi(buf);
169    if ( terminate ) {
170     ok = kill(pid, SIGUSR1);
171    } else {
172     ok = kill(pid, SIGINT);
173    }
174    if ( ok == 0 ) {
175     return 0;
176    } else {
177     ROAR_WARN("restart_server(*): Can not kill roard by pidfile");
178    }
179   } else {
180    ROAR_WARN("restart_server(*): Can not find a PID in the pidfile");
181   }
182  }
183 }
184#endif
185
186 if ( roar_connect(&con, server) == -1 ) {
187  return -1;
188 }
189
190 if ( roar_terminate(&con, terminate) == -1 ) {
191  return -1;
192 }
193
194 return roar_disconnect(&con);
195}
196
197#define R_SETUID 1
198#define R_SETGID 2
199
200int init_config (void) {
201 int i;
202
203 memset(g_config, 0, sizeof(struct roard_config));
204
205 for (i = 0; i < ROAR_DIR_DIRIDS; i++) {
206  g_config->streams[i].mixer_channels = 1;
207  g_config->streams[i].mixer.rpg_mul  = 1;
208  g_config->streams[i].mixer.rpg_div  = 1;
209  g_config->streams[i].mixer.scale    = 65535;
210  g_config->streams[i].mixer.mixer[0] = g_config->streams[i].mixer.scale;
211 }
212
213 g_config->streams[ROAR_DIR_PLAY    ].flags = ROAR_FLAG_META;
214 g_config->streams[ROAR_DIR_OUTPUT  ].flags = ROAR_FLAG_PASSMIXER;
215 g_config->streams[ROAR_DIR_FILTER  ].flags = ROAR_FLAG_SYNC;
216 g_config->streams[ROAR_DIR_MIDI_OUT].flags = ROAR_FLAG_SYNC;
217 g_config->streams[ROAR_DIR_BIDIR   ].flags = ROAR_FLAG_ANTIECHO;
218
219 g_config->location = "***default***";
220
221 return 0;
222}
223
224int update_stream_flags (char * str) {
225 int    dir;
226 char * flags;
227 char * k;
228 int    op;
229 int    flag;
230
231 if ( (flags = strstr(str, "=")) == NULL )
232  return -1;
233
234 *flags = 0;
235  flags++;
236
237 if ( (dir = roar_str2dir(str)) == -1 )
238  return -1;
239
240 while (flags != NULL) {
241  k = flags;
242  flags = strstr(flags, ",");
243
244  if ( flags != NULL )
245   *(flags++) = 0;
246
247  switch (*k) {
248   case '+': k++; op = ROAR_SET_FLAG;   break;
249   case '-': k++; op = ROAR_RESET_FLAG; break;
250   default:
251     op = ROAR_SET_FLAG;
252  }
253
254  flag = 0;
255
256  if ( !strcmp(k, "sync") ) {
257   flag = ROAR_FLAG_SYNC;
258  } else if ( !strcmp(k, "meta") ) {
259   flag = ROAR_FLAG_META;
260  } else if ( !strcmp(k, "cleanmeta") ) {
261   flag = ROAR_FLAG_CLEANMETA;
262  } else if ( !strcmp(k, "pause") ) {
263   flag = ROAR_FLAG_PAUSE;
264  } else if ( !strcmp(k, "mute") ) {
265   flag = ROAR_FLAG_MUTE;
266  } else if ( !strcmp(k, "antiecho") ) {
267   flag = ROAR_FLAG_ANTIECHO;
268  } else if ( !strcmp(k, "passmixer") ) {
269   flag = ROAR_FLAG_PASSMIXER;
270  } else {
271   return -1;
272  }
273
274  g_config->streams[dir].flags |= flag;
275
276  if ( op == ROAR_RESET_FLAG )
277   g_config->streams[dir].flags -= flag;
278 }
279
280 return 0;
281}
282
283int add_output (char * drv, char * dev, char * opts, int prim, int count) {
284 int stream;
285 struct roar_stream * s;
286 struct roar_stream_server * ss;
287 char * k, * v;
288#ifdef ROAR_DRIVER_CODEC
289 char * to_free = NULL;
290#endif
291 int codec;
292 int sync = 0, f_mmap = 0;
293 int32_t blocks = -1, blocksize = -1;
294 int dir = ROAR_DIR_OUTPUT;
295 int error = 0;
296 // DMX:
297 int32_t channel  = -1;
298 int32_t universe = -1;
299 uint16_t tu16;
300 float q = -32e6;
301
302 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
303
304 if ( drv == NULL && count == 0 ) {
305  drv  = ROAR_DRIVER_DEFAULT;
306  prim = 1;
307  sync = 1;
308
309#ifdef ROAR_DRIVER_CODEC
310  if ( opts == NULL ) {
311   opts = to_free = strdup("codec=" ROAR_DRIVER_CODEC);
312  }
313#endif
314 }
315
316 if ( opts == NULL && count == 0 ) {
317  sync = 1;
318  prim = 1; // if ( prim == 0 ) prim = 1; -> prim allways = 1
319 }
320
321 if ( (stream = streams_new()) == -1 ) {
322  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
323  if ( prim ) alive = 0;
324  return -1;
325 }
326
327 streams_get(stream, &ss);
328 s = ROAR_STREAM(ss);
329
330 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
331
332 s->pos_rel_id = -1;
333// s->info.codec = codec;
334
335 codec = s->info.codec;
336
337 k = strtok(opts, ",");
338 while (k != NULL) {
339//  ROAR_WARN("add_output(*): opts: %s", k);
340
341  if ( (v = strstr(k, "=")) != NULL ) {
342   *v++ = 0;
343  }
344
345  ROAR_DBG("add_output(*): opts: k='%s', v='%s'", k, v);
346  if ( strcmp(k, "rate") == 0 ) {
347   s->info.rate = atoi(v);
348  } else if ( strcmp(k, "channels") == 0 ) {
349   s->info.channels = atoi(v);
350  } else if ( strcmp(k, "bits") == 0 ) {
351   s->info.bits = atoi(v);
352  } else if ( strcmp(k, "codec") == 0 ) {
353   if ( (codec = roar_str2codec(v)) == -1 ) {
354    ROAR_ERR("add_output(*): unknown codec '%s'", v);
355    error++;
356   }
357  } else if ( strcmp(k, "q") == 0 ) {
358   q = atof(v);
359  } else if ( strcmp(k, "blocks") == 0 ) {
360   blocks = atoi(v);
361  } else if ( strcmp(k, "blocksize") == 0 ) {
362   blocksize = atoi(v);
363  } else if ( strcmp(k, "mmap") == 0 ) {
364   f_mmap = 1;
365  } else if ( strcmp(k, "subsystem") == 0 ) {
366   if ( !strcasecmp(v, "wave") || !strcasecmp(v, "waveform") ) {
367    dir = ROAR_DIR_OUTPUT;
368   } else if ( !strcasecmp(v, "midi") ) {
369    dir = ROAR_DIR_MIDI_OUT;
370   } else if ( !strcasecmp(v, "light") ) {
371    dir = ROAR_DIR_LIGHT_OUT;
372   } else if ( !strcasecmp(v, "raw") ) {
373    dir = ROAR_DIR_RAW_OUT;
374   } else {
375    ROAR_ERR("add_output(*): unknown subsystem '%s'", k);
376    error++;
377   }
378  // DMX:
379  } else if ( strcmp(k, "channel") == 0 ) {
380   channel  = atoi(v);
381   if ( channel < 0 || channel > 65535 ) {
382    ROAR_ERR("add_output(*): Invalide channel (not within 0..65535): %i", channel);
383    channel = -1;
384    error++;
385   }
386  } else if ( strcmp(k, "universe") == 0 ) {
387   universe = atoi(v);
388   if ( universe < 0 || universe > 255 ) {
389    ROAR_ERR("add_output(*): Invalide universe (not within 0..255): %i", universe);
390    universe = -1;
391    error++;
392   }
393
394  } else if ( strcmp(k, "name") == 0 ) {
395   if ( streams_set_name(stream, v) == -1 ) {
396    ROAR_ERR("add_output(*): Can not set Stream name");
397    error++;
398   }
399
400  } else if ( strcmp(k, "meta") == 0 ) {
401   streams_set_flag(stream, ROAR_FLAG_META);
402  } else if ( strcmp(k, "sync") == 0 ) {
403   sync = 1;
404  } else if ( strcmp(k, "primary") == 0 ) {
405   prim = 1;
406
407  } else if ( strcmp(k, "cleanmeta") == 0 ) {
408   streams_set_flag(stream, ROAR_FLAG_CLEANMETA);
409  } else if ( strcmp(k, "autoconf") == 0 ) {
410   streams_set_flag(stream, ROAR_FLAG_AUTOCONF);
411  } else if ( strcmp(k, "recsource") == 0 ) {
412   streams_set_flag(stream, ROAR_FLAG_RECSOURCE);
413  } else if ( strcmp(k, "passmixer") == 0 ) {
414   streams_set_flag(stream, ROAR_FLAG_PASSMIXER);
415  } else {
416   ROAR_ERR("add_output(*): unknown option '%s'", k);
417   error++;
418  }
419
420  if ( error ) {
421   streams_delete(stream);
422   if ( prim ) alive = 0;
423#ifdef ROAR_DRIVER_CODEC
424   if ( to_free != NULL )
425    free(to_free);
426#endif
427   return -1;
428  }
429
430  k = strtok(NULL, ",");
431 }
432
433 if ( streams_set_dir(stream, dir, 1) == -1 ) {
434  streams_delete(stream);
435  return -1;
436 }
437
438#ifdef ROAR_DRIVER_CODEC
439 if ( to_free != NULL )
440  free(to_free);
441#endif
442
443 if ( codec == ROAR_CODEC_ALAW || codec == ROAR_CODEC_MULAW )
444  s->info.bits = 8; // needed to open OSS driver, will be overriden by codecfilter
445
446 s->info.codec = codec;
447 ROAR_STREAM_SERVER(s)->codec_orgi = codec;
448
449 if ( driver_openvio(&(ss->vio), &(ss->driver_id), drv, dev, &(s->info), -1, ss) == -1 ) {
450  ss->driver_id = -1; // don't close a driver not opened...
451  memset(&(ss->vio), 0, sizeof(struct roar_vio_calls));
452  streams_delete(stream);
453  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
454  if ( prim ) alive = 0;
455  return -1;
456 }
457
458 roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAMID, &stream); // ignore errors here
459 roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAM,   s); // ignore errors here
460
461 if ( blocks != -1 )
462  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLOCKS, &blocks);
463
464 if ( blocksize != -1 )
465  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLKSIZE, &blocksize);
466
467 // TODO: we shoudld *really* check for errors here...
468 if ( channel != -1 ) {
469  tu16 = channel;
470  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXSCHAN, &tu16);
471 }
472 if ( universe != -1 ) {
473  tu16 = universe;
474  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXUNIV, &tu16);
475 }
476
477 ROAR_DBG("add_output(*): ss->driver_id=%i", ss->driver_id);
478
479 streams_set_fh(stream, -1); // update some internal structures
480
481 if ( q > -1e6 ) {
482  ROAR_DBG("add_output(*): setting q=%f", q);
483  streams_ctl(stream, ROAR_CODECFILTER_CTL_SET_Q|ROAR_STREAM_CTL_TYPE_FLOAT, &q);
484 }
485
486 client_stream_add(g_source_client, stream);
487
488 if ( prim ) {
489  streams_mark_primary(stream);
490  s->pos_rel_id = stream;
491 }
492
493 if ( sync ) {
494  streams_set_flag(stream, ROAR_FLAG_SYNC);
495 } else {
496  streams_reset_flag(stream, ROAR_FLAG_SYNC);
497 }
498
499 if ( f_mmap )
500  streams_set_flag(stream, ROAR_FLAG_MMAP);
501
502 return 0;
503}
504
505
506// SLP:
507void register_slp_callback(SLPHandle hslp, SLPError errcode, void * cookie) {
508 /* return the error code in the cookie */
509 *(SLPError*)cookie = errcode;
510}
511
512int register_slp (int unreg, char * sockname) {
513#ifdef ROAR_HAVE_LIBSLP
514 static int regged = 0;
515 static char * sn = NULL;
516 SLPError err;
517 SLPError callbackerr;
518 SLPHandle hslp;
519 char addr[1024];
520 char attr[1024] = "";
521 char * location;
522
523 if ( sockname != NULL )
524  sn = sockname;
525
526 snprintf(addr, sizeof(addr), ROAR_SLP_URL_TYPE "://%s", sn);
527
528 err = SLPOpen("en", SLP_FALSE, &hslp);
529
530 if (err != SLP_OK) {
531  ROAR_ERR("Error opening slp handle: Error #%i", err);
532  return -1;
533 }
534
535 if (!unreg) {
536
537  if ( SLPEscape(g_config->location, &location, SLP_FALSE) != SLP_OK ) {
538   ROAR_ERR("Error using SLPEscape() on server location, really bad!");
539   SLPClose(hslp);
540   return -1;
541  }
542
543  snprintf(attr, sizeof(attr), "(wave-rate=%i),(wave-channels=%i),(wave-bits=%i),"
544                               "(light-channels=%i),(location=%s)",
545           g_sa->rate, g_sa->channels, g_sa->bits,
546           g_light_state.channels,
547           location
548          );
549
550  /* Register a service with SLP */
551  err = SLPReg(hslp,
552               addr,
553               SLP_LIFETIME_MAXIMUM,
554               0,
555               attr,
556               SLP_TRUE,
557               register_slp_callback,
558               &callbackerr);
559  regged = 1;
560 } else if ( unreg && regged ) {
561  err = SLPDereg(hslp, addr, register_slp_callback, &callbackerr);
562  regged = 0;
563 } else {
564  SLPClose(hslp);
565  return -1;
566 }
567
568 /* err may contain an error code that occurred as the slp library    */
569 /* _prepared_ to make the call.                                     */
570 if ( err != SLP_OK ) {
571  ROAR_ERR("Error (de)registering service with slp: Error #%i", err);
572  return -1;
573 }
574
575 /* callbackerr may contain an error code (that was assigned through */
576 /* the callback cookie) that occurred as slp packets were sent on    */
577 /* the wire */
578 if (callbackerr != SLP_OK) {
579  ROAR_ERR("Error (de)registering service with slp: Error #%i", callbackerr);
580  return -1;
581 }
582
583 SLPClose(hslp);
584 return 0;
585#else
586 return -1;
587#endif
588}
589
590
591// MAIN:
592
593#ifdef ROAR_HAVE_MAIN_ARGS
594int main (int argc, char * argv[]) {
595#else
596int main (void) {
597#endif
598#ifdef ROAR_HAVE_MAIN_ARGS
599 int i;
600 char * k;
601#endif
602#ifdef ROAR_SUPPORT_LISTEN
603 char user_sock[80]  = {0};
604#endif
605 struct roar_audio_info sa, max_sa;
606 struct roard_config config;
607#ifdef ROAR_HAVE_FORK
608 int    daemon       = 0;
609#endif
610 int    realtime     = 0;
611 int    sysclocksync = 0;
612 char * driver    = NULL;
613 char * device    = NULL;
614#ifdef ROAR_HAVE_MAIN_ARGS
615 char * opts      = NULL;
616#endif
617// char * server = ROAR_DEFAULT_SOCK_GLOBAL;
618#ifdef ROAR_SUPPORT_LISTEN
619 int      port    = ROAR_DEFAULT_PORT;
620#endif
621 int               drvid;
622 char * s_drv     = "cf";
623 char * s_dev     = NULL;
624 char * s_con     = NULL;
625 char * s_opt     = NULL;
626 int    s_prim    = 0;
627 char * o_drv     = getenv("ROAR_DRIVER");
628 char * o_dev     = getenv("ROAR_DEVICE");
629 char * o_opts    = NULL;
630 int    o_prim    = 0;
631 int    o_count   = 0;
632 int    light_channels = LIGHT_CHANNELS_DEFAULT;
633 char * sock_grp  = ROAR_DEFAULT_SOCKGRP;
634 char * sock_user = NULL;
635#ifdef ROAR_SUPPORT_LISTEN
636 int    sock_type = ROAR_SOCKET_TYPE_UNKNOWN;
637#endif
638#ifdef ROAR_HAVE_LIBSLP
639 int    reg_slp   = 0;
640#endif
641#ifdef ROAR_HAVE_CHROOT
642 char * chrootdir = NULL;
643#endif
644#if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID)
645 int    setids    = 0;
646#endif
647#ifdef ROAR_HAVE_UNIX
648 char * env_roar_proxy_backup;
649#endif
650#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
651 struct group   * grp  = NULL;
652#endif
653#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
654 struct passwd  * pwd  = NULL;
655#endif
656#ifdef ROAR_HAVE_GETSERVBYNAME
657 struct servent * serv = NULL;
658#endif
659 DRIVER_USERDATA_T drvinst;
660 struct roar_client * self = NULL;
661#ifdef ROAR_HAVE_LIBDNET
662 char decnethost[80];
663#endif
664#ifdef SUPPORT_PIDFILE
665 struct roar_vio_calls pidfile_vio;
666#endif
667
668 g_standby       =  0;
669 g_autostandby   =  0;
670 alive           =  1;
671#ifdef ROAR_SUPPORT_LISTEN
672 g_no_listen     =  0;
673 g_listen_socket = -1;
674#else
675 g_terminate     =  1;
676#endif
677
678 sa.bits     = ROAR_BITS_DEFAULT;
679 sa.channels = ROAR_CHANNELS_DEFAULT;
680 sa.rate     = ROAR_RATE_DEFAULT;
681 sa.codec    = ROAR_CODEC_DEFAULT;
682
683 g_sa        = &sa;
684 g_max_sa    = &max_sa;
685
686 memcpy(g_max_sa, g_sa, sizeof(max_sa));
687
688 g_config = &config;
689
690 if ( init_config() == -1 ) {
691  ROAR_ERR("Can not init default config!");
692  return 1;
693 }
694
695 if ( midi_init_config() == -1 ) {
696  ROAR_ERR("Can not init MIDI config!");
697  return 1;
698 }
699
700#ifdef ROAR_SUPPORT_LISTEN
701#ifdef ROAR_HAVE_GETUID
702 if ( getuid() != 0 && getenv("HOME") != NULL ) {
703  snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER);
704  server = user_sock;
705 }
706#endif
707
708 if ( getenv("ROAR_SERVER") != NULL )
709  server = getenv("ROAR_SERVER");
710#endif
711
712 if ( clients_init() == -1 ) {
713  ROAR_ERR("Can not init clients!");
714  return 1;
715 }
716
717 if ( streams_init() == -1 ) {
718  ROAR_ERR("Can not init streams!");
719  return 1;
720 }
721
722 if ( (g_self_client = clients_new()) == -1 ) {
723  ROAR_ERR("Can not create self client!");
724  return 1;
725 }
726
727 if ( sources_init() == -1 ) {
728  ROAR_ERR("Can not init sources!");
729  return 1;
730 }
731
732 if ( (sources_set_client(g_self_client)) == -1 ) {
733  ROAR_ERR("Can not init set source client!");
734  return 1;
735 }
736
737#ifdef ROAR_HAVE_MAIN_ARGS
738 for (i = 1; i < argc; i++) {
739  k = argv[i];
740
741  if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) {
742   usage();
743   return 0;
744
745  } else if ( strcmp(k, "--start") == 0 ) {
746   // this is a no op
747  } else if ( strcmp(k, "--restart") == 0 ) {
748#ifdef ROAR_SUPPORT_LISTEN
749   if ( restart_server(server, 1) == -1 ) {
750    ROAR_WARN("Can not terminate old server (not running at %s?), tring to continue anyway", server);
751   }
752#else
753   ROAR_ERR("--restart not supported");
754#endif
755  } else if ( strcmp(k, "--shutdown") == 0 ) {
756#ifdef ROAR_SUPPORT_LISTEN
757   if ( restart_server(server, 1) == -1 ) {
758    ROAR_WARN("Can not terminate old server (not running at %s?)", server);
759    return 1;
760   }
761   return 0;
762#else
763   ROAR_ERR("--shutdown not supported");
764   return 1;
765#endif
766  } else if ( strcmp(k, "--stop") == 0 ) {
767#ifdef ROAR_SUPPORT_LISTEN
768   if ( restart_server(server, 0) == -1 ) {
769    ROAR_WARN("Can not stop old server (not running at %s?)", server);
770    return 1;
771   }
772   return 0;
773#else
774   ROAR_ERR("--stop not supported");
775   return 1;
776#endif
777
778
779  } else if ( strcmp(k, "--demon") == 0 || strcmp(k, "--daemon") == 0 ) {
780#ifdef ROAR_HAVE_FORK
781   daemon = 1;
782#else
783   ROAR_ERR("--daemon not supported");
784#endif
785  } else if ( strcmp(k, "--terminate") == 0 ) {
786   g_terminate = 1;
787  } else if ( strcmp(k, "--sysclocksync") == 0 ) {
788   sysclocksync = 1000;
789  } else if ( strcmp(k, "--realtime") == 0 ) {
790   realtime++;
791  } else if ( strcmp(k, "--chroot") == 0 ) {
792#ifdef ROAR_HAVE_CHROOT
793   chrootdir = argv[++i];
794#else
795   ROAR_ERR("--chroot not supported");
796   i++;
797#endif
798  } else if ( strcmp(k, "--setgid") == 0 ) {
799#ifdef ROAR_HAVE_SETGID
800   setids |= R_SETGID;
801#else
802   ROAR_ERR("--setgid not supported");
803#endif
804  } else if ( strcmp(k, "--setuid") == 0 ) {
805#ifdef ROAR_HAVE_SETUID
806   setids |= R_SETUID;
807#else
808   ROAR_ERR("--setuid not supported");
809#endif
810  } else if ( strcmp(k, "--location") == 0 ) {
811   g_config->location = argv[++i];
812  } else if ( strcmp(k, "--pidfile") == 0 ) {
813#ifdef SUPPORT_PIDFILE
814   pidfile = argv[++i];
815#else
816   ROAR_ERR("--pidfile not supported");
817   i++;
818#endif
819
820  } else if ( strcmp(k, "--list-cf") == 0 ) {
821   print_codecfilterlist();
822   return 0;
823
824  } else if ( strcmp(k, "-R") == 0 || strcmp(k, "--rate") == 0 ) {
825   sa.rate = atoi(argv[++i]);
826  } else if ( strcmp(k, "-B") == 0 || strcmp(k, "--bits") == 0 ) {
827   sa.bits = atoi(argv[++i]);
828  } else if ( strcmp(k, "-C") == 0 || strcmp(k, "--chans") == 0 ) {
829   sa.channels = atoi(argv[++i]);
830
831  } else if ( strcmp(k, "--stream-flags") == 0 ) {
832   if ( update_stream_flags(argv[++i]) == -1 ) {
833    ROAR_ERR("Can not set stream flags");
834    return 1;
835   }
836
837  } else if ( strcmp(k, "-d") == 0 || strcmp(k, "--driver") == 0 ) {
838   driver = argv[++i];
839   if ( strcmp(driver, "list") == 0 ) {
840    ROAR_WARN("The option is obsolete, use --list-driver!");
841    print_driverlist();
842    return 0;
843   }
844  } else if ( strcmp(k, "-D") == 0 || strcmp(k, "--device") == 0 ) {
845   device = argv[++i];
846  } else if ( strcmp(k, "-dO") == 0 ) {
847   opts = argv[++i];
848  } else if ( strcmp(k, "--list-driver") == 0 ) {
849   print_driverlist();
850   return 0;
851
852  } else if ( strcmp(k, "-o") == 0 || strcmp(k, "--odriver") == 0 ) {
853   o_drv  = argv[++i];
854  } else if ( strcmp(k, "-O") == 0 || strcmp(k, "--odevice") == 0 ) {
855   o_dev  = argv[++i];
856  } else if ( strcmp(k, "-oO") == 0 ) {
857   o_opts = argv[++i];
858  } else if ( strcmp(k, "-oP") == 0 ) {
859   o_prim = 1;
860  } else if ( strcmp(k, "-oN") == 0 ) {
861   if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 )
862    o_count++;
863
864   o_drv  = o_dev = o_opts = NULL;
865   o_prim = 0;
866
867  } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) {
868   s_drv = argv[++i];
869  } else if ( strcmp(k, "-S") == 0 ) {
870   s_dev = argv[++i];
871  } else if ( strcmp(k, "-sO") == 0 ) {
872   s_opt = argv[++i];
873  } else if ( strcmp(k, "-sC") == 0 ) {
874   s_con = argv[++i];
875  } else if ( strcmp(k, "-sP") == 0 ) {
876   s_prim = 1;
877  } else if ( strcmp(k, "-sN") == 0 ) {
878   if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
879    ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
880   }
881   s_opt = s_dev = s_con = NULL;
882   s_drv = "cf";
883   s_prim = 0;
884  } else if ( strcmp(k, "--list-sources") == 0 ) {
885   print_sourcelist();
886   return 0;
887
888  } else if ( strcmp(k, "--light-channels") == 0 ) {
889   light_channels = atoi(argv[++i]);
890
891  } else if ( strcmp(k, "--midi-no-console") == 0 ) {
892   midi_config.init_cb = 0;
893  } else if ( strcmp(k, "--midi-console-enable") == 0 ) {
894   midi_config.init_cb = 1;
895  } else if ( strcmp(k, "--midi-console") == 0 ) {
896   midi_config.console_dev = argv[++i];
897   midi_config.init_cb = 1;
898
899  } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--port") == 0 ) {
900   // This is only usefull in INET not UNIX mode.
901#ifdef ROAR_SUPPORT_LISTEN
902   if ( *server == '/' )
903    server = ROAR_DEFAULT_HOST;
904
905   errno = 0;
906   if ( (port = atoi(argv[++i])) < 1 ) {
907#ifdef ROAR_HAVE_GETSERVBYNAME
908    if ( (serv = getservbyname(argv[i], "tcp")) == NULL ) {
909     ROAR_ERR("Unknown service: %s: %s", argv[i], strerror(errno));
910     return 1;
911    }
912    // NOTE: we need to use ROAR_NET2HOST16() here even if s_port is of type int!
913    ROAR_DBG("main(*): serv = {s_name='%s', s_aliases={...}, s_port=%i, s_proto='%s'}",
914            serv->s_name, ROAR_NET2HOST16(serv->s_port), serv->s_proto);
915    port = ROAR_NET2HOST16(serv->s_port);
916#else
917    ROAR_ERR("invalite port number: %s", argv[i]);
918    return 1;
919#endif
920   }
921#endif
922  } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) {
923#ifdef ROAR_SUPPORT_LISTEN
924   server = argv[++i];
925#endif
926
927  } else if ( strcmp(k, "-t") == 0 || strcmp(k, "--tcp") == 0 ) {
928#ifdef ROAR_SUPPORT_LISTEN
929   if ( sock_type != ROAR_SOCKET_TYPE_TCP && sock_type != ROAR_SOCKET_TYPE_TCP6 )
930    sock_type = ROAR_SOCKET_TYPE_TCP;
931
932   if ( *server == '/' )
933    server = ROAR_DEFAULT_HOST;
934#endif
935
936  } else if ( strcmp(k, "-4") == 0 ) {
937#ifdef ROAR_SUPPORT_LISTEN
938   sock_type = ROAR_SOCKET_TYPE_TCP;
939   if ( *server == '/' )
940    server = ROAR_DEFAULT_HOST;
941#endif
942  } else if ( strcmp(k, "-6") == 0 ) {
943#ifdef ROAR_SUPPORT_LISTEN
944#ifdef PF_INET6
945   sock_type = ROAR_SOCKET_TYPE_TCP6;
946   if ( *server == '/' )
947    server = ROAR_DEFAULT_HOST;
948#else
949    ROAR_ERR("No IPv6 support compiled in!");
950    return 1;
951#endif
952#endif
953
954  } else if ( strcmp(k, "-u") == 0 || strcmp(k, "--unix") == 0 ) {
955#ifdef ROAR_SUPPORT_LISTEN
956   // ignore this case as it is the default behavor.
957   sock_type = ROAR_SOCKET_TYPE_UNIX;
958#endif
959
960  } else if ( strcmp(k, "-n") == 0 || strcmp(k, "--decnet") == 0 ) {
961#ifdef ROAR_SUPPORT_LISTEN
962#ifdef ROAR_HAVE_LIBDNET
963    port   = ROAR_DEFAULT_NUM;
964    strcpy(decnethost, ROAR_DEFAULT_LISTEN_OBJECT);
965    server = decnethost;
966    sock_type = ROAR_SOCKET_TYPE_DECNET;
967#else
968    ROAR_ERR("No DECnet support compiled in!");
969    return 1;
970#endif
971#endif
972
973  } else if ( strcmp(k, "--slp") == 0 ) {
974#ifdef ROAR_HAVE_LIBSLP
975   reg_slp = 1;
976#else
977    ROAR_ERR("No OpenSLP support compiled in!");
978    return 1;
979#endif
980
981  } else if ( strcmp(k, "-G") == 0 ) {
982   sock_grp  = argv[++i];
983  } else if ( strcmp(k, "-U") == 0 ) {
984   sock_user = argv[++i];
985
986  } else if ( strcmp(k, "--no-listen") == 0 ) {
987#ifdef ROAR_SUPPORT_LISTEN
988   server      = "";
989   g_terminate = 1;
990   g_no_listen = 1;
991#endif
992  } else if ( strcmp(k, "--client-fh") == 0 ) {
993   if ( clients_set_fh(clients_new(), atoi(argv[++i])) == -1 ) {
994    ROAR_ERR("main(*): Can not set client's fh");
995    return 1;
996   }
997  } else if ( strcmp(k, "--close-fh") == 0 ) {
998#ifdef ROAR_HAVE_IO_POSIX
999   close(atoi(argv[++i]));
1000#else
1001   i++;
1002   ROAR_WARN("can not close file handle %s (closing not supported)", argv[i]);
1003#endif
1004
1005  } else if ( strcmp(k, "--standby") == 0 ) {
1006   g_standby = 1;
1007  } else if ( strcmp(k, "--auto-standby") == 0 ) {
1008   g_autostandby = 1;
1009  } else {
1010   usage();
1011   return 1;
1012  }
1013
1014 }
1015#endif
1016
1017 if ( s_dev != NULL ) {
1018  if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
1019   ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
1020  }
1021 }
1022
1023 add_output(o_drv, o_dev, o_opts, o_prim, o_count);
1024
1025 ROAR_DBG("Server config: rate=%i, bits=%i, chans=%i", sa.rate, sa.bits, sa.channels);
1026
1027 if ( midi_init() == -1 ) {
1028  ROAR_ERR("Can not initialize MIDI subsystem");
1029 }
1030
1031 if ( light_init(light_channels) == -1 ) {
1032  ROAR_ERR("Can not initialize light control subsystem");
1033 }
1034
1035#ifdef ROAR_SUPPORT_LISTEN
1036 if ( *server != 0 ) {
1037  if ( (g_listen_socket = roar_socket_listen(sock_type, server, port)) == -1 ) {
1038#ifdef ROAR_HAVE_UNIX
1039   if ( *server == '/' ) {
1040    if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) {
1041     env_roar_proxy_backup = strdup(env_roar_proxy_backup);
1042     unsetenv("ROAR_PROXY");
1043    }
1044    if ( (i = roar_socket_connect(server, port)) != -1 ) {
1045     close(i);
1046     ROAR_ERR("Can not open listen socket!");
1047     return 1;
1048    } else {
1049     unlink(server);
1050     if ( (g_listen_socket = roar_socket_listen(sock_type, server, port)) == -1 ) {
1051      ROAR_ERR("Can not open listen socket!");
1052      return 1;
1053     }
1054    }
1055    if ( env_roar_proxy_backup != NULL ) {
1056     setenv("ROAR_PROXY", env_roar_proxy_backup, 0);
1057     free(env_roar_proxy_backup);
1058    }
1059#else
1060   if (0) { // noop
1061#endif
1062   } else {
1063    ROAR_ERR("Can not open listen socket!");
1064    return 1;
1065   }
1066  }
1067
1068#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
1069  if ( (grp = getgrnam(sock_grp)) == NULL ) {
1070   ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno));
1071  }
1072#endif
1073#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
1074  if ( sock_user || (setids & R_SETUID) ) {
1075   if ( (pwd = getpwnam(sock_user)) == NULL ) {
1076    ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno));
1077   }
1078  }
1079#endif
1080
1081#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_UNIX)
1082  if ( *server == '/' ) {
1083   if ( grp ) {
1084    if ( pwd ) {
1085     if ( chown(server, pwd->pw_uid, grp->gr_gid) == -1 )
1086      return 1;
1087    } else {
1088     if ( chown(server, -1, grp->gr_gid) == -1 )
1089      return 1;
1090    }
1091#ifdef ROAR_HAVE_GETUID
1092    if ( getuid() == 0 )
1093     if ( chmod(server, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1 )
1094      return 1;
1095#endif
1096   }
1097  }
1098#endif
1099 }
1100#endif
1101
1102 if ( output_buffer_init(&sa) == -1 ) {
1103  ROAR_ERR("Can not init output buffer!");
1104  return 1;
1105 }
1106
1107 if ( driver == NULL ) {
1108  driver = "null";
1109 } else {
1110  ROAR_WARN("Usage of old driver interface. use -o not -d!");
1111 }
1112
1113 if ( driver_open(&drvinst, &drvid, driver, device, &sa) == -1 ) {
1114  ROAR_ERR("Can not open output driver!");
1115  return 1;
1116 }
1117
1118 if ( samples_init() == -1 ) {
1119  ROAR_ERR("Can not init samples!");
1120  return 1;
1121 }
1122
1123
1124 // we should handle this on microcontrollers, too.
1125#if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_TARGET_WIN32)
1126 signal(SIGINT,  on_sig_int);
1127 signal(SIGCHLD, on_sig_chld);
1128 signal(SIGUSR1, on_sig_usr1);
1129 signal(SIGPIPE, SIG_IGN);  // ignore broken pipes
1130#endif
1131
1132 if ( realtime ) {
1133#ifdef DEBUG
1134  ROAR_WARN("compiled with -DDEBUG but realtime is enabled: for real realtime support compiel without -DDEBUG");
1135#endif
1136
1137#ifdef ROAR_HAVE_NICE
1138  errno = 0;
1139  nice(-5*realtime); // -5 for each --realtime
1140  if ( errno ) {
1141   ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
1142  }
1143#else
1144  ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
1145#endif
1146/*
1147#ifdef __linux__
1148  if ( ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0)) == -1 )
1149   ROAR_WARN("Can not set io priority: %s", strerror(errno));
1150#endif
1151*/
1152 }
1153
1154#ifdef ROAR_HAVE_SETGID
1155 if ( setids & R_SETGID ) {
1156  if ( setgroups(0, (const gid_t *) NULL) == -1 ) {
1157   ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno));
1158  }
1159  if ( !grp || setgid(grp->gr_gid) == -1 ) {
1160   ROAR_ERR("Can not set GroupID: %s", strerror(errno));
1161  }
1162 }
1163#endif
1164
1165
1166 clients_set_pid(g_self_client, getpid());
1167#ifdef ROAR_HAVE_GETUID
1168 clients_set_uid(g_self_client, getuid());
1169#endif
1170#ifdef ROAR_HAVE_GETGID
1171 clients_set_gid(g_self_client, getgid());
1172#endif
1173 clients_get(g_self_client, &self);
1174
1175 if ( self == NULL ) {
1176  ROAR_ERR("Can not get self client!");
1177  return 1;
1178 }
1179
1180 strcpy(self->name, "RoarAudio daemon internal");
1181
1182#ifdef ROAR_HAVE_FORK
1183 if ( daemon ) {
1184  close(ROAR_STDIN );
1185  close(ROAR_STDOUT);
1186  close(ROAR_STDERR);
1187
1188  if ( fork() )
1189   ROAR_U_EXIT(0);
1190
1191#ifdef ROAR_HAVE_SETSID
1192  setsid();
1193#endif
1194  clients_set_pid(g_self_client, getpid()); // reset pid as it changed
1195 }
1196#endif
1197
1198#ifdef SUPPORT_PIDFILE
1199 if ( pidfile != NULL ) {
1200  if ( roar_vio_open_file(&pidfile_vio, pidfile, O_WRONLY|O_CREAT, 0644) == -1 ) {
1201   ROAR_ERR("Can not write pidfile: %s", pidfile);
1202  } else {
1203   roar_vio_printf(&pidfile_vio, "%i\n", getpid());
1204   roar_vio_close(&pidfile_vio);
1205  }
1206 }
1207#endif
1208
1209#ifdef ROAR_HAVE_CHROOT
1210 if (chrootdir) {
1211  if ( chroot(chrootdir) == -1 ) {
1212   ROAR_ERR("Can not chroot to %s: %s", chrootdir, strerror(errno));
1213   return 2;
1214  }
1215  if ( chdir("/") == -1 ) {
1216   ROAR_ERR("Can not chdir to /: %s", strerror(errno));
1217   return 2;
1218  }
1219 }
1220#endif
1221
1222#ifdef ROAR_HAVE_SETUID
1223 if ( setids & R_SETUID ) {
1224  if ( !pwd || setuid(pwd->pw_uid) == -1 ) {
1225   ROAR_ERR("Can not set UserID: %s", strerror(errno));
1226   return 3;
1227  }
1228#ifdef ROAR_HAVE_GETUID
1229  clients_set_uid(g_self_client, getuid());
1230#endif
1231 }
1232#endif
1233
1234 // Register with OpenSLP:
1235#ifdef ROAR_HAVE_LIBSLP
1236 if ( reg_slp ) {
1237  register_slp(0, server);
1238 }
1239#endif
1240
1241 // start main loop...
1242 main_loop(drvid, drvinst, &sa, sysclocksync);
1243
1244 // clean up.
1245 clean_quit_prep();
1246 driver_close(drvinst, drvid);
1247 output_buffer_free();
1248
1249 return 0;
1250}
1251
1252void cleanup_listen_socket (int terminate) {
1253 // Deregister from SLP:
1254#ifdef ROAR_HAVE_LIBSLP
1255 register_slp(1, NULL);
1256#endif
1257
1258#ifdef ROAR_SUPPORT_LISTEN
1259 if ( g_listen_socket != -1 ) {
1260#ifdef ROAR_HAVE_IO_POSIX
1261  close(g_listen_socket);
1262#endif // #else is useless because we are in void context.
1263
1264  g_listen_socket = -1;
1265
1266#ifdef ROAR_HAVE_UNIX
1267  if ( *server == '/' )
1268   unlink(server);
1269#endif
1270 }
1271
1272#endif
1273
1274 if ( terminate )
1275  g_terminate = 1;
1276}
1277
1278void clean_quit_prep (void) {
1279 cleanup_listen_socket(0);
1280
1281 sources_free();
1282 streams_free();
1283 clients_free();
1284 midi_cb_stop(); // stop console beep
1285 midi_free();
1286 light_free();
1287
1288#ifdef SUPPORT_PIDFILE
1289 if ( pidfile != NULL )
1290  unlink(pidfile);
1291#endif
1292}
1293
1294void clean_quit (void) {
1295 clean_quit_prep();
1296// driver_close(drvinst, drvid);
1297// output_buffer_free();
1298 exit(0);
1299}
1300
1301//ll
Note: See TracBrowser for help on using the repository browser.