[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 |
---|
[2530] | 28 | char * server[ROAR_MAX_LISTEN_SOCKETS]; |
---|
[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 | |
---|
[2530] | 36 | #if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID) |
---|
| 37 | int setids = 0; |
---|
| 38 | #endif |
---|
| 39 | |
---|
[1503] | 40 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 41 | void usage (void) { |
---|
| 42 | printf("Usage: roard [OPTIONS]...\n\n"); |
---|
| 43 | |
---|
[68] | 44 | printf("Misc Options:\n\n"); |
---|
| 45 | printf( |
---|
[775] | 46 | " --daemon - Bring the server into background after init\n" |
---|
[71] | 47 | " --terminate - Terminate after last client quited\n" |
---|
[2109] | 48 | " --start - No op parameter (starting roard is default operation)\n" |
---|
[274] | 49 | " --restart - Trys to stop an old instance and start a new with new settings\n" |
---|
[2109] | 50 | " --stop - Stops a running roard (provide --pidfile!)\n" |
---|
| 51 | " --shutdown - Terminates a running roard (provide --pidfile!)\n" |
---|
[276] | 52 | " --realtime - Trys to get realtime priority,\n" |
---|
| 53 | " give multible times for being more realtime\n" |
---|
[444] | 54 | " --chroot DIR - chroots to the given dir\n" |
---|
| 55 | " --setgid - GroupID to the audio group as specified via -G\n" |
---|
| 56 | " --setuid - UserID to the audio user as specified via -U\n" |
---|
[905] | 57 | " --sysclocksync - calculate exact sample rate using the system clock\n" |
---|
[2017] | 58 | " --location LOC - Set lion readable location of server\n" |
---|
[2104] | 59 | #ifdef SUPPORT_PIDFILE |
---|
| 60 | " --pidfile PIDFILE - Write a pidfile at PIDFILE\n" |
---|
| 61 | #endif |
---|
[68] | 62 | ); |
---|
| 63 | |
---|
| 64 | printf("\nAudio Options:\n\n"); |
---|
[0] | 65 | printf( |
---|
| 66 | " -R --rate RATE - Set server rate\n" |
---|
| 67 | " -B --bits BITS - Set server bits\n" |
---|
| 68 | " -C --chans CHANNELS - Set server channels\n" |
---|
| 69 | ); |
---|
| 70 | |
---|
[2339] | 71 | printf("\nStream Options:\n\n"); |
---|
| 72 | printf( |
---|
| 73 | " --stream-flags D=F - Set default flags for stream directions\n" |
---|
| 74 | " D is the stream direction and F is a comma seperated\n" |
---|
| 75 | " list of flags in form +flag or -flag to set or unset\n" |
---|
| 76 | " a flag as default or remove it from the default\n" |
---|
| 77 | ); |
---|
| 78 | |
---|
[1923] | 79 | printf("\nDriver Options: (obsolete, do not use, Use Ouput Options)\n\n"); |
---|
[974] | 80 | printf(" -d --driver DRV - Set the driver (default: %s)\n", ROAR_DRIVER_DEFAULT); |
---|
[0] | 81 | printf(" -D --device DEV - Set the device\n"); |
---|
| 82 | printf(" -dO OPTS - Set output options\n"); |
---|
[973] | 83 | printf(" --list-driver - List all drivers\n"); |
---|
[0] | 84 | |
---|
[932] | 85 | printf("\nOutput Options:\n\n"); |
---|
[974] | 86 | printf(" -o --odriver DRV - Set the driver, use '--list-driver' to get a list\n"); |
---|
[932] | 87 | printf(" -O --odevice DEV - Set the device\n"); |
---|
| 88 | printf(" -oO OPTS - Set output options\n"); |
---|
| 89 | printf(" -oN - Adds another output\n"); |
---|
[961] | 90 | printf(" -oP - Mark output as primary\n"); |
---|
[932] | 91 | |
---|
[2485] | 92 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[0] | 93 | printf("\nSource Options:\n\n"); |
---|
| 94 | printf(" -s --source DRV - Use DRV as input driver\n" |
---|
| 95 | " -S DEV - Use DEV as input device\n" |
---|
| 96 | " -sO OPTS - Use OPTS as input options\n" |
---|
[1512] | 97 | " -sN - Adds another source\n" |
---|
[0] | 98 | " -sP - Make souce as primary\n" |
---|
| 99 | ); |
---|
[2270] | 100 | printf(" --list-sources - List all sources\n"); |
---|
[2485] | 101 | #endif |
---|
[0] | 102 | |
---|
[280] | 103 | printf("\nCodec Filter Options:\n\n"); |
---|
| 104 | printf(" --list-cf - List all codec filter\n" |
---|
| 105 | ); |
---|
[0] | 106 | |
---|
[2500] | 107 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[1923] | 108 | printf("\nMIDI Options:\n\n"); |
---|
[1924] | 109 | printf(" --midi-no-console - Disable console based MIDI synth\n" |
---|
[2444] | 110 | " --midi-console-enable - Enables the console based MIDI synth\n" |
---|
[1924] | 111 | " --midi-console DEV - Set device for MIDI console\n" |
---|
[2489] | 112 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
[2451] | 113 | " --ssynth-enable - Enable simple software synth\n" |
---|
| 114 | " --ssynth-disable - Disable simple software synth\n" |
---|
[2489] | 115 | #endif |
---|
[1924] | 116 | ); |
---|
[2500] | 117 | #endif |
---|
[1923] | 118 | |
---|
[2494] | 119 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1923] | 120 | printf("\nLight Control Options:\n\n"); |
---|
| 121 | printf(" --light-channels NUM - Sets the number of channels for Light control (default: %i)\n", |
---|
| 122 | LIGHT_CHANNELS_DEFAULT |
---|
| 123 | ); |
---|
[2494] | 124 | #endif |
---|
[1923] | 125 | |
---|
[2725] | 126 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 127 | printf("\nRadio Date and Transmitter Control System Options:\n\n"); |
---|
| 128 | printf(" --rds-pi PI - Sets the RDS Programme Identification (PI)\n" |
---|
| 129 | " --rds-ps PS - Sets the RDS Programme Service Name (PS)\n" |
---|
| 130 | " --rds-pty PTY - Sets the RDS Programme Type (PTY)\n" |
---|
| 131 | " --rds-tp - Sets the RDS Traffic Programme (TP) flag\n" |
---|
| 132 | " --rds-ct - Enables sending of RDS Clock Time (CT)\n" |
---|
| 133 | ); |
---|
| 134 | #endif |
---|
| 135 | |
---|
[0] | 136 | printf("\nServer Options:\n\n"); |
---|
| 137 | printf(" -t --tcp - Use TCP listen socket\n" |
---|
| 138 | " -u --unix - Use UNIX Domain listen socket (default)\n" |
---|
[508] | 139 | #ifdef ROAR_HAVE_LIBDNET |
---|
| 140 | " -n --decnet - use DECnet listen socket\n" |
---|
| 141 | #endif |
---|
[518] | 142 | " -4 - Use IPv4 connections (implies -t)\n" |
---|
| 143 | #ifdef PF_INET6 |
---|
| 144 | " -6 - Use IPv6 connections (implies -t)\n" |
---|
| 145 | #endif |
---|
| 146 | #ifdef IPV6_ADDRFORM |
---|
| 147 | " -64 - Try to downgrade sockets from IPv6 into IPv4,\n" |
---|
| 148 | " this is normaly not usefull.\n" |
---|
| 149 | #endif |
---|
[0] | 150 | " -p --port - TCP Port to bind to\n" |
---|
| 151 | " -b --bind - IP/Hostname to bind to\n" |
---|
[1115] | 152 | " --sock - Filename for UNIX Domain Socket\n" |
---|
[2530] | 153 | " --proto PROTO - Use PROTO as protocol on Socket\n" |
---|
| 154 | " --new-sock - Parameters for new socket follows\n" |
---|
[1993] | 155 | #ifdef ROAR_HAVE_LIBSLP |
---|
| 156 | " --slp - Enable OpenSLP support\n" |
---|
| 157 | #endif |
---|
[450] | 158 | " -G GROUP - Sets the group for the UNIX Domain Socket, (default: %s)\n" |
---|
[2737] | 159 | " You need the permissions to change the GID\n" |
---|
[444] | 160 | " -U USER - Sets the user for the UNIX Domain Socket, (default: do not set)\n" |
---|
[2737] | 161 | " You need the permissions to change the UID (normaly only root has)\n" |
---|
[548] | 162 | " --no-listen - Do not listen for new clients\n" |
---|
| 163 | " (only usefull for relaing, impleys --terminate)\n" |
---|
[274] | 164 | " --client-fh - Comunicate with a client over this handle\n" |
---|
[501] | 165 | " (only usefull for relaing)\n" |
---|
[920] | 166 | " --close-fh - Closes the given fh\n" |
---|
| 167 | " --standby - Start in standby state\n" |
---|
| 168 | " --auto-standby - Automatical goes into standby if there are no streams\n", |
---|
[2755] | 169 | #ifdef ROAR_DEFAULT_SOCKGRP |
---|
[450] | 170 | ROAR_DEFAULT_SOCKGRP |
---|
[2755] | 171 | #else |
---|
| 172 | "(none)" |
---|
| 173 | #endif |
---|
[0] | 174 | ); |
---|
| 175 | // printf("\n Options:\n\n"); |
---|
| 176 | printf("\n"); |
---|
| 177 | } |
---|
[1503] | 178 | #endif |
---|
[0] | 179 | |
---|
[2109] | 180 | int restart_server (char * server, int terminate) { |
---|
[579] | 181 | struct roar_connection con; |
---|
[2111] | 182 | #ifdef ROAR_HAVE_KILL |
---|
| 183 | char buf[80]; |
---|
| 184 | ssize_t l; |
---|
| 185 | struct roar_vio_calls fh; |
---|
| 186 | pid_t pid; |
---|
| 187 | int ok; |
---|
| 188 | |
---|
| 189 | if ( pidfile != NULL ) { |
---|
| 190 | if ( roar_vio_open_file(&fh, pidfile, O_RDONLY, 0644) == -1 ) { |
---|
| 191 | ROAR_WARN("restart_server(*): Can not read pidfile: %s", pidfile); |
---|
| 192 | } else { |
---|
| 193 | l = roar_vio_read(&fh, buf, 80); |
---|
| 194 | roar_vio_close(&fh); |
---|
| 195 | if ( l > 0 ) { |
---|
| 196 | buf[l-1] = 0; |
---|
| 197 | buf[79] = 0; |
---|
| 198 | pid = atoi(buf); |
---|
| 199 | if ( terminate ) { |
---|
[2113] | 200 | ok = kill(pid, SIGUSR1); |
---|
[2111] | 201 | } else { |
---|
| 202 | ok = kill(pid, SIGINT); |
---|
| 203 | } |
---|
| 204 | if ( ok == 0 ) { |
---|
| 205 | return 0; |
---|
| 206 | } else { |
---|
| 207 | ROAR_WARN("restart_server(*): Can not kill roard by pidfile"); |
---|
| 208 | } |
---|
| 209 | } else { |
---|
| 210 | ROAR_WARN("restart_server(*): Can not find a PID in the pidfile"); |
---|
| 211 | } |
---|
| 212 | } |
---|
| 213 | } |
---|
| 214 | #endif |
---|
[2109] | 215 | |
---|
[579] | 216 | if ( roar_connect(&con, server) == -1 ) { |
---|
| 217 | return -1; |
---|
| 218 | } |
---|
| 219 | |
---|
[2109] | 220 | if ( roar_terminate(&con, terminate) == -1 ) { |
---|
[579] | 221 | return -1; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | return roar_disconnect(&con); |
---|
| 225 | } |
---|
| 226 | |
---|
[444] | 227 | #define R_SETUID 1 |
---|
| 228 | #define R_SETGID 2 |
---|
| 229 | |
---|
[1609] | 230 | int init_config (void) { |
---|
| 231 | int i; |
---|
| 232 | |
---|
| 233 | memset(g_config, 0, sizeof(struct roard_config)); |
---|
| 234 | |
---|
| 235 | for (i = 0; i < ROAR_DIR_DIRIDS; i++) { |
---|
| 236 | g_config->streams[i].mixer_channels = 1; |
---|
| 237 | g_config->streams[i].mixer.rpg_mul = 1; |
---|
| 238 | g_config->streams[i].mixer.rpg_div = 1; |
---|
| 239 | g_config->streams[i].mixer.scale = 65535; |
---|
| 240 | g_config->streams[i].mixer.mixer[0] = g_config->streams[i].mixer.scale; |
---|
| 241 | } |
---|
| 242 | |
---|
[2291] | 243 | g_config->streams[ROAR_DIR_PLAY ].flags = ROAR_FLAG_META; |
---|
[2413] | 244 | g_config->streams[ROAR_DIR_OUTPUT ].flags = ROAR_FLAG_PASSMIXER; |
---|
[2264] | 245 | g_config->streams[ROAR_DIR_FILTER ].flags = ROAR_FLAG_SYNC; |
---|
[1899] | 246 | g_config->streams[ROAR_DIR_MIDI_OUT].flags = ROAR_FLAG_SYNC; |
---|
[2160] | 247 | g_config->streams[ROAR_DIR_BIDIR ].flags = ROAR_FLAG_ANTIECHO; |
---|
[1899] | 248 | |
---|
[2017] | 249 | g_config->location = "***default***"; |
---|
| 250 | |
---|
[1609] | 251 | return 0; |
---|
| 252 | } |
---|
| 253 | |
---|
[2530] | 254 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 255 | int init_listening (void) { |
---|
| 256 | int i; |
---|
| 257 | |
---|
| 258 | for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) { |
---|
| 259 | g_listen_socket[i] = -1; |
---|
| 260 | g_listen_proto[i] = ROAR_PROTO_ROARAUDIO; |
---|
| 261 | server[i] = NULL; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | return 0; |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | int add_listen (char * addr, int port, int sock_type, char * user, char * group, int proto) { |
---|
| 268 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
| 269 | struct group * grp = NULL; |
---|
| 270 | #endif |
---|
| 271 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
| 272 | struct passwd * pwd = NULL; |
---|
| 273 | #endif |
---|
| 274 | #ifdef ROAR_HAVE_UNIX |
---|
| 275 | char * env_roar_proxy_backup; |
---|
| 276 | #endif |
---|
| 277 | int sockid = -1; |
---|
| 278 | int sock; |
---|
| 279 | int i; |
---|
| 280 | |
---|
| 281 | if ( *addr != 0 ) { |
---|
| 282 | for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) { |
---|
| 283 | if ( g_listen_socket[i] == -1 ) { |
---|
| 284 | sockid = i; |
---|
| 285 | break; |
---|
| 286 | } |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | if ( sockid == -1 ) |
---|
| 290 | return -1; |
---|
| 291 | |
---|
| 292 | g_listen_proto[sockid] = proto; |
---|
| 293 | |
---|
| 294 | ROAR_DBG("add_listen(*): proto=0x%.4x", proto); |
---|
| 295 | |
---|
| 296 | if ( (g_listen_socket[sockid] = roar_socket_listen(sock_type, addr, port)) == -1 ) { |
---|
| 297 | #ifdef ROAR_HAVE_UNIX |
---|
| 298 | if ( *addr == '/' ) { |
---|
| 299 | if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) { |
---|
| 300 | env_roar_proxy_backup = strdup(env_roar_proxy_backup); |
---|
| 301 | unsetenv("ROAR_PROXY"); |
---|
| 302 | } |
---|
| 303 | if ( (sock = roar_socket_connect(addr, port)) != -1 ) { |
---|
| 304 | close(sock); |
---|
| 305 | ROAR_ERR("Can not open listen socket!"); |
---|
| 306 | return 1; |
---|
| 307 | } else { |
---|
| 308 | unlink(addr); |
---|
| 309 | if ( (g_listen_socket[sockid] = roar_socket_listen(sock_type, addr, port)) == -1 ) { |
---|
| 310 | ROAR_ERR("Can not open listen socket!"); |
---|
| 311 | return 1; |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | if ( env_roar_proxy_backup != NULL ) { |
---|
| 315 | setenv("ROAR_PROXY", env_roar_proxy_backup, 0); |
---|
| 316 | free(env_roar_proxy_backup); |
---|
| 317 | } |
---|
| 318 | #else |
---|
| 319 | if (0) { // noop |
---|
| 320 | #endif |
---|
| 321 | } else { |
---|
| 322 | ROAR_ERR("Can not open listen socket!"); |
---|
| 323 | return 1; |
---|
| 324 | } |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[2753] | 328 | if ( group != NULL ) { |
---|
| 329 | if ( (grp = getgrnam(group)) == NULL ) { |
---|
| 330 | ROAR_ERR("Can not get GID for group %s: %s", group, strerror(errno)); |
---|
| 331 | } |
---|
[2530] | 332 | } |
---|
| 333 | #endif |
---|
| 334 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[2752] | 335 | if ( user ) { |
---|
[2530] | 336 | if ( (pwd = getpwnam(user)) == NULL ) { |
---|
| 337 | ROAR_ERR("Can not get UID for user %s: %s", user, strerror(errno)); |
---|
| 338 | } |
---|
| 339 | } |
---|
| 340 | #endif |
---|
| 341 | |
---|
| 342 | #if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_UNIX) |
---|
| 343 | if ( *addr == '/' ) { |
---|
[2753] | 344 | if ( grp || pwd ) { |
---|
| 345 | if ( chown(addr, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 ) |
---|
[2530] | 346 | return 1; |
---|
[2753] | 347 | } |
---|
[2530] | 348 | #ifdef ROAR_HAVE_GETUID |
---|
[2753] | 349 | if ( grp ) { |
---|
[2530] | 350 | if ( getuid() == 0 ) |
---|
| 351 | if ( chmod(addr, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1 ) |
---|
| 352 | return 1; |
---|
[2753] | 353 | } |
---|
[2530] | 354 | #endif |
---|
| 355 | } |
---|
| 356 | #endif |
---|
| 357 | } |
---|
| 358 | |
---|
[2736] | 359 | // in case we opened the listening socket correctly. |
---|
| 360 | server[sockid] = addr; |
---|
[2530] | 361 | return 0; |
---|
| 362 | } |
---|
| 363 | #endif |
---|
| 364 | |
---|
[2339] | 365 | int update_stream_flags (char * str) { |
---|
| 366 | int dir; |
---|
| 367 | char * flags; |
---|
| 368 | char * k; |
---|
| 369 | int op; |
---|
| 370 | int flag; |
---|
| 371 | |
---|
| 372 | if ( (flags = strstr(str, "=")) == NULL ) |
---|
| 373 | return -1; |
---|
| 374 | |
---|
| 375 | *flags = 0; |
---|
| 376 | flags++; |
---|
| 377 | |
---|
| 378 | if ( (dir = roar_str2dir(str)) == -1 ) |
---|
| 379 | return -1; |
---|
| 380 | |
---|
| 381 | while (flags != NULL) { |
---|
| 382 | k = flags; |
---|
| 383 | flags = strstr(flags, ","); |
---|
| 384 | |
---|
| 385 | if ( flags != NULL ) |
---|
| 386 | *(flags++) = 0; |
---|
| 387 | |
---|
| 388 | switch (*k) { |
---|
[2340] | 389 | case '+': k++; op = ROAR_SET_FLAG; break; |
---|
| 390 | case '-': k++; op = ROAR_RESET_FLAG; break; |
---|
[2339] | 391 | default: |
---|
[2340] | 392 | op = ROAR_SET_FLAG; |
---|
[2339] | 393 | } |
---|
| 394 | |
---|
| 395 | flag = 0; |
---|
| 396 | |
---|
| 397 | if ( !strcmp(k, "sync") ) { |
---|
| 398 | flag = ROAR_FLAG_SYNC; |
---|
| 399 | } else if ( !strcmp(k, "meta") ) { |
---|
| 400 | flag = ROAR_FLAG_META; |
---|
| 401 | } else if ( !strcmp(k, "cleanmeta") ) { |
---|
| 402 | flag = ROAR_FLAG_CLEANMETA; |
---|
| 403 | } else if ( !strcmp(k, "pause") ) { |
---|
| 404 | flag = ROAR_FLAG_PAUSE; |
---|
| 405 | } else if ( !strcmp(k, "mute") ) { |
---|
| 406 | flag = ROAR_FLAG_MUTE; |
---|
| 407 | } else if ( !strcmp(k, "antiecho") ) { |
---|
| 408 | flag = ROAR_FLAG_ANTIECHO; |
---|
[2413] | 409 | } else if ( !strcmp(k, "passmixer") ) { |
---|
| 410 | flag = ROAR_FLAG_PASSMIXER; |
---|
[2339] | 411 | } else { |
---|
| 412 | return -1; |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | g_config->streams[dir].flags |= flag; |
---|
| 416 | |
---|
[2340] | 417 | if ( op == ROAR_RESET_FLAG ) |
---|
[2339] | 418 | g_config->streams[dir].flags -= flag; |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | return 0; |
---|
| 422 | } |
---|
| 423 | |
---|
[1145] | 424 | int add_output (char * drv, char * dev, char * opts, int prim, int count) { |
---|
[933] | 425 | int stream; |
---|
| 426 | struct roar_stream * s; |
---|
| 427 | struct roar_stream_server * ss; |
---|
[938] | 428 | char * k, * v; |
---|
[1208] | 429 | #ifdef ROAR_DRIVER_CODEC |
---|
| 430 | char * to_free = NULL; |
---|
| 431 | #endif |
---|
[1926] | 432 | int sync = 0, f_mmap = 0; |
---|
[1522] | 433 | int32_t blocks = -1, blocksize = -1; |
---|
[1920] | 434 | int dir = ROAR_DIR_OUTPUT; |
---|
[1991] | 435 | int error = 0; |
---|
| 436 | // DMX: |
---|
| 437 | int32_t channel = -1; |
---|
| 438 | int32_t universe = -1; |
---|
| 439 | uint16_t tu16; |
---|
[2085] | 440 | float q = -32e6; |
---|
[933] | 441 | |
---|
[938] | 442 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
[933] | 443 | |
---|
[1145] | 444 | if ( drv == NULL && count == 0 ) { |
---|
| 445 | drv = ROAR_DRIVER_DEFAULT; |
---|
| 446 | prim = 1; |
---|
| 447 | sync = 1; |
---|
[1208] | 448 | |
---|
| 449 | #ifdef ROAR_DRIVER_CODEC |
---|
| 450 | if ( opts == NULL ) { |
---|
| 451 | opts = to_free = strdup("codec=" ROAR_DRIVER_CODEC); |
---|
| 452 | } |
---|
| 453 | #endif |
---|
[1145] | 454 | } |
---|
| 455 | |
---|
[1227] | 456 | if ( opts == NULL && count == 0 ) { |
---|
| 457 | sync = 1; |
---|
| 458 | prim = 1; // if ( prim == 0 ) prim = 1; -> prim allways = 1 |
---|
| 459 | } |
---|
| 460 | |
---|
[2785] | 461 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
| 462 | |
---|
[933] | 463 | if ( (stream = streams_new()) == -1 ) { |
---|
[938] | 464 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts); |
---|
[982] | 465 | if ( prim ) alive = 0; |
---|
[933] | 466 | return -1; |
---|
| 467 | } |
---|
| 468 | |
---|
[2785] | 469 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
| 470 | |
---|
[933] | 471 | streams_get(stream, &ss); |
---|
| 472 | s = ROAR_STREAM(ss); |
---|
| 473 | |
---|
[2785] | 474 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
| 475 | |
---|
[2511] | 476 | memset(&(s->info), 0xFF, sizeof(struct roar_audio_info)); // set everything to -1 |
---|
[933] | 477 | |
---|
| 478 | s->pos_rel_id = -1; |
---|
| 479 | // s->info.codec = codec; |
---|
| 480 | |
---|
[2785] | 481 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
| 482 | |
---|
[2788] | 483 | if ( opts == NULL ) { |
---|
| 484 | k = NULL; |
---|
| 485 | } else { |
---|
| 486 | k = strtok(opts, ","); |
---|
| 487 | } |
---|
[2786] | 488 | |
---|
| 489 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s'): initial k='%s'(%p)", drv, dev, opts, k, k); |
---|
| 490 | |
---|
[938] | 491 | while (k != NULL) { |
---|
| 492 | // ROAR_WARN("add_output(*): opts: %s", k); |
---|
| 493 | |
---|
| 494 | if ( (v = strstr(k, "=")) != NULL ) { |
---|
| 495 | *v++ = 0; |
---|
| 496 | } |
---|
| 497 | |
---|
| 498 | ROAR_DBG("add_output(*): opts: k='%s', v='%s'", k, v); |
---|
| 499 | if ( strcmp(k, "rate") == 0 ) { |
---|
| 500 | s->info.rate = atoi(v); |
---|
| 501 | } else if ( strcmp(k, "channels") == 0 ) { |
---|
| 502 | s->info.channels = atoi(v); |
---|
| 503 | } else if ( strcmp(k, "bits") == 0 ) { |
---|
| 504 | s->info.bits = atoi(v); |
---|
| 505 | } else if ( strcmp(k, "codec") == 0 ) { |
---|
[2511] | 506 | if ( (s->info.codec = roar_str2codec(v)) == -1 ) { |
---|
[938] | 507 | ROAR_ERR("add_output(*): unknown codec '%s'", v); |
---|
[1991] | 508 | error++; |
---|
[938] | 509 | } |
---|
[2085] | 510 | } else if ( strcmp(k, "q") == 0 ) { |
---|
| 511 | q = atof(v); |
---|
[1221] | 512 | } else if ( strcmp(k, "blocks") == 0 ) { |
---|
| 513 | blocks = atoi(v); |
---|
[1522] | 514 | } else if ( strcmp(k, "blocksize") == 0 ) { |
---|
| 515 | blocksize = atoi(v); |
---|
[1926] | 516 | } else if ( strcmp(k, "mmap") == 0 ) { |
---|
| 517 | f_mmap = 1; |
---|
[1919] | 518 | } else if ( strcmp(k, "subsystem") == 0 ) { |
---|
| 519 | if ( !strcasecmp(v, "wave") || !strcasecmp(v, "waveform") ) { |
---|
[1920] | 520 | dir = ROAR_DIR_OUTPUT; |
---|
[2494] | 521 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[1919] | 522 | } else if ( !strcasecmp(v, "midi") ) { |
---|
| 523 | dir = ROAR_DIR_MIDI_OUT; |
---|
[2494] | 524 | #endif |
---|
| 525 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1919] | 526 | } else if ( !strcasecmp(v, "light") ) { |
---|
| 527 | dir = ROAR_DIR_LIGHT_OUT; |
---|
[2494] | 528 | #endif |
---|
| 529 | #ifndef ROAR_WITHOUT_DCOMP_RAW |
---|
[2234] | 530 | } else if ( !strcasecmp(v, "raw") ) { |
---|
| 531 | dir = ROAR_DIR_RAW_OUT; |
---|
[2494] | 532 | #endif |
---|
[2681] | 533 | } else if ( !strcasecmp(v, "complex") ) { |
---|
| 534 | dir = ROAR_DIR_COMPLEX_OUT; |
---|
[1919] | 535 | } else { |
---|
[2494] | 536 | ROAR_ERR("add_output(*): unknown/unsupported subsystem '%s'", k); |
---|
[1991] | 537 | error++; |
---|
| 538 | } |
---|
| 539 | // DMX: |
---|
| 540 | } else if ( strcmp(k, "channel") == 0 ) { |
---|
| 541 | channel = atoi(v); |
---|
| 542 | if ( channel < 0 || channel > 65535 ) { |
---|
| 543 | ROAR_ERR("add_output(*): Invalide channel (not within 0..65535): %i", channel); |
---|
| 544 | channel = -1; |
---|
| 545 | error++; |
---|
[1919] | 546 | } |
---|
[1991] | 547 | } else if ( strcmp(k, "universe") == 0 ) { |
---|
| 548 | universe = atoi(v); |
---|
| 549 | if ( universe < 0 || universe > 255 ) { |
---|
| 550 | ROAR_ERR("add_output(*): Invalide universe (not within 0..255): %i", universe); |
---|
| 551 | universe = -1; |
---|
| 552 | error++; |
---|
| 553 | } |
---|
| 554 | |
---|
[2115] | 555 | } else if ( strcmp(k, "name") == 0 ) { |
---|
| 556 | if ( streams_set_name(stream, v) == -1 ) { |
---|
| 557 | ROAR_ERR("add_output(*): Can not set Stream name"); |
---|
| 558 | error++; |
---|
| 559 | } |
---|
[1991] | 560 | |
---|
[1032] | 561 | } else if ( strcmp(k, "meta") == 0 ) { |
---|
| 562 | streams_set_flag(stream, ROAR_FLAG_META); |
---|
[1117] | 563 | } else if ( strcmp(k, "sync") == 0 ) { |
---|
| 564 | sync = 1; |
---|
[1221] | 565 | } else if ( strcmp(k, "primary") == 0 ) { |
---|
| 566 | prim = 1; |
---|
| 567 | |
---|
| 568 | } else if ( strcmp(k, "cleanmeta") == 0 ) { |
---|
| 569 | streams_set_flag(stream, ROAR_FLAG_CLEANMETA); |
---|
| 570 | } else if ( strcmp(k, "autoconf") == 0 ) { |
---|
[1531] | 571 | streams_set_flag(stream, ROAR_FLAG_AUTOCONF); |
---|
[2413] | 572 | } else if ( strcmp(k, "recsource") == 0 ) { |
---|
| 573 | streams_set_flag(stream, ROAR_FLAG_RECSOURCE); |
---|
| 574 | } else if ( strcmp(k, "passmixer") == 0 ) { |
---|
| 575 | streams_set_flag(stream, ROAR_FLAG_PASSMIXER); |
---|
[938] | 576 | } else { |
---|
| 577 | ROAR_ERR("add_output(*): unknown option '%s'", k); |
---|
[1991] | 578 | error++; |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | if ( error ) { |
---|
[938] | 582 | streams_delete(stream); |
---|
[982] | 583 | if ( prim ) alive = 0; |
---|
[1208] | 584 | #ifdef ROAR_DRIVER_CODEC |
---|
| 585 | if ( to_free != NULL ) |
---|
| 586 | free(to_free); |
---|
| 587 | #endif |
---|
[938] | 588 | return -1; |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | k = strtok(NULL, ","); |
---|
| 592 | } |
---|
| 593 | |
---|
[2785] | 594 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
| 595 | |
---|
[2511] | 596 | // set audio info... |
---|
| 597 | switch (dir) { |
---|
| 598 | case ROAR_DIR_LIGHT_OUT: |
---|
| 599 | switch (s->info.codec) { |
---|
| 600 | case ROAR_CODEC_DMX512: |
---|
| 601 | case -1: |
---|
| 602 | if ( s->info.rate == -1 ) |
---|
| 603 | s->info.rate = ROAR_OUTPUT_CFREQ; |
---|
| 604 | |
---|
| 605 | s->info.channels = 0; |
---|
| 606 | s->info.bits = 8; |
---|
| 607 | s->info.codec = ROAR_CODEC_DMX512; // in case codec == -1 |
---|
| 608 | break; |
---|
| 609 | } |
---|
| 610 | break; |
---|
| 611 | case ROAR_DIR_MIDI_OUT: |
---|
| 612 | switch (s->info.codec) { |
---|
| 613 | case ROAR_CODEC_MIDI: |
---|
| 614 | case -1: |
---|
| 615 | if ( s->info.rate == -1 ) |
---|
| 616 | s->info.rate = ROAR_MIDI_TICKS_PER_BEAT; |
---|
| 617 | |
---|
| 618 | s->info.channels = ROAR_MIDI_CHANNELS_DEFAULT; |
---|
| 619 | s->info.bits = ROAR_MIDI_BITS; |
---|
| 620 | s->info.codec = ROAR_CODEC_MIDI; // in case codec == -1 |
---|
| 621 | break; |
---|
| 622 | } |
---|
| 623 | break; |
---|
| 624 | case ROAR_DIR_RAW_OUT: |
---|
| 625 | if ( s->info.rate == -1 ) |
---|
| 626 | s->info.rate = 0; |
---|
| 627 | if ( s->info.bits == -1 ) |
---|
| 628 | s->info.bits = 0; |
---|
| 629 | if ( s->info.channels == -1 ) |
---|
| 630 | s->info.channels = 0; |
---|
| 631 | if ( s->info.codec == -1 ) |
---|
| 632 | s->info.codec = 0; |
---|
| 633 | break; |
---|
| 634 | } |
---|
| 635 | |
---|
| 636 | if ( s->info.rate == -1 ) |
---|
| 637 | s->info.rate = g_sa->rate; |
---|
| 638 | if ( s->info.bits == -1 ) |
---|
| 639 | s->info.bits = g_sa->bits; |
---|
| 640 | if ( s->info.channels == -1 ) |
---|
| 641 | s->info.channels = g_sa->channels; |
---|
| 642 | if ( s->info.codec == -1 ) |
---|
| 643 | s->info.codec = g_sa->codec; |
---|
| 644 | |
---|
| 645 | ROAR_DBG("add_output(*): s->info = {.rate=%i, .bits=%i, .channels=%i, .codec=%i}", s->info.rate, s->info.bits, s->info.channels, s->info.codec); |
---|
| 646 | |
---|
[1919] | 647 | if ( streams_set_dir(stream, dir, 1) == -1 ) { |
---|
| 648 | streams_delete(stream); |
---|
| 649 | return -1; |
---|
| 650 | } |
---|
| 651 | |
---|
[1208] | 652 | #ifdef ROAR_DRIVER_CODEC |
---|
| 653 | if ( to_free != NULL ) |
---|
| 654 | free(to_free); |
---|
| 655 | #endif |
---|
| 656 | |
---|
[2511] | 657 | if ( s->info.codec == ROAR_CODEC_ALAW || s->info.codec == ROAR_CODEC_MULAW ) |
---|
[941] | 658 | s->info.bits = 8; // needed to open OSS driver, will be overriden by codecfilter |
---|
| 659 | |
---|
[2511] | 660 | ROAR_STREAM_SERVER(s)->codec_orgi = s->info.codec; |
---|
[933] | 661 | |
---|
[2364] | 662 | if ( driver_openvio(&(ss->vio), &(ss->driver_id), drv, dev, &(s->info), -1, ss) == -1 ) { |
---|
[1581] | 663 | ss->driver_id = -1; // don't close a driver not opened... |
---|
| 664 | memset(&(ss->vio), 0, sizeof(struct roar_vio_calls)); |
---|
[933] | 665 | streams_delete(stream); |
---|
[938] | 666 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts); |
---|
[982] | 667 | if ( prim ) alive = 0; |
---|
[933] | 668 | return -1; |
---|
| 669 | } |
---|
| 670 | |
---|
[1528] | 671 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAMID, &stream); // ignore errors here |
---|
| 672 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAM, s); // ignore errors here |
---|
| 673 | |
---|
[1221] | 674 | if ( blocks != -1 ) |
---|
| 675 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLOCKS, &blocks); |
---|
| 676 | |
---|
[1522] | 677 | if ( blocksize != -1 ) |
---|
| 678 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLKSIZE, &blocksize); |
---|
| 679 | |
---|
[1991] | 680 | // TODO: we shoudld *really* check for errors here... |
---|
| 681 | if ( channel != -1 ) { |
---|
| 682 | tu16 = channel; |
---|
| 683 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXSCHAN, &tu16); |
---|
| 684 | } |
---|
| 685 | if ( universe != -1 ) { |
---|
| 686 | tu16 = universe; |
---|
| 687 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXUNIV, &tu16); |
---|
| 688 | } |
---|
| 689 | |
---|
[1156] | 690 | ROAR_DBG("add_output(*): ss->driver_id=%i", ss->driver_id); |
---|
| 691 | |
---|
[938] | 692 | streams_set_fh(stream, -1); // update some internal structures |
---|
| 693 | |
---|
[2087] | 694 | if ( q > -1e6 ) { |
---|
| 695 | ROAR_DBG("add_output(*): setting q=%f", q); |
---|
| 696 | streams_ctl(stream, ROAR_CODECFILTER_CTL_SET_Q|ROAR_STREAM_CTL_TYPE_FLOAT, &q); |
---|
| 697 | } |
---|
| 698 | |
---|
[2490] | 699 | client_stream_add(g_self_client, stream); |
---|
[933] | 700 | |
---|
[1200] | 701 | if ( prim ) { |
---|
[961] | 702 | streams_mark_primary(stream); |
---|
[1200] | 703 | s->pos_rel_id = stream; |
---|
| 704 | } |
---|
[961] | 705 | |
---|
[1120] | 706 | if ( sync ) { |
---|
[1117] | 707 | streams_set_flag(stream, ROAR_FLAG_SYNC); |
---|
[1120] | 708 | } else { |
---|
| 709 | streams_reset_flag(stream, ROAR_FLAG_SYNC); |
---|
| 710 | } |
---|
[1117] | 711 | |
---|
[1926] | 712 | if ( f_mmap ) |
---|
| 713 | streams_set_flag(stream, ROAR_FLAG_MMAP); |
---|
| 714 | |
---|
[2511] | 715 | ROAR_DBG("add_output(*): s->info = {.rate=%i, .bits=%i, .channels=%i, .codec=%i}", s->info.rate, s->info.bits, s->info.channels, s->info.codec); |
---|
[933] | 716 | return 0; |
---|
[932] | 717 | } |
---|
| 718 | |
---|
[1993] | 719 | |
---|
| 720 | // SLP: |
---|
| 721 | void register_slp_callback(SLPHandle hslp, SLPError errcode, void * cookie) { |
---|
| 722 | /* return the error code in the cookie */ |
---|
| 723 | *(SLPError*)cookie = errcode; |
---|
| 724 | } |
---|
| 725 | |
---|
| 726 | int register_slp (int unreg, char * sockname) { |
---|
| 727 | #ifdef ROAR_HAVE_LIBSLP |
---|
| 728 | static int regged = 0; |
---|
| 729 | static char * sn = NULL; |
---|
| 730 | SLPError err; |
---|
| 731 | SLPError callbackerr; |
---|
| 732 | SLPHandle hslp; |
---|
| 733 | char addr[1024]; |
---|
| 734 | char attr[1024] = ""; |
---|
[2017] | 735 | char * location; |
---|
[1993] | 736 | |
---|
| 737 | if ( sockname != NULL ) |
---|
| 738 | sn = sockname; |
---|
| 739 | |
---|
[2016] | 740 | snprintf(addr, sizeof(addr), ROAR_SLP_URL_TYPE "://%s", sn); |
---|
[1993] | 741 | |
---|
| 742 | err = SLPOpen("en", SLP_FALSE, &hslp); |
---|
| 743 | |
---|
| 744 | if (err != SLP_OK) { |
---|
| 745 | ROAR_ERR("Error opening slp handle: Error #%i", err); |
---|
| 746 | return -1; |
---|
| 747 | } |
---|
| 748 | |
---|
| 749 | if (!unreg) { |
---|
[2017] | 750 | |
---|
| 751 | if ( SLPEscape(g_config->location, &location, SLP_FALSE) != SLP_OK ) { |
---|
| 752 | ROAR_ERR("Error using SLPEscape() on server location, really bad!"); |
---|
| 753 | SLPClose(hslp); |
---|
| 754 | return -1; |
---|
| 755 | } |
---|
| 756 | |
---|
[1995] | 757 | snprintf(attr, sizeof(attr), "(wave-rate=%i),(wave-channels=%i),(wave-bits=%i)," |
---|
[2494] | 758 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
| 759 | "(light-channels=%i)," |
---|
| 760 | #endif |
---|
| 761 | "(location=%s)", |
---|
[1995] | 762 | g_sa->rate, g_sa->channels, g_sa->bits, |
---|
[2494] | 763 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[2017] | 764 | g_light_state.channels, |
---|
[2494] | 765 | #endif |
---|
[2017] | 766 | location |
---|
[1995] | 767 | ); |
---|
| 768 | |
---|
[1993] | 769 | /* Register a service with SLP */ |
---|
| 770 | err = SLPReg(hslp, |
---|
| 771 | addr, |
---|
| 772 | SLP_LIFETIME_MAXIMUM, |
---|
| 773 | 0, |
---|
| 774 | attr, |
---|
| 775 | SLP_TRUE, |
---|
| 776 | register_slp_callback, |
---|
| 777 | &callbackerr); |
---|
[1994] | 778 | regged = 1; |
---|
| 779 | } else if ( unreg && regged ) { |
---|
| 780 | err = SLPDereg(hslp, addr, register_slp_callback, &callbackerr); |
---|
| 781 | regged = 0; |
---|
| 782 | } else { |
---|
| 783 | SLPClose(hslp); |
---|
| 784 | return -1; |
---|
| 785 | } |
---|
[1993] | 786 | |
---|
[1994] | 787 | /* err may contain an error code that occurred as the slp library */ |
---|
| 788 | /* _prepared_ to make the call. */ |
---|
| 789 | if ( err != SLP_OK ) { |
---|
| 790 | ROAR_ERR("Error (de)registering service with slp: Error #%i", err); |
---|
| 791 | return -1; |
---|
| 792 | } |
---|
| 793 | |
---|
| 794 | /* callbackerr may contain an error code (that was assigned through */ |
---|
| 795 | /* the callback cookie) that occurred as slp packets were sent on */ |
---|
| 796 | /* the wire */ |
---|
| 797 | if (callbackerr != SLP_OK) { |
---|
| 798 | ROAR_ERR("Error (de)registering service with slp: Error #%i", callbackerr); |
---|
| 799 | return -1; |
---|
[1993] | 800 | } |
---|
| 801 | |
---|
| 802 | SLPClose(hslp); |
---|
| 803 | return 0; |
---|
| 804 | #else |
---|
| 805 | return -1; |
---|
| 806 | #endif |
---|
| 807 | } |
---|
| 808 | |
---|
| 809 | |
---|
| 810 | // MAIN: |
---|
| 811 | |
---|
[1503] | 812 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 813 | int main (int argc, char * argv[]) { |
---|
[1503] | 814 | #else |
---|
| 815 | int main (void) { |
---|
| 816 | #endif |
---|
| 817 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 818 | int i; |
---|
| 819 | char * k; |
---|
[1503] | 820 | #endif |
---|
[2787] | 821 | #if defined(ROAR_SUPPORT_LISTEN) && defined(ROAR_HAVE_GETUID) |
---|
[905] | 822 | char user_sock[80] = {0}; |
---|
[1494] | 823 | #endif |
---|
[1609] | 824 | struct roar_audio_info sa, max_sa; |
---|
| 825 | struct roard_config config; |
---|
[1486] | 826 | #ifdef ROAR_HAVE_FORK |
---|
[905] | 827 | int daemon = 0; |
---|
[1486] | 828 | #endif |
---|
[905] | 829 | int realtime = 0; |
---|
| 830 | int sysclocksync = 0; |
---|
[1207] | 831 | char * driver = NULL; |
---|
| 832 | char * device = NULL; |
---|
[1503] | 833 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[1207] | 834 | char * opts = NULL; |
---|
[1503] | 835 | #endif |
---|
[60] | 836 | // char * server = ROAR_DEFAULT_SOCK_GLOBAL; |
---|
[1494] | 837 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 838 | int port = ROAR_DEFAULT_PORT; |
---|
| 839 | char * sock_addr = NULL; |
---|
| 840 | int sock_proto = ROAR_PROTO_ROARAUDIO; |
---|
[1494] | 841 | #endif |
---|
[0] | 842 | int drvid; |
---|
[2486] | 843 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[550] | 844 | char * s_drv = "cf"; |
---|
[1110] | 845 | char * s_dev = NULL; |
---|
[444] | 846 | char * s_con = NULL; |
---|
| 847 | char * s_opt = NULL; |
---|
| 848 | int s_prim = 0; |
---|
[2486] | 849 | #endif |
---|
[1207] | 850 | char * o_drv = getenv("ROAR_DRIVER"); |
---|
| 851 | char * o_dev = getenv("ROAR_DEVICE"); |
---|
[932] | 852 | char * o_opts = NULL; |
---|
[961] | 853 | int o_prim = 0; |
---|
[1145] | 854 | int o_count = 0; |
---|
[2494] | 855 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1923] | 856 | int light_channels = LIGHT_CHANNELS_DEFAULT; |
---|
[2494] | 857 | #endif |
---|
[2751] | 858 | #ifdef ROAR_DEFAULT_SOCKGRP |
---|
[450] | 859 | char * sock_grp = ROAR_DEFAULT_SOCKGRP; |
---|
[2751] | 860 | #else |
---|
| 861 | char * sock_grp = NULL; |
---|
| 862 | #endif |
---|
[444] | 863 | char * sock_user = NULL; |
---|
[1494] | 864 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[517] | 865 | int sock_type = ROAR_SOCKET_TYPE_UNKNOWN; |
---|
[1494] | 866 | #endif |
---|
[1993] | 867 | #ifdef ROAR_HAVE_LIBSLP |
---|
| 868 | int reg_slp = 0; |
---|
| 869 | #endif |
---|
[1486] | 870 | #ifdef ROAR_HAVE_CHROOT |
---|
[444] | 871 | char * chrootdir = NULL; |
---|
[1486] | 872 | #endif |
---|
| 873 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[446] | 874 | struct group * grp = NULL; |
---|
[1486] | 875 | #endif |
---|
| 876 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[446] | 877 | struct passwd * pwd = NULL; |
---|
[1486] | 878 | #endif |
---|
| 879 | #ifdef ROAR_HAVE_GETSERVBYNAME |
---|
[446] | 880 | struct servent * serv = NULL; |
---|
[1486] | 881 | #endif |
---|
[0] | 882 | DRIVER_USERDATA_T drvinst; |
---|
[39] | 883 | struct roar_client * self = NULL; |
---|
[508] | 884 | #ifdef ROAR_HAVE_LIBDNET |
---|
| 885 | char decnethost[80]; |
---|
| 886 | #endif |
---|
[2104] | 887 | #ifdef SUPPORT_PIDFILE |
---|
| 888 | struct roar_vio_calls pidfile_vio; |
---|
| 889 | #endif |
---|
[0] | 890 | |
---|
[2784] | 891 | ROAR_DBG("main(*): starting roard..."); |
---|
| 892 | |
---|
[0] | 893 | g_standby = 0; |
---|
[920] | 894 | g_autostandby = 0; |
---|
[982] | 895 | alive = 1; |
---|
[1494] | 896 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[1155] | 897 | g_no_listen = 0; |
---|
[1494] | 898 | #else |
---|
| 899 | g_terminate = 1; |
---|
| 900 | #endif |
---|
[0] | 901 | |
---|
| 902 | sa.bits = ROAR_BITS_DEFAULT; |
---|
| 903 | sa.channels = ROAR_CHANNELS_DEFAULT; |
---|
| 904 | sa.rate = ROAR_RATE_DEFAULT; |
---|
| 905 | sa.codec = ROAR_CODEC_DEFAULT; |
---|
| 906 | |
---|
[1609] | 907 | g_sa = &sa; |
---|
| 908 | g_max_sa = &max_sa; |
---|
| 909 | |
---|
| 910 | memcpy(g_max_sa, g_sa, sizeof(max_sa)); |
---|
| 911 | |
---|
| 912 | g_config = &config; |
---|
| 913 | |
---|
| 914 | if ( init_config() == -1 ) { |
---|
| 915 | ROAR_ERR("Can not init default config!"); |
---|
| 916 | return 1; |
---|
| 917 | } |
---|
[0] | 918 | |
---|
[2530] | 919 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 920 | if ( init_listening() == -1 ) { |
---|
| 921 | ROAR_ERR("Can not init listening sockets!"); |
---|
| 922 | return 1; |
---|
| 923 | } |
---|
| 924 | #endif |
---|
| 925 | |
---|
[2500] | 926 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[1924] | 927 | if ( midi_init_config() == -1 ) { |
---|
| 928 | ROAR_ERR("Can not init MIDI config!"); |
---|
| 929 | return 1; |
---|
| 930 | } |
---|
[2500] | 931 | #endif |
---|
[60] | 932 | |
---|
[2489] | 933 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
[2451] | 934 | if ( ssynth_init_config() == -1 ) { |
---|
| 935 | ROAR_ERR("Can not init ssynth config!"); |
---|
| 936 | return 1; |
---|
| 937 | } |
---|
[2489] | 938 | #endif |
---|
[2451] | 939 | |
---|
[2718] | 940 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 941 | if ( rdtcs_init_config() == -1 ) { |
---|
| 942 | ROAR_ERR("Can not init RDTCS config!"); |
---|
| 943 | return 1; |
---|
| 944 | } |
---|
| 945 | #endif |
---|
| 946 | |
---|
[1494] | 947 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2767] | 948 | #ifndef ROAR_TARGET_WIN32 |
---|
[2530] | 949 | sock_addr = ROAR_DEFAULT_SOCK_GLOBAL; |
---|
[2767] | 950 | #else |
---|
| 951 | sock_addr = ROAR_DEFAULT_HOST; |
---|
| 952 | #endif |
---|
| 953 | |
---|
[1753] | 954 | #ifdef ROAR_HAVE_GETUID |
---|
[1486] | 955 | if ( getuid() != 0 && getenv("HOME") != NULL ) { |
---|
| 956 | snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER); |
---|
[2530] | 957 | sock_addr = user_sock; |
---|
[60] | 958 | } |
---|
[1753] | 959 | #endif |
---|
[60] | 960 | |
---|
[279] | 961 | if ( getenv("ROAR_SERVER") != NULL ) |
---|
[2530] | 962 | sock_addr = getenv("ROAR_SERVER"); |
---|
[1494] | 963 | #endif |
---|
[279] | 964 | |
---|
[63] | 965 | if ( clients_init() == -1 ) { |
---|
| 966 | ROAR_ERR("Can not init clients!"); |
---|
| 967 | return 1; |
---|
| 968 | } |
---|
| 969 | |
---|
| 970 | if ( streams_init() == -1 ) { |
---|
| 971 | ROAR_ERR("Can not init streams!"); |
---|
| 972 | return 1; |
---|
| 973 | } |
---|
| 974 | |
---|
[64] | 975 | if ( (g_self_client = clients_new()) == -1 ) { |
---|
| 976 | ROAR_ERR("Can not create self client!"); |
---|
| 977 | return 1; |
---|
| 978 | } |
---|
| 979 | |
---|
[2485] | 980 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[0] | 981 | if ( sources_init() == -1 ) { |
---|
| 982 | ROAR_ERR("Can not init sources!"); |
---|
| 983 | return 1; |
---|
| 984 | } |
---|
| 985 | |
---|
[64] | 986 | if ( (sources_set_client(g_self_client)) == -1 ) { |
---|
| 987 | ROAR_ERR("Can not init set source client!"); |
---|
| 988 | return 1; |
---|
| 989 | } |
---|
[2485] | 990 | #endif |
---|
[64] | 991 | |
---|
[1503] | 992 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 993 | for (i = 1; i < argc; i++) { |
---|
| 994 | k = argv[i]; |
---|
| 995 | |
---|
| 996 | if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) { |
---|
| 997 | usage(); |
---|
| 998 | return 0; |
---|
| 999 | |
---|
[2109] | 1000 | } else if ( strcmp(k, "--start") == 0 ) { |
---|
| 1001 | // this is a no op |
---|
[579] | 1002 | } else if ( strcmp(k, "--restart") == 0 ) { |
---|
[1494] | 1003 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1004 | if ( restart_server(sock_addr, 1) == -1 ) { |
---|
| 1005 | ROAR_WARN("Can not terminate old server (not running at %s?), tring to continue anyway", sock_addr); |
---|
[579] | 1006 | } |
---|
[1494] | 1007 | #else |
---|
| 1008 | ROAR_ERR("--restart not supported"); |
---|
| 1009 | #endif |
---|
[2109] | 1010 | } else if ( strcmp(k, "--shutdown") == 0 ) { |
---|
| 1011 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1012 | if ( restart_server(sock_addr, 1) == -1 ) { |
---|
| 1013 | ROAR_WARN("Can not terminate old server (not running at %s?)", sock_addr); |
---|
[2109] | 1014 | return 1; |
---|
| 1015 | } |
---|
| 1016 | return 0; |
---|
| 1017 | #else |
---|
| 1018 | ROAR_ERR("--shutdown not supported"); |
---|
| 1019 | return 1; |
---|
| 1020 | #endif |
---|
| 1021 | } else if ( strcmp(k, "--stop") == 0 ) { |
---|
| 1022 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1023 | if ( restart_server(sock_addr, 0) == -1 ) { |
---|
| 1024 | ROAR_WARN("Can not stop old server (not running at %s?)", sock_addr); |
---|
[2109] | 1025 | return 1; |
---|
| 1026 | } |
---|
| 1027 | return 0; |
---|
| 1028 | #else |
---|
| 1029 | ROAR_ERR("--stop not supported"); |
---|
| 1030 | return 1; |
---|
| 1031 | #endif |
---|
| 1032 | |
---|
[579] | 1033 | |
---|
[775] | 1034 | } else if ( strcmp(k, "--demon") == 0 || strcmp(k, "--daemon") == 0 ) { |
---|
[1486] | 1035 | #ifdef ROAR_HAVE_FORK |
---|
[775] | 1036 | daemon = 1; |
---|
[1486] | 1037 | #else |
---|
| 1038 | ROAR_ERR("--daemon not supported"); |
---|
| 1039 | #endif |
---|
[71] | 1040 | } else if ( strcmp(k, "--terminate") == 0 ) { |
---|
| 1041 | g_terminate = 1; |
---|
[905] | 1042 | } else if ( strcmp(k, "--sysclocksync") == 0 ) { |
---|
| 1043 | sysclocksync = 1000; |
---|
[275] | 1044 | } else if ( strcmp(k, "--realtime") == 0 ) { |
---|
[276] | 1045 | realtime++; |
---|
[444] | 1046 | } else if ( strcmp(k, "--chroot") == 0 ) { |
---|
[1486] | 1047 | #ifdef ROAR_HAVE_CHROOT |
---|
[444] | 1048 | chrootdir = argv[++i]; |
---|
[1486] | 1049 | #else |
---|
| 1050 | ROAR_ERR("--chroot not supported"); |
---|
| 1051 | i++; |
---|
| 1052 | #endif |
---|
[444] | 1053 | } else if ( strcmp(k, "--setgid") == 0 ) { |
---|
[1486] | 1054 | #ifdef ROAR_HAVE_SETGID |
---|
[444] | 1055 | setids |= R_SETGID; |
---|
[1486] | 1056 | #else |
---|
| 1057 | ROAR_ERR("--setgid not supported"); |
---|
| 1058 | #endif |
---|
[444] | 1059 | } else if ( strcmp(k, "--setuid") == 0 ) { |
---|
[1486] | 1060 | #ifdef ROAR_HAVE_SETUID |
---|
[444] | 1061 | setids |= R_SETUID; |
---|
[1486] | 1062 | #else |
---|
| 1063 | ROAR_ERR("--setuid not supported"); |
---|
| 1064 | #endif |
---|
[2017] | 1065 | } else if ( strcmp(k, "--location") == 0 ) { |
---|
| 1066 | g_config->location = argv[++i]; |
---|
[2104] | 1067 | } else if ( strcmp(k, "--pidfile") == 0 ) { |
---|
| 1068 | #ifdef SUPPORT_PIDFILE |
---|
| 1069 | pidfile = argv[++i]; |
---|
| 1070 | #else |
---|
| 1071 | ROAR_ERR("--pidfile not supported"); |
---|
| 1072 | i++; |
---|
| 1073 | #endif |
---|
[68] | 1074 | |
---|
[280] | 1075 | } else if ( strcmp(k, "--list-cf") == 0 ) { |
---|
| 1076 | print_codecfilterlist(); |
---|
| 1077 | return 0; |
---|
| 1078 | |
---|
[0] | 1079 | } else if ( strcmp(k, "-R") == 0 || strcmp(k, "--rate") == 0 ) { |
---|
| 1080 | sa.rate = atoi(argv[++i]); |
---|
| 1081 | } else if ( strcmp(k, "-B") == 0 || strcmp(k, "--bits") == 0 ) { |
---|
| 1082 | sa.bits = atoi(argv[++i]); |
---|
| 1083 | } else if ( strcmp(k, "-C") == 0 || strcmp(k, "--chans") == 0 ) { |
---|
| 1084 | sa.channels = atoi(argv[++i]); |
---|
| 1085 | |
---|
[2339] | 1086 | } else if ( strcmp(k, "--stream-flags") == 0 ) { |
---|
| 1087 | if ( update_stream_flags(argv[++i]) == -1 ) { |
---|
| 1088 | ROAR_ERR("Can not set stream flags"); |
---|
| 1089 | return 1; |
---|
| 1090 | } |
---|
| 1091 | |
---|
[0] | 1092 | } else if ( strcmp(k, "-d") == 0 || strcmp(k, "--driver") == 0 ) { |
---|
| 1093 | driver = argv[++i]; |
---|
| 1094 | if ( strcmp(driver, "list") == 0 ) { |
---|
[974] | 1095 | ROAR_WARN("The option is obsolete, use --list-driver!"); |
---|
[0] | 1096 | print_driverlist(); |
---|
[973] | 1097 | return 0; |
---|
[0] | 1098 | } |
---|
| 1099 | } else if ( strcmp(k, "-D") == 0 || strcmp(k, "--device") == 0 ) { |
---|
| 1100 | device = argv[++i]; |
---|
| 1101 | } else if ( strcmp(k, "-dO") == 0 ) { |
---|
| 1102 | opts = argv[++i]; |
---|
[973] | 1103 | } else if ( strcmp(k, "--list-driver") == 0 ) { |
---|
| 1104 | print_driverlist(); |
---|
| 1105 | return 0; |
---|
[0] | 1106 | |
---|
[932] | 1107 | } else if ( strcmp(k, "-o") == 0 || strcmp(k, "--odriver") == 0 ) { |
---|
| 1108 | o_drv = argv[++i]; |
---|
| 1109 | } else if ( strcmp(k, "-O") == 0 || strcmp(k, "--odevice") == 0 ) { |
---|
| 1110 | o_dev = argv[++i]; |
---|
| 1111 | } else if ( strcmp(k, "-oO") == 0 ) { |
---|
| 1112 | o_opts = argv[++i]; |
---|
[961] | 1113 | } else if ( strcmp(k, "-oP") == 0 ) { |
---|
| 1114 | o_prim = 1; |
---|
[932] | 1115 | } else if ( strcmp(k, "-oN") == 0 ) { |
---|
[1145] | 1116 | if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 ) |
---|
| 1117 | o_count++; |
---|
| 1118 | |
---|
[961] | 1119 | o_drv = o_dev = o_opts = NULL; |
---|
| 1120 | o_prim = 0; |
---|
[932] | 1121 | |
---|
[0] | 1122 | } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) { |
---|
[2485] | 1123 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[550] | 1124 | s_drv = argv[++i]; |
---|
[2485] | 1125 | #else |
---|
| 1126 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
| 1127 | #endif |
---|
[550] | 1128 | } else if ( strcmp(k, "-S") == 0 ) { |
---|
[2485] | 1129 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[1110] | 1130 | s_dev = argv[++i]; |
---|
[2485] | 1131 | #else |
---|
| 1132 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
| 1133 | #endif |
---|
[0] | 1134 | } else if ( strcmp(k, "-sO") == 0 ) { |
---|
[2485] | 1135 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[0] | 1136 | s_opt = argv[++i]; |
---|
[2485] | 1137 | #else |
---|
| 1138 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
| 1139 | #endif |
---|
[0] | 1140 | } else if ( strcmp(k, "-sC") == 0 ) { |
---|
[2485] | 1141 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[0] | 1142 | s_con = argv[++i]; |
---|
[2485] | 1143 | #else |
---|
| 1144 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
| 1145 | #endif |
---|
[0] | 1146 | } else if ( strcmp(k, "-sP") == 0 ) { |
---|
[2485] | 1147 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[0] | 1148 | s_prim = 1; |
---|
[2485] | 1149 | #else |
---|
| 1150 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
| 1151 | #endif |
---|
[1110] | 1152 | } else if ( strcmp(k, "-sN") == 0 ) { |
---|
[2485] | 1153 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[1110] | 1154 | if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) { |
---|
| 1155 | ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv); |
---|
| 1156 | } |
---|
| 1157 | s_opt = s_dev = s_con = NULL; |
---|
| 1158 | s_drv = "cf"; |
---|
| 1159 | s_prim = 0; |
---|
[2485] | 1160 | #else |
---|
| 1161 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
| 1162 | #endif |
---|
[2270] | 1163 | } else if ( strcmp(k, "--list-sources") == 0 ) { |
---|
[2485] | 1164 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[2270] | 1165 | print_sourcelist(); |
---|
| 1166 | return 0; |
---|
[2485] | 1167 | #else |
---|
| 1168 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
[2504] | 1169 | return 1; |
---|
[2485] | 1170 | #endif |
---|
[0] | 1171 | |
---|
[1923] | 1172 | } else if ( strcmp(k, "--light-channels") == 0 ) { |
---|
[2494] | 1173 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1923] | 1174 | light_channels = atoi(argv[++i]); |
---|
[2494] | 1175 | #else |
---|
| 1176 | ROAR_WARN("main(*): no light subsystem compiled in"); |
---|
| 1177 | #endif |
---|
[1923] | 1178 | |
---|
[2725] | 1179 | } else if ( strcmp(k, "--rds-pi") == 0 ) { |
---|
| 1180 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1181 | g_rdtcs.rds.pi = atoi(argv[++i]); |
---|
| 1182 | #else |
---|
| 1183 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
| 1184 | #endif |
---|
[2728] | 1185 | } else if ( strcmp(k, "--rds-ps") == 0 ) { |
---|
| 1186 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1187 | if ( rdtcs_rds_set_ps(argv[++i]) == -1 ) { |
---|
[2729] | 1188 | ROAR_ERR("Can not set RDS PS to '%s' (longer than 8 chars?)", argv[i]); |
---|
[2728] | 1189 | return 1; |
---|
| 1190 | } |
---|
| 1191 | #else |
---|
| 1192 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
| 1193 | #endif |
---|
| 1194 | } else if ( strcmp(k, "--rds-pty") == 0 ) { |
---|
| 1195 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1196 | if ( rdtcs_rds_set_pty(argv[++i]) == -1 ) { |
---|
[2729] | 1197 | ROAR_ERR("Can not set RDS PTY to '%s'", argv[i]); |
---|
[2728] | 1198 | return 1; |
---|
| 1199 | } |
---|
| 1200 | #else |
---|
| 1201 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
| 1202 | #endif |
---|
| 1203 | } else if ( strcmp(k, "--rds-tp") == 0 ) { |
---|
| 1204 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1205 | if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_TP, 0) == -1 ) { |
---|
| 1206 | ROAR_ERR("Can not set RDS TP flag"); |
---|
| 1207 | return 1; |
---|
| 1208 | } |
---|
| 1209 | #else |
---|
| 1210 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
| 1211 | #endif |
---|
| 1212 | } else if ( strcmp(k, "--rds-ct") == 0 ) { |
---|
| 1213 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1214 | if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_CT, 0) == -1 ) { |
---|
| 1215 | ROAR_ERR("Can not set RDS CT flag"); |
---|
| 1216 | return 1; |
---|
| 1217 | } |
---|
| 1218 | #else |
---|
| 1219 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
| 1220 | #endif |
---|
| 1221 | |
---|
[2725] | 1222 | |
---|
[1924] | 1223 | } else if ( strcmp(k, "--midi-no-console") == 0 ) { |
---|
[2487] | 1224 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
[1924] | 1225 | midi_config.init_cb = 0; |
---|
[2487] | 1226 | #else |
---|
| 1227 | // no warning here as this is the disable option |
---|
| 1228 | #endif |
---|
[2444] | 1229 | } else if ( strcmp(k, "--midi-console-enable") == 0 ) { |
---|
[2487] | 1230 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
[2444] | 1231 | midi_config.init_cb = 1; |
---|
[2487] | 1232 | #else |
---|
| 1233 | ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in"); |
---|
| 1234 | #endif |
---|
[1924] | 1235 | } else if ( strcmp(k, "--midi-console") == 0 ) { |
---|
[2487] | 1236 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
[1924] | 1237 | midi_config.console_dev = argv[++i]; |
---|
[2444] | 1238 | midi_config.init_cb = 1; |
---|
[2487] | 1239 | #else |
---|
| 1240 | ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in"); |
---|
| 1241 | #endif |
---|
[1924] | 1242 | |
---|
[2451] | 1243 | } else if ( strcmp(k, "--ssynth-enable") == 0 ) { |
---|
[2489] | 1244 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
[2451] | 1245 | ssynth_conf.enable = 1; |
---|
[2489] | 1246 | #else |
---|
| 1247 | ROAR_ERR("main(*): No support for ssynth compiled in"); |
---|
| 1248 | #endif |
---|
[2451] | 1249 | } else if ( strcmp(k, "--ssynth-disable") == 0 ) { |
---|
[2489] | 1250 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
[2451] | 1251 | ssynth_conf.enable = 0; |
---|
[2489] | 1252 | #else |
---|
| 1253 | // we can safely ignore the disable |
---|
| 1254 | #endif |
---|
[2451] | 1255 | |
---|
[0] | 1256 | } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--port") == 0 ) { |
---|
[447] | 1257 | // This is only usefull in INET not UNIX mode. |
---|
[1494] | 1258 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1259 | if ( *sock_addr == '/' ) |
---|
| 1260 | sock_addr = ROAR_DEFAULT_HOST; |
---|
[447] | 1261 | |
---|
[446] | 1262 | errno = 0; |
---|
| 1263 | if ( (port = atoi(argv[++i])) < 1 ) { |
---|
[1486] | 1264 | #ifdef ROAR_HAVE_GETSERVBYNAME |
---|
[446] | 1265 | if ( (serv = getservbyname(argv[i], "tcp")) == NULL ) { |
---|
| 1266 | ROAR_ERR("Unknown service: %s: %s", argv[i], strerror(errno)); |
---|
| 1267 | return 1; |
---|
| 1268 | } |
---|
| 1269 | // NOTE: we need to use ROAR_NET2HOST16() here even if s_port is of type int! |
---|
| 1270 | ROAR_DBG("main(*): serv = {s_name='%s', s_aliases={...}, s_port=%i, s_proto='%s'}", |
---|
| 1271 | serv->s_name, ROAR_NET2HOST16(serv->s_port), serv->s_proto); |
---|
| 1272 | port = ROAR_NET2HOST16(serv->s_port); |
---|
[1486] | 1273 | #else |
---|
| 1274 | ROAR_ERR("invalite port number: %s", argv[i]); |
---|
| 1275 | return 1; |
---|
| 1276 | #endif |
---|
[446] | 1277 | } |
---|
[1494] | 1278 | #endif |
---|
[1115] | 1279 | } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) { |
---|
[1494] | 1280 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1281 | sock_addr = argv[++i]; |
---|
| 1282 | #endif |
---|
| 1283 | |
---|
| 1284 | } else if ( strcmp(k, "--proto") == 0 ) { |
---|
| 1285 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2549] | 1286 | if ( (sock_proto = roar_str2proto(argv[++i])) == -1 ) { |
---|
[2530] | 1287 | ROAR_ERR("Unknown protocol: %s", argv[i]); |
---|
| 1288 | return 1; |
---|
| 1289 | } |
---|
[1494] | 1290 | #endif |
---|
[518] | 1291 | |
---|
[573] | 1292 | } else if ( strcmp(k, "-t") == 0 || strcmp(k, "--tcp") == 0 ) { |
---|
[1494] | 1293 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[518] | 1294 | if ( sock_type != ROAR_SOCKET_TYPE_TCP && sock_type != ROAR_SOCKET_TYPE_TCP6 ) |
---|
| 1295 | sock_type = ROAR_SOCKET_TYPE_TCP; |
---|
| 1296 | |
---|
[2530] | 1297 | if ( *sock_addr == '/' ) |
---|
| 1298 | sock_addr = ROAR_DEFAULT_HOST; |
---|
[1494] | 1299 | #endif |
---|
[518] | 1300 | |
---|
| 1301 | } else if ( strcmp(k, "-4") == 0 ) { |
---|
[1494] | 1302 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[517] | 1303 | sock_type = ROAR_SOCKET_TYPE_TCP; |
---|
[2530] | 1304 | if ( *sock_addr == '/' ) |
---|
| 1305 | sock_addr = ROAR_DEFAULT_HOST; |
---|
[1494] | 1306 | #endif |
---|
[518] | 1307 | } else if ( strcmp(k, "-6") == 0 ) { |
---|
[1494] | 1308 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[519] | 1309 | #ifdef PF_INET6 |
---|
[518] | 1310 | sock_type = ROAR_SOCKET_TYPE_TCP6; |
---|
[2530] | 1311 | if ( *sock_addr == '/' ) |
---|
| 1312 | sock_addr = ROAR_DEFAULT_HOST; |
---|
[519] | 1313 | #else |
---|
| 1314 | ROAR_ERR("No IPv6 support compiled in!"); |
---|
| 1315 | return 1; |
---|
| 1316 | #endif |
---|
[1494] | 1317 | #endif |
---|
[518] | 1318 | |
---|
[573] | 1319 | } else if ( strcmp(k, "-u") == 0 || strcmp(k, "--unix") == 0 ) { |
---|
[1494] | 1320 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[62] | 1321 | // ignore this case as it is the default behavor. |
---|
[517] | 1322 | sock_type = ROAR_SOCKET_TYPE_UNIX; |
---|
[1494] | 1323 | #endif |
---|
[518] | 1324 | |
---|
[573] | 1325 | } else if ( strcmp(k, "-n") == 0 || strcmp(k, "--decnet") == 0 ) { |
---|
[1494] | 1326 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[508] | 1327 | #ifdef ROAR_HAVE_LIBDNET |
---|
| 1328 | port = ROAR_DEFAULT_NUM; |
---|
| 1329 | strcpy(decnethost, ROAR_DEFAULT_LISTEN_OBJECT); |
---|
[2530] | 1330 | sock_addr = decnethost; |
---|
[517] | 1331 | sock_type = ROAR_SOCKET_TYPE_DECNET; |
---|
[508] | 1332 | #else |
---|
| 1333 | ROAR_ERR("No DECnet support compiled in!"); |
---|
| 1334 | return 1; |
---|
| 1335 | #endif |
---|
[1494] | 1336 | #endif |
---|
[2530] | 1337 | } else if ( strcmp(k, "--new-sock") == 0 ) { |
---|
| 1338 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 1339 | if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto) != 0 ) { |
---|
| 1340 | ROAR_ERR("Can not open listen socket!"); |
---|
| 1341 | return 1; |
---|
| 1342 | } |
---|
| 1343 | #endif |
---|
[518] | 1344 | |
---|
[1993] | 1345 | } else if ( strcmp(k, "--slp") == 0 ) { |
---|
| 1346 | #ifdef ROAR_HAVE_LIBSLP |
---|
| 1347 | reg_slp = 1; |
---|
| 1348 | #else |
---|
| 1349 | ROAR_ERR("No OpenSLP support compiled in!"); |
---|
| 1350 | return 1; |
---|
| 1351 | #endif |
---|
| 1352 | |
---|
[60] | 1353 | } else if ( strcmp(k, "-G") == 0 ) { |
---|
[444] | 1354 | sock_grp = argv[++i]; |
---|
| 1355 | } else if ( strcmp(k, "-U") == 0 ) { |
---|
| 1356 | sock_user = argv[++i]; |
---|
[0] | 1357 | |
---|
[68] | 1358 | } else if ( strcmp(k, "--no-listen") == 0 ) { |
---|
[1494] | 1359 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1360 | sock_addr = ""; |
---|
[548] | 1361 | g_terminate = 1; |
---|
[1155] | 1362 | g_no_listen = 1; |
---|
[1494] | 1363 | #endif |
---|
[68] | 1364 | } else if ( strcmp(k, "--client-fh") == 0 ) { |
---|
| 1365 | if ( clients_set_fh(clients_new(), atoi(argv[++i])) == -1 ) { |
---|
| 1366 | ROAR_ERR("main(*): Can not set client's fh"); |
---|
| 1367 | return 1; |
---|
| 1368 | } |
---|
[501] | 1369 | } else if ( strcmp(k, "--close-fh") == 0 ) { |
---|
[1486] | 1370 | #ifdef ROAR_HAVE_IO_POSIX |
---|
[501] | 1371 | close(atoi(argv[++i])); |
---|
[1486] | 1372 | #else |
---|
| 1373 | i++; |
---|
| 1374 | ROAR_WARN("can not close file handle %s (closing not supported)", argv[i]); |
---|
| 1375 | #endif |
---|
[68] | 1376 | |
---|
[920] | 1377 | } else if ( strcmp(k, "--standby") == 0 ) { |
---|
| 1378 | g_standby = 1; |
---|
| 1379 | } else if ( strcmp(k, "--auto-standby") == 0 ) { |
---|
| 1380 | g_autostandby = 1; |
---|
[0] | 1381 | } else { |
---|
| 1382 | usage(); |
---|
| 1383 | return 1; |
---|
| 1384 | } |
---|
| 1385 | |
---|
| 1386 | } |
---|
[1503] | 1387 | #endif |
---|
[0] | 1388 | |
---|
[2485] | 1389 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[1110] | 1390 | if ( s_dev != NULL ) { |
---|
| 1391 | if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) { |
---|
| 1392 | ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv); |
---|
| 1393 | } |
---|
| 1394 | } |
---|
[2485] | 1395 | #endif |
---|
[1110] | 1396 | |
---|
[1145] | 1397 | add_output(o_drv, o_dev, o_opts, o_prim, o_count); |
---|
[932] | 1398 | |
---|
[0] | 1399 | ROAR_DBG("Server config: rate=%i, bits=%i, chans=%i", sa.rate, sa.bits, sa.channels); |
---|
| 1400 | |
---|
[2500] | 1401 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[1819] | 1402 | if ( midi_init() == -1 ) { |
---|
[281] | 1403 | ROAR_ERR("Can not initialize MIDI subsystem"); |
---|
[1819] | 1404 | } |
---|
[2500] | 1405 | #endif |
---|
[1819] | 1406 | |
---|
[2489] | 1407 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
[2451] | 1408 | if ( ssynth_init() == -1 ) { |
---|
| 1409 | ROAR_ERR("Can not initialize ssynth subsystem"); |
---|
| 1410 | } |
---|
[2489] | 1411 | #endif |
---|
[2451] | 1412 | |
---|
[2494] | 1413 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1819] | 1414 | if ( light_init(light_channels) == -1 ) { |
---|
| 1415 | ROAR_ERR("Can not initialize light control subsystem"); |
---|
| 1416 | } |
---|
[2494] | 1417 | #endif |
---|
[281] | 1418 | |
---|
[2718] | 1419 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1420 | if ( rdtcs_init() == -1 ) { |
---|
| 1421 | ROAR_ERR("Can not initialize RDTCS subsystem"); |
---|
| 1422 | } |
---|
| 1423 | #endif |
---|
| 1424 | |
---|
[1494] | 1425 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1426 | if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto) != 0 ) { |
---|
| 1427 | ROAR_ERR("Can not open listen socket!"); |
---|
| 1428 | return 1; |
---|
[60] | 1429 | } |
---|
[1494] | 1430 | #endif |
---|
[60] | 1431 | |
---|
[0] | 1432 | if ( output_buffer_init(&sa) == -1 ) { |
---|
| 1433 | ROAR_ERR("Can not init output buffer!"); |
---|
| 1434 | return 1; |
---|
| 1435 | } |
---|
| 1436 | |
---|
[1145] | 1437 | if ( driver == NULL ) { |
---|
| 1438 | driver = "null"; |
---|
| 1439 | } else { |
---|
| 1440 | ROAR_WARN("Usage of old driver interface. use -o not -d!"); |
---|
| 1441 | } |
---|
| 1442 | |
---|
[0] | 1443 | if ( driver_open(&drvinst, &drvid, driver, device, &sa) == -1 ) { |
---|
| 1444 | ROAR_ERR("Can not open output driver!"); |
---|
| 1445 | return 1; |
---|
| 1446 | } |
---|
| 1447 | |
---|
[44] | 1448 | if ( samples_init() == -1 ) { |
---|
| 1449 | ROAR_ERR("Can not init samples!"); |
---|
| 1450 | return 1; |
---|
| 1451 | } |
---|
| 1452 | |
---|
| 1453 | |
---|
[1486] | 1454 | // we should handle this on microcontrollers, too. |
---|
[1753] | 1455 | #if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_TARGET_WIN32) |
---|
[0] | 1456 | signal(SIGINT, on_sig_int); |
---|
[2732] | 1457 | signal(SIGTERM, on_sig_term); |
---|
[285] | 1458 | signal(SIGCHLD, on_sig_chld); |
---|
[2112] | 1459 | signal(SIGUSR1, on_sig_usr1); |
---|
[0] | 1460 | signal(SIGPIPE, SIG_IGN); // ignore broken pipes |
---|
[1486] | 1461 | #endif |
---|
[0] | 1462 | |
---|
[275] | 1463 | if ( realtime ) { |
---|
[278] | 1464 | #ifdef DEBUG |
---|
| 1465 | ROAR_WARN("compiled with -DDEBUG but realtime is enabled: for real realtime support compiel without -DDEBUG"); |
---|
| 1466 | #endif |
---|
| 1467 | |
---|
[1486] | 1468 | #ifdef ROAR_HAVE_NICE |
---|
[275] | 1469 | errno = 0; |
---|
[276] | 1470 | nice(-5*realtime); // -5 for each --realtime |
---|
[1486] | 1471 | if ( errno ) { |
---|
| 1472 | ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno)); |
---|
| 1473 | } |
---|
| 1474 | #else |
---|
| 1475 | ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno)); |
---|
| 1476 | #endif |
---|
[277] | 1477 | /* |
---|
[276] | 1478 | #ifdef __linux__ |
---|
[277] | 1479 | if ( ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0)) == -1 ) |
---|
| 1480 | ROAR_WARN("Can not set io priority: %s", strerror(errno)); |
---|
[276] | 1481 | #endif |
---|
[277] | 1482 | */ |
---|
[275] | 1483 | } |
---|
| 1484 | |
---|
[2756] | 1485 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[444] | 1486 | if ( setids & R_SETGID ) { |
---|
[2754] | 1487 | if ( sock_grp == NULL ) { |
---|
| 1488 | ROAR_ERR("Can not set GID if no groupname is supplied"); |
---|
| 1489 | return 1; |
---|
| 1490 | } |
---|
[2584] | 1491 | if ( (grp = getgrnam(sock_grp)) == NULL ) { |
---|
| 1492 | ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno)); |
---|
| 1493 | return 1; |
---|
| 1494 | } |
---|
[444] | 1495 | if ( setgroups(0, (const gid_t *) NULL) == -1 ) { |
---|
| 1496 | ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno)); |
---|
| 1497 | } |
---|
[523] | 1498 | if ( !grp || setgid(grp->gr_gid) == -1 ) { |
---|
[444] | 1499 | ROAR_ERR("Can not set GroupID: %s", strerror(errno)); |
---|
| 1500 | } |
---|
| 1501 | } |
---|
[1486] | 1502 | #endif |
---|
[444] | 1503 | |
---|
[0] | 1504 | |
---|
[39] | 1505 | clients_set_pid(g_self_client, getpid()); |
---|
[1753] | 1506 | #ifdef ROAR_HAVE_GETUID |
---|
[440] | 1507 | clients_set_uid(g_self_client, getuid()); |
---|
[1753] | 1508 | #endif |
---|
| 1509 | #ifdef ROAR_HAVE_GETGID |
---|
[440] | 1510 | clients_set_gid(g_self_client, getgid()); |
---|
[1753] | 1511 | #endif |
---|
[39] | 1512 | clients_get(g_self_client, &self); |
---|
[37] | 1513 | |
---|
[39] | 1514 | if ( self == NULL ) { |
---|
| 1515 | ROAR_ERR("Can not get self client!"); |
---|
| 1516 | return 1; |
---|
| 1517 | } |
---|
| 1518 | |
---|
[775] | 1519 | strcpy(self->name, "RoarAudio daemon internal"); |
---|
[68] | 1520 | |
---|
[2815] | 1521 | if ( roar_nnode_free(&(self->nnode)) == -1 ) |
---|
| 1522 | return 1; |
---|
| 1523 | |
---|
| 1524 | // not fully correct but ok as workaorund |
---|
| 1525 | // so tools assume that roard runs on the same machine as |
---|
| 1526 | // they in case they use AF_UNIX: |
---|
| 1527 | if ( roar_nnode_new(&(self->nnode), ROAR_SOCKET_TYPE_UNIX) == -1 ) |
---|
| 1528 | return 1; |
---|
| 1529 | |
---|
[1486] | 1530 | #ifdef ROAR_HAVE_FORK |
---|
[775] | 1531 | if ( daemon ) { |
---|
[68] | 1532 | close(ROAR_STDIN ); |
---|
| 1533 | close(ROAR_STDOUT); |
---|
| 1534 | close(ROAR_STDERR); |
---|
[1753] | 1535 | |
---|
[68] | 1536 | if ( fork() ) |
---|
[1486] | 1537 | ROAR_U_EXIT(0); |
---|
[1753] | 1538 | |
---|
| 1539 | #ifdef ROAR_HAVE_SETSID |
---|
| 1540 | setsid(); |
---|
| 1541 | #endif |
---|
[1046] | 1542 | clients_set_pid(g_self_client, getpid()); // reset pid as it changed |
---|
[68] | 1543 | } |
---|
[1486] | 1544 | #endif |
---|
[68] | 1545 | |
---|
[2757] | 1546 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
| 1547 | // early test for UID as we need this for the pidfile and the setuid() |
---|
| 1548 | if ( sock_user != NULL ) { |
---|
| 1549 | if ( (pwd = getpwnam(sock_user)) == NULL ) { |
---|
| 1550 | ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno)); |
---|
| 1551 | return 1; |
---|
| 1552 | } |
---|
| 1553 | } |
---|
| 1554 | #endif |
---|
| 1555 | |
---|
[2104] | 1556 | #ifdef SUPPORT_PIDFILE |
---|
[2106] | 1557 | if ( pidfile != NULL ) { |
---|
| 1558 | if ( roar_vio_open_file(&pidfile_vio, pidfile, O_WRONLY|O_CREAT, 0644) == -1 ) { |
---|
| 1559 | ROAR_ERR("Can not write pidfile: %s", pidfile); |
---|
| 1560 | } else { |
---|
| 1561 | roar_vio_printf(&pidfile_vio, "%i\n", getpid()); |
---|
| 1562 | roar_vio_close(&pidfile_vio); |
---|
| 1563 | } |
---|
[2765] | 1564 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[2759] | 1565 | if ( pwd || grp ) { |
---|
| 1566 | if ( chown(pidfile, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 ) { |
---|
| 1567 | ROAR_WARN("Can not change ownership of pidfile: %s: %s", pidfile, strerror(errno)); |
---|
| 1568 | } |
---|
| 1569 | } |
---|
| 1570 | if ( chmod(pidfile, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1 ) { |
---|
| 1571 | ROAR_WARN("Can not change permissions of pidfile: %s: %s", pidfile, strerror(errno)); |
---|
| 1572 | } |
---|
[2765] | 1573 | #endif |
---|
[2104] | 1574 | } |
---|
| 1575 | #endif |
---|
| 1576 | |
---|
[1486] | 1577 | #ifdef ROAR_HAVE_CHROOT |
---|
[444] | 1578 | if (chrootdir) { |
---|
| 1579 | if ( chroot(chrootdir) == -1 ) { |
---|
| 1580 | ROAR_ERR("Can not chroot to %s: %s", chrootdir, strerror(errno)); |
---|
| 1581 | return 2; |
---|
| 1582 | } |
---|
| 1583 | if ( chdir("/") == -1 ) { |
---|
| 1584 | ROAR_ERR("Can not chdir to /: %s", strerror(errno)); |
---|
| 1585 | return 2; |
---|
| 1586 | } |
---|
| 1587 | } |
---|
[1486] | 1588 | #endif |
---|
[444] | 1589 | |
---|
[2756] | 1590 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[444] | 1591 | if ( setids & R_SETUID ) { |
---|
[2752] | 1592 | if ( sock_user == NULL ) { |
---|
| 1593 | ROAR_ERR("Can not set UID if no username is supplied"); |
---|
| 1594 | return 1; |
---|
| 1595 | } |
---|
[444] | 1596 | if ( !pwd || setuid(pwd->pw_uid) == -1 ) { |
---|
| 1597 | ROAR_ERR("Can not set UserID: %s", strerror(errno)); |
---|
| 1598 | return 3; |
---|
| 1599 | } |
---|
[1753] | 1600 | #ifdef ROAR_HAVE_GETUID |
---|
[444] | 1601 | clients_set_uid(g_self_client, getuid()); |
---|
[1753] | 1602 | #endif |
---|
[444] | 1603 | } |
---|
[1486] | 1604 | #endif |
---|
[444] | 1605 | |
---|
[1993] | 1606 | // Register with OpenSLP: |
---|
[2028] | 1607 | #ifdef ROAR_HAVE_LIBSLP |
---|
[1993] | 1608 | if ( reg_slp ) { |
---|
[2530] | 1609 | register_slp(0, sock_addr); |
---|
[1993] | 1610 | } |
---|
[2028] | 1611 | #endif |
---|
[1993] | 1612 | |
---|
[0] | 1613 | // start main loop... |
---|
[905] | 1614 | main_loop(drvid, drvinst, &sa, sysclocksync); |
---|
[0] | 1615 | |
---|
| 1616 | // clean up. |
---|
| 1617 | clean_quit_prep(); |
---|
| 1618 | driver_close(drvinst, drvid); |
---|
| 1619 | output_buffer_free(); |
---|
| 1620 | |
---|
| 1621 | return 0; |
---|
| 1622 | } |
---|
| 1623 | |
---|
[574] | 1624 | void cleanup_listen_socket (int terminate) { |
---|
[2530] | 1625 | int i; |
---|
| 1626 | |
---|
[1993] | 1627 | // Deregister from SLP: |
---|
[2028] | 1628 | #ifdef ROAR_HAVE_LIBSLP |
---|
[1993] | 1629 | register_slp(1, NULL); |
---|
[2028] | 1630 | #endif |
---|
[580] | 1631 | |
---|
[1494] | 1632 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1633 | for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) { |
---|
| 1634 | if ( g_listen_socket[i] != -1 ) { |
---|
[1486] | 1635 | #ifdef ROAR_HAVE_IO_POSIX |
---|
[2530] | 1636 | close(g_listen_socket[i]); |
---|
[1486] | 1637 | #endif // #else is useless because we are in void context. |
---|
[60] | 1638 | |
---|
[2530] | 1639 | g_listen_socket[i] = -1; |
---|
[576] | 1640 | |
---|
[1486] | 1641 | #ifdef ROAR_HAVE_UNIX |
---|
[2530] | 1642 | if ( server[i] != NULL ) |
---|
| 1643 | if ( *(server[i]) == '/' ) |
---|
| 1644 | unlink(server[i]); |
---|
[1486] | 1645 | #endif |
---|
[2530] | 1646 | } |
---|
[580] | 1647 | } |
---|
[60] | 1648 | |
---|
[1494] | 1649 | #endif |
---|
| 1650 | |
---|
[574] | 1651 | if ( terminate ) |
---|
| 1652 | g_terminate = 1; |
---|
| 1653 | } |
---|
| 1654 | |
---|
| 1655 | void clean_quit_prep (void) { |
---|
| 1656 | cleanup_listen_socket(0); |
---|
[60] | 1657 | |
---|
[2485] | 1658 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[0] | 1659 | sources_free(); |
---|
[2485] | 1660 | #endif |
---|
[0] | 1661 | streams_free(); |
---|
| 1662 | clients_free(); |
---|
[2489] | 1663 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
[2451] | 1664 | ssynth_free(); |
---|
[2489] | 1665 | #endif |
---|
[2487] | 1666 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
[282] | 1667 | midi_cb_stop(); // stop console beep |
---|
[2487] | 1668 | #endif |
---|
[2500] | 1669 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[281] | 1670 | midi_free(); |
---|
[2500] | 1671 | #endif |
---|
[2494] | 1672 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1819] | 1673 | light_free(); |
---|
[2494] | 1674 | #endif |
---|
[2718] | 1675 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1676 | rdtcs_free(); |
---|
| 1677 | #endif |
---|
[2104] | 1678 | |
---|
| 1679 | #ifdef SUPPORT_PIDFILE |
---|
| 1680 | if ( pidfile != NULL ) |
---|
| 1681 | unlink(pidfile); |
---|
| 1682 | #endif |
---|
[0] | 1683 | } |
---|
| 1684 | |
---|
| 1685 | void clean_quit (void) { |
---|
| 1686 | clean_quit_prep(); |
---|
| 1687 | // driver_close(drvinst, drvid); |
---|
| 1688 | // output_buffer_free(); |
---|
| 1689 | exit(0); |
---|
| 1690 | } |
---|
| 1691 | |
---|
| 1692 | //ll |
---|