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