[0] | 1 | //roard.c: |
---|
| 2 | |
---|
[668] | 3 | /* |
---|
[3358] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
[668] | 5 | * |
---|
| 6 | * This file is part of roard a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[668] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[0] | 26 | #include "roard.h" |
---|
| 27 | |
---|
[1494] | 28 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 29 | char * server[ROAR_MAX_LISTEN_SOCKETS]; |
---|
[1494] | 30 | #endif |
---|
[60] | 31 | |
---|
[2104] | 32 | #if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_FS_POSIX) |
---|
| 33 | #define SUPPORT_PIDFILE |
---|
| 34 | char * pidfile = NULL; |
---|
| 35 | #endif |
---|
| 36 | |
---|
[2530] | 37 | #if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID) |
---|
[3374] | 38 | int setids = 0; |
---|
| 39 | #endif |
---|
| 40 | |
---|
| 41 | #ifdef ROAR_HAVE_LIBX11 |
---|
| 42 | char * x11display = NULL; |
---|
[2530] | 43 | #endif |
---|
| 44 | |
---|
[1503] | 45 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 46 | void usage (void) { |
---|
| 47 | printf("Usage: roard [OPTIONS]...\n\n"); |
---|
| 48 | |
---|
[68] | 49 | printf("Misc Options:\n\n"); |
---|
| 50 | printf( |
---|
[775] | 51 | " --daemon - Bring the server into background after init\n" |
---|
[2970] | 52 | " --verbose - Be more verbose, can be used multiple times\n" |
---|
[71] | 53 | " --terminate - Terminate after last client quited\n" |
---|
[2109] | 54 | " --start - No op parameter (starting roard is default operation)\n" |
---|
[274] | 55 | " --restart - Trys to stop an old instance and start a new with new settings\n" |
---|
[2109] | 56 | " --stop - Stops a running roard (provide --pidfile!)\n" |
---|
| 57 | " --shutdown - Terminates a running roard (provide --pidfile!)\n" |
---|
[276] | 58 | " --realtime - Trys to get realtime priority,\n" |
---|
| 59 | " give multible times for being more realtime\n" |
---|
[444] | 60 | " --chroot DIR - chroots to the given dir\n" |
---|
| 61 | " --setgid - GroupID to the audio group as specified via -G\n" |
---|
| 62 | " --setuid - UserID to the audio user as specified via -U\n" |
---|
[905] | 63 | " --sysclocksync - calculate exact sample rate using the system clock\n" |
---|
[2017] | 64 | " --location LOC - Set lion readable location of server\n" |
---|
[2104] | 65 | #ifdef SUPPORT_PIDFILE |
---|
| 66 | " --pidfile PIDFILE - Write a pidfile at PIDFILE\n" |
---|
| 67 | #endif |
---|
[3688] | 68 | #ifdef ROAR_HAVE_SYSLOG |
---|
| 69 | " --log-syslog - Log Warnings, Errors, ... to syslog\n" |
---|
| 70 | #endif |
---|
[68] | 71 | ); |
---|
| 72 | |
---|
[3356] | 73 | printf("\nPlugin Options:\n\n"); |
---|
| 74 | printf( |
---|
| 75 | " --plugin-load FILE - Load plugin FILE\n" |
---|
| 76 | ); |
---|
| 77 | |
---|
[68] | 78 | printf("\nAudio Options:\n\n"); |
---|
[0] | 79 | printf( |
---|
| 80 | " -R --rate RATE - Set server rate\n" |
---|
| 81 | " -B --bits BITS - Set server bits\n" |
---|
| 82 | " -C --chans CHANNELS - Set server channels\n" |
---|
[3963] | 83 | " --aiprofile PROFILE - Use the given audio profile\n" |
---|
[0] | 84 | ); |
---|
| 85 | |
---|
[2339] | 86 | printf("\nStream Options:\n\n"); |
---|
| 87 | printf( |
---|
| 88 | " --stream-flags D=F - Set default flags for stream directions\n" |
---|
| 89 | " D is the stream direction and F is a comma seperated\n" |
---|
| 90 | " list of flags in form +flag or -flag to set or unset\n" |
---|
| 91 | " a flag as default or remove it from the default\n" |
---|
| 92 | ); |
---|
| 93 | |
---|
[1923] | 94 | printf("\nDriver Options: (obsolete, do not use, Use Ouput Options)\n\n"); |
---|
[974] | 95 | printf(" -d --driver DRV - Set the driver (default: %s)\n", ROAR_DRIVER_DEFAULT); |
---|
[0] | 96 | printf(" -D --device DEV - Set the device\n"); |
---|
| 97 | printf(" -dO OPTS - Set output options\n"); |
---|
[973] | 98 | printf(" --list-driver - List all drivers\n"); |
---|
[0] | 99 | |
---|
[932] | 100 | printf("\nOutput Options:\n\n"); |
---|
[974] | 101 | printf(" -o --odriver DRV - Set the driver, use '--list-driver' to get a list\n"); |
---|
[932] | 102 | printf(" -O --odevice DEV - Set the device\n"); |
---|
| 103 | printf(" -oO OPTS - Set output options\n"); |
---|
| 104 | printf(" -oN - Adds another output\n"); |
---|
[961] | 105 | printf(" -oP - Mark output as primary\n"); |
---|
[932] | 106 | |
---|
[2485] | 107 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[0] | 108 | printf("\nSource Options:\n\n"); |
---|
| 109 | printf(" -s --source DRV - Use DRV as input driver\n" |
---|
| 110 | " -S DEV - Use DEV as input device\n" |
---|
| 111 | " -sO OPTS - Use OPTS as input options\n" |
---|
[1512] | 112 | " -sN - Adds another source\n" |
---|
[0] | 113 | " -sP - Make souce as primary\n" |
---|
| 114 | ); |
---|
[2270] | 115 | printf(" --list-sources - List all sources\n"); |
---|
[2485] | 116 | #endif |
---|
[0] | 117 | |
---|
[280] | 118 | printf("\nCodec Filter Options:\n\n"); |
---|
| 119 | printf(" --list-cf - List all codec filter\n" |
---|
| 120 | ); |
---|
[0] | 121 | |
---|
[2500] | 122 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[1923] | 123 | printf("\nMIDI Options:\n\n"); |
---|
[1924] | 124 | printf(" --midi-no-console - Disable console based MIDI synth\n" |
---|
[2444] | 125 | " --midi-console-enable - Enables the console based MIDI synth\n" |
---|
[1924] | 126 | " --midi-console DEV - Set device for MIDI console\n" |
---|
[2489] | 127 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
[2451] | 128 | " --ssynth-enable - Enable simple software synth\n" |
---|
| 129 | " --ssynth-disable - Disable simple software synth\n" |
---|
[2489] | 130 | #endif |
---|
[1924] | 131 | ); |
---|
[2500] | 132 | #endif |
---|
[1923] | 133 | |
---|
[2494] | 134 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1923] | 135 | printf("\nLight Control Options:\n\n"); |
---|
| 136 | printf(" --light-channels NUM - Sets the number of channels for Light control (default: %i)\n", |
---|
| 137 | LIGHT_CHANNELS_DEFAULT |
---|
| 138 | ); |
---|
[2494] | 139 | #endif |
---|
[1923] | 140 | |
---|
[2725] | 141 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
[3339] | 142 | printf("\nRadio Data and Transmitter Control System Options:\n\n"); |
---|
[2725] | 143 | printf(" --rds-pi PI - Sets the RDS Programme Identification (PI)\n" |
---|
| 144 | " --rds-ps PS - Sets the RDS Programme Service Name (PS)\n" |
---|
| 145 | " --rds-pty PTY - Sets the RDS Programme Type (PTY)\n" |
---|
| 146 | " --rds-tp - Sets the RDS Traffic Programme (TP) flag\n" |
---|
| 147 | " --rds-ct - Enables sending of RDS Clock Time (CT)\n" |
---|
| 148 | ); |
---|
| 149 | #endif |
---|
| 150 | |
---|
[3374] | 151 | #ifdef ROAR_HAVE_LIBX11 |
---|
| 152 | printf("\nX11 Options:\n\n"); |
---|
| 153 | printf( |
---|
| 154 | " --x11-display DISPLAY - Set display for X11\n" |
---|
| 155 | " --display DISPLAY - Set display for X11\n" |
---|
| 156 | ); |
---|
| 157 | #endif |
---|
| 158 | |
---|
[0] | 159 | printf("\nServer Options:\n\n"); |
---|
| 160 | printf(" -t --tcp - Use TCP listen socket\n" |
---|
[3992] | 161 | #ifdef ROAR_HAVE_UNIX |
---|
[0] | 162 | " -u --unix - Use UNIX Domain listen socket (default)\n" |
---|
[3992] | 163 | #endif |
---|
[508] | 164 | #ifdef ROAR_HAVE_LIBDNET |
---|
| 165 | " -n --decnet - use DECnet listen socket\n" |
---|
| 166 | #endif |
---|
[518] | 167 | " -4 - Use IPv4 connections (implies -t)\n" |
---|
[3837] | 168 | #ifdef AF_INET6 |
---|
[518] | 169 | " -6 - Use IPv6 connections (implies -t)\n" |
---|
| 170 | #endif |
---|
| 171 | #ifdef IPV6_ADDRFORM |
---|
| 172 | " -64 - Try to downgrade sockets from IPv6 into IPv4,\n" |
---|
| 173 | " this is normaly not usefull.\n" |
---|
| 174 | #endif |
---|
[0] | 175 | " -p --port - TCP Port to bind to\n" |
---|
| 176 | " -b --bind - IP/Hostname to bind to\n" |
---|
[1115] | 177 | " --sock - Filename for UNIX Domain Socket\n" |
---|
[2530] | 178 | " --proto PROTO - Use PROTO as protocol on Socket\n" |
---|
[3252] | 179 | " --proto-dir DIR - Set direction parameter for protocol\n" |
---|
| 180 | " --proto-rate RATE - Set sample rate parameter for protocol\n" |
---|
| 181 | " --proto-bits BITS - Set bits per sample parameter for protocol\n" |
---|
| 182 | " --proto-codec E - Set codec parameter for protocol\n" |
---|
| 183 | " --proto-chans C - Set number of channels paramter for protocol\n" |
---|
[3954] | 184 | " --proto-aiprofile PROFILE\n" |
---|
| 185 | " - Sets the audio profile for socket\n" |
---|
[3956] | 186 | " --proto-profile P - Set profile for listen socket\n" |
---|
[3127] | 187 | " --list-proto - List supported protocols\n" |
---|
[3956] | 188 | " --list-profiles - List supported profiles for --proto-profile\n" |
---|
[2530] | 189 | " --new-sock - Parameters for new socket follows\n" |
---|
[1993] | 190 | #ifdef ROAR_HAVE_LIBSLP |
---|
| 191 | " --slp - Enable OpenSLP support\n" |
---|
| 192 | #endif |
---|
[3373] | 193 | #ifdef ROAR_HAVE_LIBX11 |
---|
| 194 | " --x11 - Enable X11 support\n" |
---|
| 195 | #endif |
---|
[3039] | 196 | " --jumbo-mtu MTU - Sets the MTU for Jumbo Packets\n" |
---|
[450] | 197 | " -G GROUP - Sets the group for the UNIX Domain Socket, (default: %s)\n" |
---|
[2737] | 198 | " You need the permissions to change the GID\n" |
---|
[444] | 199 | " -U USER - Sets the user for the UNIX Domain Socket, (default: do not set)\n" |
---|
[2737] | 200 | " You need the permissions to change the UID (normaly only root has)\n" |
---|
[548] | 201 | " --no-listen - Do not listen for new clients\n" |
---|
| 202 | " (only usefull for relaing, impleys --terminate)\n" |
---|
[274] | 203 | " --client-fh - Comunicate with a client over this handle\n" |
---|
[501] | 204 | " (only usefull for relaing)\n" |
---|
[920] | 205 | " --close-fh - Closes the given fh\n" |
---|
| 206 | " --standby - Start in standby state\n" |
---|
| 207 | " --auto-standby - Automatical goes into standby if there are no streams\n", |
---|
[2755] | 208 | #ifdef ROAR_DEFAULT_SOCKGRP |
---|
[450] | 209 | ROAR_DEFAULT_SOCKGRP |
---|
[2755] | 210 | #else |
---|
| 211 | "(none)" |
---|
| 212 | #endif |
---|
[0] | 213 | ); |
---|
| 214 | // printf("\n Options:\n\n"); |
---|
| 215 | printf("\n"); |
---|
| 216 | } |
---|
[3127] | 217 | |
---|
| 218 | static void list_proto (void) { |
---|
| 219 | printf(" Protocol Flag Subsys - Description\n"); |
---|
| 220 | printf("------------------------------------------------------\n"); |
---|
| 221 | printf(" roar WM LRX - RoarAudio native protocol\n"); |
---|
| 222 | #if !defined(ROAR_WITHOUT_DCOMP_EMUL_ESD) && defined(ROAR_HAVE_H_ESD) |
---|
| 223 | printf(" esd W - EsounD emulation\n"); |
---|
| 224 | #endif |
---|
[3603] | 225 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE |
---|
[3257] | 226 | printf(" simple WM LRX - PulseAudio simple protocol\n"); |
---|
[3597] | 227 | #endif |
---|
[3684] | 228 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND |
---|
| 229 | printf(" rsound W - RSound emulation\n"); |
---|
| 230 | #endif |
---|
[3981] | 231 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY |
---|
| 232 | printf(" rplay W - RPlay emulation\n"); |
---|
| 233 | #endif |
---|
[3127] | 234 | } |
---|
| 235 | |
---|
[1503] | 236 | #endif |
---|
[0] | 237 | |
---|
[2109] | 238 | int restart_server (char * server, int terminate) { |
---|
[579] | 239 | struct roar_connection con; |
---|
[2111] | 240 | #ifdef ROAR_HAVE_KILL |
---|
| 241 | char buf[80]; |
---|
| 242 | ssize_t l; |
---|
| 243 | struct roar_vio_calls fh; |
---|
| 244 | pid_t pid; |
---|
| 245 | int ok; |
---|
| 246 | |
---|
| 247 | if ( pidfile != NULL ) { |
---|
| 248 | if ( roar_vio_open_file(&fh, pidfile, O_RDONLY, 0644) == -1 ) { |
---|
| 249 | ROAR_WARN("restart_server(*): Can not read pidfile: %s", pidfile); |
---|
| 250 | } else { |
---|
| 251 | l = roar_vio_read(&fh, buf, 80); |
---|
| 252 | roar_vio_close(&fh); |
---|
| 253 | if ( l > 0 ) { |
---|
| 254 | buf[l-1] = 0; |
---|
| 255 | buf[79] = 0; |
---|
| 256 | pid = atoi(buf); |
---|
| 257 | if ( terminate ) { |
---|
[2113] | 258 | ok = kill(pid, SIGUSR1); |
---|
[2111] | 259 | } else { |
---|
| 260 | ok = kill(pid, SIGINT); |
---|
| 261 | } |
---|
| 262 | if ( ok == 0 ) { |
---|
| 263 | return 0; |
---|
| 264 | } else { |
---|
| 265 | ROAR_WARN("restart_server(*): Can not kill roard by pidfile"); |
---|
| 266 | } |
---|
| 267 | } else { |
---|
| 268 | ROAR_WARN("restart_server(*): Can not find a PID in the pidfile"); |
---|
| 269 | } |
---|
| 270 | } |
---|
| 271 | } |
---|
| 272 | #endif |
---|
[2109] | 273 | |
---|
[579] | 274 | if ( roar_connect(&con, server) == -1 ) { |
---|
| 275 | return -1; |
---|
| 276 | } |
---|
| 277 | |
---|
[2109] | 278 | if ( roar_terminate(&con, terminate) == -1 ) { |
---|
[579] | 279 | return -1; |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | return roar_disconnect(&con); |
---|
| 283 | } |
---|
| 284 | |
---|
[444] | 285 | #define R_SETUID 1 |
---|
| 286 | #define R_SETGID 2 |
---|
| 287 | |
---|
[1609] | 288 | int init_config (void) { |
---|
| 289 | int i; |
---|
| 290 | |
---|
| 291 | memset(g_config, 0, sizeof(struct roard_config)); |
---|
| 292 | |
---|
| 293 | for (i = 0; i < ROAR_DIR_DIRIDS; i++) { |
---|
| 294 | g_config->streams[i].mixer_channels = 1; |
---|
| 295 | g_config->streams[i].mixer.rpg_mul = 1; |
---|
| 296 | g_config->streams[i].mixer.rpg_div = 1; |
---|
| 297 | g_config->streams[i].mixer.scale = 65535; |
---|
| 298 | g_config->streams[i].mixer.mixer[0] = g_config->streams[i].mixer.scale; |
---|
| 299 | } |
---|
| 300 | |
---|
[2291] | 301 | g_config->streams[ROAR_DIR_PLAY ].flags = ROAR_FLAG_META; |
---|
[2413] | 302 | g_config->streams[ROAR_DIR_OUTPUT ].flags = ROAR_FLAG_PASSMIXER; |
---|
[2264] | 303 | g_config->streams[ROAR_DIR_FILTER ].flags = ROAR_FLAG_SYNC; |
---|
[1899] | 304 | g_config->streams[ROAR_DIR_MIDI_OUT].flags = ROAR_FLAG_SYNC; |
---|
[2160] | 305 | g_config->streams[ROAR_DIR_BIDIR ].flags = ROAR_FLAG_ANTIECHO; |
---|
[1899] | 306 | |
---|
[2017] | 307 | g_config->location = "***default***"; |
---|
| 308 | |
---|
[1609] | 309 | return 0; |
---|
| 310 | } |
---|
| 311 | |
---|
[2530] | 312 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 313 | int init_listening (void) { |
---|
| 314 | int i; |
---|
| 315 | |
---|
[3128] | 316 | memset(g_listen, 0, sizeof(g_listen)); |
---|
| 317 | |
---|
[2530] | 318 | for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) { |
---|
[3128] | 319 | g_listen[i].proto = ROAR_PROTO_ROARAUDIO; |
---|
[2530] | 320 | server[i] = NULL; |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | return 0; |
---|
| 324 | } |
---|
| 325 | |
---|
[3731] | 326 | int get_listen(struct roard_listen ** sock, char *** sockname) { |
---|
[3730] | 327 | int i; |
---|
| 328 | |
---|
| 329 | if ( sock == NULL ) |
---|
| 330 | return -1; |
---|
| 331 | |
---|
| 332 | for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) { |
---|
[3802] | 333 | if ( ! g_listen[i].used ) { |
---|
[3730] | 334 | server[i] = NULL; |
---|
[3731] | 335 | *sock = &(g_listen[i]); |
---|
[3730] | 336 | |
---|
[3733] | 337 | if ( sockname != NULL ) |
---|
[3730] | 338 | *sockname = &(server[i]); |
---|
[3733] | 339 | |
---|
| 340 | return 0; |
---|
[3730] | 341 | } |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | return -1; |
---|
| 345 | } |
---|
| 346 | |
---|
[3956] | 347 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 348 | static struct _listen_profile { |
---|
| 349 | const char * name; |
---|
| 350 | int type; |
---|
| 351 | int port; |
---|
| 352 | const char * sockaddr; |
---|
| 353 | int proto; |
---|
| 354 | int dir; |
---|
| 355 | const char * aiprofile; |
---|
| 356 | const char * desc; |
---|
| 357 | } _g_listen_profiles[] = { |
---|
| 358 | // TODO: convert port numbers into consts! |
---|
| 359 | |
---|
| 360 | // RoarAudio: |
---|
[3992] | 361 | #ifdef ROAR_HAVE_UNIX |
---|
[3959] | 362 | {"roar-usock", ROAR_SOCKET_TYPE_UNIX, 0, "~/.roar", ROAR_PROTO_ROARAUDIO, -1, NULL, NULL}, |
---|
[3956] | 363 | {"roar-gsock", ROAR_SOCKET_TYPE_UNIX, 0, "/tmp/roar", ROAR_PROTO_ROARAUDIO, -1, NULL, NULL}, |
---|
[3992] | 364 | #endif |
---|
| 365 | #ifdef ROAR_HAVE_IPV4 |
---|
[3956] | 366 | {"roar-tcp", ROAR_SOCKET_TYPE_TCP, ROAR_DEFAULT_PORT, "localhost", ROAR_PROTO_ROARAUDIO, -1, NULL, NULL}, |
---|
| 367 | {"roar-tcp-pub", ROAR_SOCKET_TYPE_TCP, ROAR_DEFAULT_PORT, "0.0.0.0", ROAR_PROTO_ROARAUDIO, -1, NULL, NULL}, |
---|
[3992] | 368 | #endif |
---|
| 369 | #ifdef ROAR_HAVE_LIBDNET |
---|
[3956] | 370 | {"roar-dnet", ROAR_SOCKET_TYPE_DECNET, 0, "::roar", ROAR_PROTO_ROARAUDIO, -1, NULL, NULL}, |
---|
[3992] | 371 | #endif |
---|
| 372 | #ifdef ROAR_HAVE_UNIX |
---|
[3987] | 373 | {"roar-abstract", ROAR_SOCKET_TYPE_UNIX, 0, "+abstract", ROAR_PROTO_ROARAUDIO, -1, NULL, NULL}, |
---|
[3992] | 374 | #endif |
---|
[3956] | 375 | |
---|
| 376 | // EsounD: |
---|
[3992] | 377 | #if !defined(ROAR_WITHOUT_DCOMP_EMUL_ESD) && defined(ROAR_HAVE_H_ESD) |
---|
| 378 | #ifdef ROAR_HAVE_UNIX |
---|
[3956] | 379 | {"esd-unix", ROAR_SOCKET_TYPE_UNIX, 0, "/tmp/.esd/socket", ROAR_PROTO_ESOUND, -1, NULL, NULL}, |
---|
[3992] | 380 | #endif |
---|
| 381 | #ifdef ROAR_HAVE_IPV4 |
---|
[3956] | 382 | {"esd-tcp", ROAR_SOCKET_TYPE_TCP, 16001, "localhost", ROAR_PROTO_ESOUND, -1, NULL, NULL}, |
---|
| 383 | {"esd-tcp-pub", ROAR_SOCKET_TYPE_TCP, 16001, "0.0.0.0", ROAR_PROTO_ESOUND, -1, NULL, NULL}, |
---|
[3992] | 384 | #endif |
---|
| 385 | #endif |
---|
[3956] | 386 | |
---|
| 387 | // RSound: |
---|
[3992] | 388 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND |
---|
| 389 | #ifdef ROAR_HAVE_UNIX |
---|
[3966] | 390 | {"rsound-unix", ROAR_SOCKET_TYPE_UNIX, 0, "/tmp/rsound", ROAR_PROTO_RSOUND, -1, NULL, NULL}, |
---|
[3992] | 391 | #endif |
---|
| 392 | #ifdef ROAR_HAVE_IPV4 |
---|
[3956] | 393 | {"rsound-tcp", ROAR_SOCKET_TYPE_TCP, 12345, "localhost", ROAR_PROTO_RSOUND, -1, NULL, NULL}, |
---|
| 394 | {"rsound-tcp-pub", ROAR_SOCKET_TYPE_TCP, 12345, "0.0.0.0", ROAR_PROTO_RSOUND, -1, NULL, NULL}, |
---|
[3992] | 395 | #endif |
---|
| 396 | #ifdef ROAR_HAVE_LIBDNET |
---|
[3956] | 397 | {"rsound-dnet", ROAR_SOCKET_TYPE_DECNET, 0, "::rsound", ROAR_PROTO_RSOUND, -1, NULL, NULL}, |
---|
[3992] | 398 | #endif |
---|
| 399 | #endif |
---|
[3957] | 400 | |
---|
| 401 | // PulseAudio Simple: |
---|
[3992] | 402 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE |
---|
| 403 | #ifdef ROAR_HAVE_IPV4 |
---|
[3957] | 404 | {"pas-play-tcp", ROAR_SOCKET_TYPE_TCP, 4712, "0.0.0.0", ROAR_PROTO_SIMPLE, |
---|
| 405 | ROAR_DIR_PLAY, "default", |
---|
| 406 | NULL}, |
---|
| 407 | {"pas-mon-tcp", ROAR_SOCKET_TYPE_TCP, 4712, "0.0.0.0", ROAR_PROTO_SIMPLE, |
---|
| 408 | ROAR_DIR_MONITOR, "default", |
---|
| 409 | NULL}, |
---|
[3992] | 410 | #endif |
---|
| 411 | #endif |
---|
[3987] | 412 | |
---|
| 413 | // RPlay: |
---|
[3992] | 414 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY |
---|
| 415 | #ifdef ROAR_HAVE_IPV4 |
---|
[3987] | 416 | {"rplay-tcp", ROAR_SOCKET_TYPE_TCP, 5556, "localhost", ROAR_PROTO_RPLAY, -1, NULL, NULL}, |
---|
| 417 | {"rplay-tcp-pub", ROAR_SOCKET_TYPE_TCP, 5556, "0.0.0.0", ROAR_PROTO_RPLAY, -1, NULL, NULL}, |
---|
[3992] | 418 | #endif |
---|
| 419 | #endif |
---|
[3987] | 420 | |
---|
| 421 | // End of List: |
---|
[3956] | 422 | {NULL, -1, -1, NULL, -1, -1, NULL, NULL} |
---|
| 423 | }; |
---|
| 424 | |
---|
| 425 | void listen_listen_profiles (void) { |
---|
| 426 | struct _listen_profile * p; |
---|
| 427 | char * type; |
---|
| 428 | int i; |
---|
[3987] | 429 | char port[8]; |
---|
[3956] | 430 | |
---|
[3990] | 431 | printf("Name Type Address Port Protocol Dir Audio Profile - Description\n"); |
---|
[3956] | 432 | printf("------------------------------------------------------------------------------------------------\n"); |
---|
| 433 | //roar-tcp-pub 0.0.0.0 16002 RoarAudio unknown (null) - (null) |
---|
| 434 | |
---|
| 435 | for (i = 0; (p = &(_g_listen_profiles[i]))->name != NULL; i++) { |
---|
| 436 | switch (p->type) { |
---|
| 437 | case ROAR_SOCKET_TYPE_UNIX: type = "UNIX"; break; |
---|
| 438 | case ROAR_SOCKET_TYPE_TCP: type = "TCP"; break; |
---|
| 439 | case ROAR_SOCKET_TYPE_DECNET: type = "DECnet"; break; |
---|
| 440 | default: |
---|
| 441 | type = "unknown"; |
---|
| 442 | break; |
---|
| 443 | } |
---|
[3987] | 444 | |
---|
| 445 | if ( p->port ) { |
---|
| 446 | sprintf(port, "%i", p->port); |
---|
| 447 | } else { |
---|
| 448 | strcpy(port, "(none)"); |
---|
| 449 | } |
---|
| 450 | |
---|
| 451 | printf("%-14s %-7s %-16s %-7s %-9s %-10s %-13s - %s\n", |
---|
[3956] | 452 | p->name, |
---|
| 453 | type, |
---|
[3987] | 454 | p->sockaddr, port, |
---|
[3956] | 455 | roar_proto2str(p->proto), |
---|
[3957] | 456 | p->dir == -1 ? "(none)" : roar_dir2str(p->dir), p->aiprofile == NULL ? "(none)" : p->aiprofile, |
---|
[3956] | 457 | p->desc == NULL ? "" : p->desc); |
---|
| 458 | } |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | int get_listen_profile (const char * name, |
---|
| 462 | int * port, char ** sockaddr, int * type, |
---|
| 463 | int * proto, |
---|
| 464 | int * dir, struct roar_audio_info * info) { |
---|
| 465 | static char buf[1024]; |
---|
| 466 | struct _listen_profile * p; |
---|
| 467 | int i; |
---|
| 468 | |
---|
| 469 | for (i = 0; (p = &(_g_listen_profiles[i]))->name != NULL; i++) { |
---|
| 470 | if ( !strcasecmp(p->name, name) ) { |
---|
| 471 | *port = p->port; |
---|
| 472 | |
---|
[3959] | 473 | if ( p->type == ROAR_SOCKET_TYPE_UNIX && p->sockaddr[0] != '+' ) { |
---|
| 474 | roar_env_render_path_r(buf, sizeof(buf), p->sockaddr); |
---|
| 475 | } else { |
---|
| 476 | strncpy(buf, p->sockaddr, sizeof(buf)); |
---|
| 477 | } |
---|
[3956] | 478 | *sockaddr = buf; |
---|
| 479 | |
---|
| 480 | *proto = p->proto; |
---|
| 481 | *dir = p->dir; |
---|
| 482 | |
---|
| 483 | if ( p->aiprofile != NULL ) { |
---|
| 484 | if ( roar_profile2info(info, p->aiprofile) == -1 ) { |
---|
| 485 | ROAR_ERR("Unknown audio profile: %s", p->aiprofile); |
---|
| 486 | return -1; |
---|
| 487 | } |
---|
| 488 | } |
---|
| 489 | return 0; |
---|
| 490 | } |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | return -1; |
---|
| 494 | } |
---|
| 495 | #endif |
---|
| 496 | |
---|
[3252] | 497 | int add_listen (char * addr, int port, int sock_type, char * user, char * group, int proto, int dir, struct roar_audio_info * info) { |
---|
[2530] | 498 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
| 499 | struct group * grp = NULL; |
---|
| 500 | #endif |
---|
| 501 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
| 502 | struct passwd * pwd = NULL; |
---|
| 503 | #endif |
---|
| 504 | #ifdef ROAR_HAVE_UNIX |
---|
| 505 | char * env_roar_proxy_backup; |
---|
| 506 | #endif |
---|
| 507 | int sockid = -1; |
---|
[3907] | 508 | #ifdef ROAR_HAVE_UNIX |
---|
[2530] | 509 | int sock; |
---|
[3907] | 510 | #endif |
---|
[2530] | 511 | int i; |
---|
| 512 | |
---|
| 513 | if ( *addr != 0 ) { |
---|
| 514 | for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) { |
---|
[3802] | 515 | if ( ! g_listen[i].used ) { |
---|
[2530] | 516 | sockid = i; |
---|
| 517 | break; |
---|
| 518 | } |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | if ( sockid == -1 ) |
---|
| 522 | return -1; |
---|
| 523 | |
---|
[3128] | 524 | g_listen[sockid].proto = proto; |
---|
[2530] | 525 | |
---|
| 526 | ROAR_DBG("add_listen(*): proto=0x%.4x", proto); |
---|
| 527 | |
---|
[3802] | 528 | if ( roar_vio_open_socket_listen(&(g_listen[sockid].sock), sock_type, addr, port) == -1 ) { |
---|
[2530] | 529 | #ifdef ROAR_HAVE_UNIX |
---|
| 530 | if ( *addr == '/' ) { |
---|
| 531 | if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) { |
---|
| 532 | env_roar_proxy_backup = strdup(env_roar_proxy_backup); |
---|
| 533 | unsetenv("ROAR_PROXY"); |
---|
| 534 | } |
---|
| 535 | if ( (sock = roar_socket_connect(addr, port)) != -1 ) { |
---|
| 536 | close(sock); |
---|
[3040] | 537 | ROAR_ERR("Can not open listen socket: Socket allready in use"); |
---|
[2530] | 538 | return 1; |
---|
| 539 | } else { |
---|
| 540 | unlink(addr); |
---|
[3802] | 541 | if ( roar_vio_open_socket_listen(&(g_listen[sockid].sock), sock_type, addr, port) == -1 ) { |
---|
[3040] | 542 | ROAR_ERR("Can not open listen socket: %s", strerror(errno)); |
---|
[2530] | 543 | return 1; |
---|
| 544 | } |
---|
| 545 | } |
---|
| 546 | if ( env_roar_proxy_backup != NULL ) { |
---|
| 547 | setenv("ROAR_PROXY", env_roar_proxy_backup, 0); |
---|
| 548 | free(env_roar_proxy_backup); |
---|
| 549 | } |
---|
| 550 | #else |
---|
| 551 | if (0) { // noop |
---|
| 552 | #endif |
---|
| 553 | } else { |
---|
[3041] | 554 | ROAR_ERR("Can not open listen socket: %s", strerror(errno)); |
---|
[2530] | 555 | return 1; |
---|
| 556 | } |
---|
| 557 | } |
---|
| 558 | |
---|
| 559 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[2753] | 560 | if ( group != NULL ) { |
---|
| 561 | if ( (grp = getgrnam(group)) == NULL ) { |
---|
| 562 | ROAR_ERR("Can not get GID for group %s: %s", group, strerror(errno)); |
---|
| 563 | } |
---|
[2530] | 564 | } |
---|
| 565 | #endif |
---|
| 566 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[2752] | 567 | if ( user ) { |
---|
[2530] | 568 | if ( (pwd = getpwnam(user)) == NULL ) { |
---|
| 569 | ROAR_ERR("Can not get UID for user %s: %s", user, strerror(errno)); |
---|
| 570 | } |
---|
| 571 | } |
---|
| 572 | #endif |
---|
| 573 | |
---|
| 574 | #if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_UNIX) |
---|
| 575 | if ( *addr == '/' ) { |
---|
[2753] | 576 | if ( grp || pwd ) { |
---|
| 577 | if ( chown(addr, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 ) |
---|
[2530] | 578 | return 1; |
---|
[2753] | 579 | } |
---|
[2530] | 580 | #ifdef ROAR_HAVE_GETUID |
---|
[2753] | 581 | if ( grp ) { |
---|
[2530] | 582 | if ( getuid() == 0 ) |
---|
| 583 | if ( chmod(addr, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1 ) |
---|
| 584 | return 1; |
---|
[2753] | 585 | } |
---|
[2530] | 586 | #endif |
---|
| 587 | } |
---|
| 588 | #endif |
---|
| 589 | } |
---|
| 590 | |
---|
[2736] | 591 | // in case we opened the listening socket correctly. |
---|
[3256] | 592 | if ( dir == -1 ) |
---|
| 593 | dir = ROAR_DIR_PLAY; |
---|
| 594 | |
---|
[3252] | 595 | g_listen[sockid].inst.stpl.dir = dir; |
---|
| 596 | memcpy(&(g_listen[sockid].inst.stpl.info), info, sizeof(struct roar_audio_info)); |
---|
[3256] | 597 | |
---|
| 598 | switch (dir) { |
---|
| 599 | case ROAR_DIR_PLAY: |
---|
| 600 | case ROAR_DIR_RECORD: |
---|
| 601 | case ROAR_DIR_MONITOR: |
---|
| 602 | case ROAR_DIR_FILTER: |
---|
| 603 | case ROAR_DIR_BIDIR: |
---|
| 604 | if ( !g_listen[sockid].inst.stpl.info.rate ) |
---|
| 605 | g_listen[sockid].inst.stpl.info.rate = g_sa->rate; |
---|
| 606 | |
---|
| 607 | if ( !g_listen[sockid].inst.stpl.info.bits ) |
---|
| 608 | g_listen[sockid].inst.stpl.info.bits = g_sa->bits; |
---|
| 609 | |
---|
| 610 | if ( !g_listen[sockid].inst.stpl.info.channels ) |
---|
| 611 | g_listen[sockid].inst.stpl.info.channels = g_sa->channels; |
---|
| 612 | |
---|
| 613 | if ( !g_listen[sockid].inst.stpl.info.codec ) |
---|
| 614 | g_listen[sockid].inst.stpl.info.codec = g_sa->codec; |
---|
| 615 | break; |
---|
| 616 | } |
---|
| 617 | |
---|
[3802] | 618 | g_listen[sockid].used = 1; |
---|
| 619 | server[sockid] = addr; |
---|
| 620 | |
---|
[2530] | 621 | return 0; |
---|
| 622 | } |
---|
| 623 | #endif |
---|
| 624 | |
---|
[2339] | 625 | int update_stream_flags (char * str) { |
---|
| 626 | int dir; |
---|
| 627 | char * flags; |
---|
| 628 | char * k; |
---|
| 629 | int op; |
---|
| 630 | int flag; |
---|
| 631 | |
---|
| 632 | if ( (flags = strstr(str, "=")) == NULL ) |
---|
| 633 | return -1; |
---|
| 634 | |
---|
| 635 | *flags = 0; |
---|
| 636 | flags++; |
---|
| 637 | |
---|
| 638 | if ( (dir = roar_str2dir(str)) == -1 ) |
---|
| 639 | return -1; |
---|
| 640 | |
---|
| 641 | while (flags != NULL) { |
---|
| 642 | k = flags; |
---|
| 643 | flags = strstr(flags, ","); |
---|
| 644 | |
---|
| 645 | if ( flags != NULL ) |
---|
| 646 | *(flags++) = 0; |
---|
| 647 | |
---|
| 648 | switch (*k) { |
---|
[2340] | 649 | case '+': k++; op = ROAR_SET_FLAG; break; |
---|
| 650 | case '-': k++; op = ROAR_RESET_FLAG; break; |
---|
[2339] | 651 | default: |
---|
[2340] | 652 | op = ROAR_SET_FLAG; |
---|
[2339] | 653 | } |
---|
| 654 | |
---|
| 655 | flag = 0; |
---|
| 656 | |
---|
| 657 | if ( !strcmp(k, "sync") ) { |
---|
| 658 | flag = ROAR_FLAG_SYNC; |
---|
| 659 | } else if ( !strcmp(k, "meta") ) { |
---|
| 660 | flag = ROAR_FLAG_META; |
---|
| 661 | } else if ( !strcmp(k, "cleanmeta") ) { |
---|
| 662 | flag = ROAR_FLAG_CLEANMETA; |
---|
| 663 | } else if ( !strcmp(k, "pause") ) { |
---|
| 664 | flag = ROAR_FLAG_PAUSE; |
---|
| 665 | } else if ( !strcmp(k, "mute") ) { |
---|
| 666 | flag = ROAR_FLAG_MUTE; |
---|
| 667 | } else if ( !strcmp(k, "antiecho") ) { |
---|
| 668 | flag = ROAR_FLAG_ANTIECHO; |
---|
[2413] | 669 | } else if ( !strcmp(k, "passmixer") ) { |
---|
| 670 | flag = ROAR_FLAG_PASSMIXER; |
---|
[2339] | 671 | } else { |
---|
| 672 | return -1; |
---|
| 673 | } |
---|
| 674 | |
---|
| 675 | g_config->streams[dir].flags |= flag; |
---|
| 676 | |
---|
[2340] | 677 | if ( op == ROAR_RESET_FLAG ) |
---|
[2339] | 678 | g_config->streams[dir].flags -= flag; |
---|
| 679 | } |
---|
| 680 | |
---|
| 681 | return 0; |
---|
| 682 | } |
---|
| 683 | |
---|
[1145] | 684 | int add_output (char * drv, char * dev, char * opts, int prim, int count) { |
---|
[933] | 685 | int stream; |
---|
| 686 | struct roar_stream * s; |
---|
| 687 | struct roar_stream_server * ss; |
---|
[938] | 688 | char * k, * v; |
---|
[1208] | 689 | #ifdef ROAR_DRIVER_CODEC |
---|
| 690 | char * to_free = NULL; |
---|
| 691 | #endif |
---|
[1926] | 692 | int sync = 0, f_mmap = 0; |
---|
[1522] | 693 | int32_t blocks = -1, blocksize = -1; |
---|
[1920] | 694 | int dir = ROAR_DIR_OUTPUT; |
---|
[1991] | 695 | int error = 0; |
---|
| 696 | // DMX: |
---|
| 697 | int32_t channel = -1; |
---|
| 698 | int32_t universe = -1; |
---|
| 699 | uint16_t tu16; |
---|
[2085] | 700 | float q = -32e6; |
---|
[933] | 701 | |
---|
[938] | 702 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
[933] | 703 | |
---|
[1145] | 704 | if ( drv == NULL && count == 0 ) { |
---|
| 705 | drv = ROAR_DRIVER_DEFAULT; |
---|
| 706 | prim = 1; |
---|
| 707 | sync = 1; |
---|
[1208] | 708 | |
---|
| 709 | #ifdef ROAR_DRIVER_CODEC |
---|
| 710 | if ( opts == NULL ) { |
---|
| 711 | opts = to_free = strdup("codec=" ROAR_DRIVER_CODEC); |
---|
| 712 | } |
---|
| 713 | #endif |
---|
[1145] | 714 | } |
---|
| 715 | |
---|
[1227] | 716 | if ( opts == NULL && count == 0 ) { |
---|
| 717 | sync = 1; |
---|
| 718 | prim = 1; // if ( prim == 0 ) prim = 1; -> prim allways = 1 |
---|
| 719 | } |
---|
| 720 | |
---|
[2785] | 721 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
| 722 | |
---|
[933] | 723 | if ( (stream = streams_new()) == -1 ) { |
---|
[938] | 724 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts); |
---|
[982] | 725 | if ( prim ) alive = 0; |
---|
[933] | 726 | return -1; |
---|
| 727 | } |
---|
| 728 | |
---|
[2785] | 729 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
| 730 | |
---|
[933] | 731 | streams_get(stream, &ss); |
---|
| 732 | s = ROAR_STREAM(ss); |
---|
| 733 | |
---|
[2785] | 734 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
| 735 | |
---|
[2511] | 736 | memset(&(s->info), 0xFF, sizeof(struct roar_audio_info)); // set everything to -1 |
---|
[933] | 737 | |
---|
| 738 | s->pos_rel_id = -1; |
---|
| 739 | // s->info.codec = codec; |
---|
| 740 | |
---|
[2785] | 741 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
| 742 | |
---|
[2788] | 743 | if ( opts == NULL ) { |
---|
| 744 | k = NULL; |
---|
| 745 | } else { |
---|
| 746 | k = strtok(opts, ","); |
---|
| 747 | } |
---|
[2786] | 748 | |
---|
| 749 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s'): initial k='%s'(%p)", drv, dev, opts, k, k); |
---|
| 750 | |
---|
[938] | 751 | while (k != NULL) { |
---|
| 752 | // ROAR_WARN("add_output(*): opts: %s", k); |
---|
| 753 | |
---|
| 754 | if ( (v = strstr(k, "=")) != NULL ) { |
---|
| 755 | *v++ = 0; |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | ROAR_DBG("add_output(*): opts: k='%s', v='%s'", k, v); |
---|
| 759 | if ( strcmp(k, "rate") == 0 ) { |
---|
| 760 | s->info.rate = atoi(v); |
---|
| 761 | } else if ( strcmp(k, "channels") == 0 ) { |
---|
| 762 | s->info.channels = atoi(v); |
---|
| 763 | } else if ( strcmp(k, "bits") == 0 ) { |
---|
| 764 | s->info.bits = atoi(v); |
---|
| 765 | } else if ( strcmp(k, "codec") == 0 ) { |
---|
[2511] | 766 | if ( (s->info.codec = roar_str2codec(v)) == -1 ) { |
---|
[938] | 767 | ROAR_ERR("add_output(*): unknown codec '%s'", v); |
---|
[1991] | 768 | error++; |
---|
[938] | 769 | } |
---|
[2085] | 770 | } else if ( strcmp(k, "q") == 0 ) { |
---|
| 771 | q = atof(v); |
---|
[1221] | 772 | } else if ( strcmp(k, "blocks") == 0 ) { |
---|
| 773 | blocks = atoi(v); |
---|
[1522] | 774 | } else if ( strcmp(k, "blocksize") == 0 ) { |
---|
| 775 | blocksize = atoi(v); |
---|
[1926] | 776 | } else if ( strcmp(k, "mmap") == 0 ) { |
---|
| 777 | f_mmap = 1; |
---|
[1919] | 778 | } else if ( strcmp(k, "subsystem") == 0 ) { |
---|
| 779 | if ( !strcasecmp(v, "wave") || !strcasecmp(v, "waveform") ) { |
---|
[1920] | 780 | dir = ROAR_DIR_OUTPUT; |
---|
[2494] | 781 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[1919] | 782 | } else if ( !strcasecmp(v, "midi") ) { |
---|
| 783 | dir = ROAR_DIR_MIDI_OUT; |
---|
[2494] | 784 | #endif |
---|
| 785 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1919] | 786 | } else if ( !strcasecmp(v, "light") ) { |
---|
| 787 | dir = ROAR_DIR_LIGHT_OUT; |
---|
[2494] | 788 | #endif |
---|
| 789 | #ifndef ROAR_WITHOUT_DCOMP_RAW |
---|
[2234] | 790 | } else if ( !strcasecmp(v, "raw") ) { |
---|
| 791 | dir = ROAR_DIR_RAW_OUT; |
---|
[2494] | 792 | #endif |
---|
[2681] | 793 | } else if ( !strcasecmp(v, "complex") ) { |
---|
| 794 | dir = ROAR_DIR_COMPLEX_OUT; |
---|
[1919] | 795 | } else { |
---|
[2494] | 796 | ROAR_ERR("add_output(*): unknown/unsupported subsystem '%s'", k); |
---|
[1991] | 797 | error++; |
---|
| 798 | } |
---|
| 799 | // DMX: |
---|
| 800 | } else if ( strcmp(k, "channel") == 0 ) { |
---|
| 801 | channel = atoi(v); |
---|
| 802 | if ( channel < 0 || channel > 65535 ) { |
---|
| 803 | ROAR_ERR("add_output(*): Invalide channel (not within 0..65535): %i", channel); |
---|
| 804 | channel = -1; |
---|
| 805 | error++; |
---|
[1919] | 806 | } |
---|
[1991] | 807 | } else if ( strcmp(k, "universe") == 0 ) { |
---|
| 808 | universe = atoi(v); |
---|
| 809 | if ( universe < 0 || universe > 255 ) { |
---|
| 810 | ROAR_ERR("add_output(*): Invalide universe (not within 0..255): %i", universe); |
---|
| 811 | universe = -1; |
---|
| 812 | error++; |
---|
| 813 | } |
---|
| 814 | |
---|
[2115] | 815 | } else if ( strcmp(k, "name") == 0 ) { |
---|
| 816 | if ( streams_set_name(stream, v) == -1 ) { |
---|
| 817 | ROAR_ERR("add_output(*): Can not set Stream name"); |
---|
| 818 | error++; |
---|
| 819 | } |
---|
[1991] | 820 | |
---|
[1032] | 821 | } else if ( strcmp(k, "meta") == 0 ) { |
---|
| 822 | streams_set_flag(stream, ROAR_FLAG_META); |
---|
[1117] | 823 | } else if ( strcmp(k, "sync") == 0 ) { |
---|
| 824 | sync = 1; |
---|
[1221] | 825 | } else if ( strcmp(k, "primary") == 0 ) { |
---|
| 826 | prim = 1; |
---|
| 827 | |
---|
| 828 | } else if ( strcmp(k, "cleanmeta") == 0 ) { |
---|
| 829 | streams_set_flag(stream, ROAR_FLAG_CLEANMETA); |
---|
| 830 | } else if ( strcmp(k, "autoconf") == 0 ) { |
---|
[1531] | 831 | streams_set_flag(stream, ROAR_FLAG_AUTOCONF); |
---|
[2413] | 832 | } else if ( strcmp(k, "recsource") == 0 ) { |
---|
| 833 | streams_set_flag(stream, ROAR_FLAG_RECSOURCE); |
---|
| 834 | } else if ( strcmp(k, "passmixer") == 0 ) { |
---|
| 835 | streams_set_flag(stream, ROAR_FLAG_PASSMIXER); |
---|
[938] | 836 | } else { |
---|
| 837 | ROAR_ERR("add_output(*): unknown option '%s'", k); |
---|
[1991] | 838 | error++; |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | if ( error ) { |
---|
[938] | 842 | streams_delete(stream); |
---|
[982] | 843 | if ( prim ) alive = 0; |
---|
[1208] | 844 | #ifdef ROAR_DRIVER_CODEC |
---|
| 845 | if ( to_free != NULL ) |
---|
| 846 | free(to_free); |
---|
| 847 | #endif |
---|
[938] | 848 | return -1; |
---|
| 849 | } |
---|
| 850 | |
---|
| 851 | k = strtok(NULL, ","); |
---|
| 852 | } |
---|
| 853 | |
---|
[2785] | 854 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
| 855 | |
---|
[2511] | 856 | // set audio info... |
---|
| 857 | switch (dir) { |
---|
| 858 | case ROAR_DIR_LIGHT_OUT: |
---|
| 859 | switch (s->info.codec) { |
---|
| 860 | case ROAR_CODEC_DMX512: |
---|
| 861 | case -1: |
---|
| 862 | if ( s->info.rate == -1 ) |
---|
| 863 | s->info.rate = ROAR_OUTPUT_CFREQ; |
---|
| 864 | |
---|
| 865 | s->info.channels = 0; |
---|
| 866 | s->info.bits = 8; |
---|
| 867 | s->info.codec = ROAR_CODEC_DMX512; // in case codec == -1 |
---|
| 868 | break; |
---|
| 869 | } |
---|
| 870 | break; |
---|
| 871 | case ROAR_DIR_MIDI_OUT: |
---|
| 872 | switch (s->info.codec) { |
---|
| 873 | case ROAR_CODEC_MIDI: |
---|
| 874 | case -1: |
---|
| 875 | if ( s->info.rate == -1 ) |
---|
| 876 | s->info.rate = ROAR_MIDI_TICKS_PER_BEAT; |
---|
| 877 | |
---|
| 878 | s->info.channels = ROAR_MIDI_CHANNELS_DEFAULT; |
---|
| 879 | s->info.bits = ROAR_MIDI_BITS; |
---|
| 880 | s->info.codec = ROAR_CODEC_MIDI; // in case codec == -1 |
---|
| 881 | break; |
---|
| 882 | } |
---|
| 883 | break; |
---|
| 884 | case ROAR_DIR_RAW_OUT: |
---|
| 885 | if ( s->info.rate == -1 ) |
---|
| 886 | s->info.rate = 0; |
---|
| 887 | if ( s->info.bits == -1 ) |
---|
| 888 | s->info.bits = 0; |
---|
| 889 | if ( s->info.channels == -1 ) |
---|
| 890 | s->info.channels = 0; |
---|
| 891 | if ( s->info.codec == -1 ) |
---|
| 892 | s->info.codec = 0; |
---|
| 893 | break; |
---|
| 894 | } |
---|
| 895 | |
---|
| 896 | if ( s->info.rate == -1 ) |
---|
| 897 | s->info.rate = g_sa->rate; |
---|
| 898 | if ( s->info.bits == -1 ) |
---|
| 899 | s->info.bits = g_sa->bits; |
---|
| 900 | if ( s->info.channels == -1 ) |
---|
| 901 | s->info.channels = g_sa->channels; |
---|
| 902 | if ( s->info.codec == -1 ) |
---|
| 903 | s->info.codec = g_sa->codec; |
---|
| 904 | |
---|
| 905 | 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); |
---|
| 906 | |
---|
[1919] | 907 | if ( streams_set_dir(stream, dir, 1) == -1 ) { |
---|
| 908 | streams_delete(stream); |
---|
| 909 | return -1; |
---|
| 910 | } |
---|
| 911 | |
---|
[1208] | 912 | #ifdef ROAR_DRIVER_CODEC |
---|
| 913 | if ( to_free != NULL ) |
---|
| 914 | free(to_free); |
---|
| 915 | #endif |
---|
| 916 | |
---|
[2511] | 917 | if ( s->info.codec == ROAR_CODEC_ALAW || s->info.codec == ROAR_CODEC_MULAW ) |
---|
[941] | 918 | s->info.bits = 8; // needed to open OSS driver, will be overriden by codecfilter |
---|
| 919 | |
---|
[2511] | 920 | ROAR_STREAM_SERVER(s)->codec_orgi = s->info.codec; |
---|
[933] | 921 | |
---|
[2364] | 922 | if ( driver_openvio(&(ss->vio), &(ss->driver_id), drv, dev, &(s->info), -1, ss) == -1 ) { |
---|
[1581] | 923 | ss->driver_id = -1; // don't close a driver not opened... |
---|
| 924 | memset(&(ss->vio), 0, sizeof(struct roar_vio_calls)); |
---|
[933] | 925 | streams_delete(stream); |
---|
[938] | 926 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts); |
---|
[982] | 927 | if ( prim ) alive = 0; |
---|
[933] | 928 | return -1; |
---|
| 929 | } |
---|
| 930 | |
---|
[1528] | 931 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAMID, &stream); // ignore errors here |
---|
| 932 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAM, s); // ignore errors here |
---|
| 933 | |
---|
[1221] | 934 | if ( blocks != -1 ) |
---|
| 935 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLOCKS, &blocks); |
---|
| 936 | |
---|
[1522] | 937 | if ( blocksize != -1 ) |
---|
| 938 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLKSIZE, &blocksize); |
---|
| 939 | |
---|
[1991] | 940 | // TODO: we shoudld *really* check for errors here... |
---|
| 941 | if ( channel != -1 ) { |
---|
| 942 | tu16 = channel; |
---|
| 943 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXSCHAN, &tu16); |
---|
| 944 | } |
---|
| 945 | if ( universe != -1 ) { |
---|
| 946 | tu16 = universe; |
---|
| 947 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXUNIV, &tu16); |
---|
| 948 | } |
---|
| 949 | |
---|
[1156] | 950 | ROAR_DBG("add_output(*): ss->driver_id=%i", ss->driver_id); |
---|
| 951 | |
---|
[938] | 952 | streams_set_fh(stream, -1); // update some internal structures |
---|
| 953 | |
---|
[2087] | 954 | if ( q > -1e6 ) { |
---|
| 955 | ROAR_DBG("add_output(*): setting q=%f", q); |
---|
| 956 | streams_ctl(stream, ROAR_CODECFILTER_CTL_SET_Q|ROAR_STREAM_CTL_TYPE_FLOAT, &q); |
---|
| 957 | } |
---|
| 958 | |
---|
[2490] | 959 | client_stream_add(g_self_client, stream); |
---|
[933] | 960 | |
---|
[1200] | 961 | if ( prim ) { |
---|
[961] | 962 | streams_mark_primary(stream); |
---|
[1200] | 963 | s->pos_rel_id = stream; |
---|
| 964 | } |
---|
[961] | 965 | |
---|
[1120] | 966 | if ( sync ) { |
---|
[1117] | 967 | streams_set_flag(stream, ROAR_FLAG_SYNC); |
---|
[1120] | 968 | } else { |
---|
| 969 | streams_reset_flag(stream, ROAR_FLAG_SYNC); |
---|
| 970 | } |
---|
[1117] | 971 | |
---|
[1926] | 972 | if ( f_mmap ) |
---|
| 973 | streams_set_flag(stream, ROAR_FLAG_MMAP); |
---|
| 974 | |
---|
[2511] | 975 | 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] | 976 | return 0; |
---|
[932] | 977 | } |
---|
| 978 | |
---|
[3373] | 979 | // X11: |
---|
| 980 | #ifdef ROAR_HAVE_LIBX11 |
---|
| 981 | int register_x11 (int unreg, char * sockname) { |
---|
| 982 | struct roar_x11_connection * x11con = NULL; |
---|
| 983 | int ret = 0; |
---|
| 984 | |
---|
[3374] | 985 | if ( (x11con = roar_x11_connect(x11display)) == NULL ) |
---|
[3373] | 986 | return -1; |
---|
| 987 | |
---|
| 988 | if ( unreg ) { |
---|
| 989 | if ( roar_x11_delete_prop(x11con, "ROAR_SERVER") == -1 ) |
---|
| 990 | ret = -1; |
---|
| 991 | } else { |
---|
| 992 | if ( roar_x11_set_prop(x11con, "ROAR_SERVER", sockname) == -1 ) |
---|
| 993 | ret = -1; |
---|
| 994 | } |
---|
| 995 | |
---|
| 996 | roar_x11_disconnect(x11con); |
---|
| 997 | |
---|
| 998 | return ret; |
---|
| 999 | } |
---|
| 1000 | #endif |
---|
[1993] | 1001 | |
---|
| 1002 | // SLP: |
---|
| 1003 | void register_slp_callback(SLPHandle hslp, SLPError errcode, void * cookie) { |
---|
| 1004 | /* return the error code in the cookie */ |
---|
| 1005 | *(SLPError*)cookie = errcode; |
---|
| 1006 | } |
---|
| 1007 | |
---|
| 1008 | int register_slp (int unreg, char * sockname) { |
---|
| 1009 | #ifdef ROAR_HAVE_LIBSLP |
---|
| 1010 | static int regged = 0; |
---|
| 1011 | static char * sn = NULL; |
---|
| 1012 | SLPError err; |
---|
| 1013 | SLPError callbackerr; |
---|
| 1014 | SLPHandle hslp; |
---|
| 1015 | char addr[1024]; |
---|
| 1016 | char attr[1024] = ""; |
---|
[2017] | 1017 | char * location; |
---|
[1993] | 1018 | |
---|
| 1019 | if ( sockname != NULL ) |
---|
| 1020 | sn = sockname; |
---|
| 1021 | |
---|
[3076] | 1022 | snprintf(addr, sizeof(addr), ROAR_SLP_URL_TYPE_ROAR "://%s", sn); |
---|
[1993] | 1023 | |
---|
| 1024 | err = SLPOpen("en", SLP_FALSE, &hslp); |
---|
| 1025 | |
---|
| 1026 | if (err != SLP_OK) { |
---|
| 1027 | ROAR_ERR("Error opening slp handle: Error #%i", err); |
---|
| 1028 | return -1; |
---|
| 1029 | } |
---|
| 1030 | |
---|
| 1031 | if (!unreg) { |
---|
[2017] | 1032 | |
---|
| 1033 | if ( SLPEscape(g_config->location, &location, SLP_FALSE) != SLP_OK ) { |
---|
| 1034 | ROAR_ERR("Error using SLPEscape() on server location, really bad!"); |
---|
| 1035 | SLPClose(hslp); |
---|
| 1036 | return -1; |
---|
| 1037 | } |
---|
| 1038 | |
---|
[1995] | 1039 | snprintf(attr, sizeof(attr), "(wave-rate=%i),(wave-channels=%i),(wave-bits=%i)," |
---|
[2494] | 1040 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
| 1041 | "(light-channels=%i)," |
---|
| 1042 | #endif |
---|
| 1043 | "(location=%s)", |
---|
[1995] | 1044 | g_sa->rate, g_sa->channels, g_sa->bits, |
---|
[2494] | 1045 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[2017] | 1046 | g_light_state.channels, |
---|
[2494] | 1047 | #endif |
---|
[2017] | 1048 | location |
---|
[1995] | 1049 | ); |
---|
| 1050 | |
---|
[1993] | 1051 | /* Register a service with SLP */ |
---|
| 1052 | err = SLPReg(hslp, |
---|
| 1053 | addr, |
---|
| 1054 | SLP_LIFETIME_MAXIMUM, |
---|
| 1055 | 0, |
---|
| 1056 | attr, |
---|
| 1057 | SLP_TRUE, |
---|
| 1058 | register_slp_callback, |
---|
| 1059 | &callbackerr); |
---|
[1994] | 1060 | regged = 1; |
---|
| 1061 | } else if ( unreg && regged ) { |
---|
| 1062 | err = SLPDereg(hslp, addr, register_slp_callback, &callbackerr); |
---|
| 1063 | regged = 0; |
---|
| 1064 | } else { |
---|
| 1065 | SLPClose(hslp); |
---|
| 1066 | return -1; |
---|
| 1067 | } |
---|
[1993] | 1068 | |
---|
[1994] | 1069 | /* err may contain an error code that occurred as the slp library */ |
---|
| 1070 | /* _prepared_ to make the call. */ |
---|
| 1071 | if ( err != SLP_OK ) { |
---|
| 1072 | ROAR_ERR("Error (de)registering service with slp: Error #%i", err); |
---|
| 1073 | return -1; |
---|
| 1074 | } |
---|
| 1075 | |
---|
| 1076 | /* callbackerr may contain an error code (that was assigned through */ |
---|
| 1077 | /* the callback cookie) that occurred as slp packets were sent on */ |
---|
| 1078 | /* the wire */ |
---|
| 1079 | if (callbackerr != SLP_OK) { |
---|
| 1080 | ROAR_ERR("Error (de)registering service with slp: Error #%i", callbackerr); |
---|
| 1081 | return -1; |
---|
[1993] | 1082 | } |
---|
| 1083 | |
---|
| 1084 | SLPClose(hslp); |
---|
| 1085 | return 0; |
---|
| 1086 | #else |
---|
| 1087 | return -1; |
---|
| 1088 | #endif |
---|
| 1089 | } |
---|
| 1090 | |
---|
| 1091 | |
---|
| 1092 | // MAIN: |
---|
| 1093 | |
---|
[1503] | 1094 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 1095 | int main (int argc, char * argv[]) { |
---|
[1503] | 1096 | #else |
---|
| 1097 | int main (void) { |
---|
| 1098 | #endif |
---|
| 1099 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 1100 | int i; |
---|
| 1101 | char * k; |
---|
[1503] | 1102 | #endif |
---|
[2787] | 1103 | #if defined(ROAR_SUPPORT_LISTEN) && defined(ROAR_HAVE_GETUID) |
---|
[905] | 1104 | char user_sock[80] = {0}; |
---|
[1494] | 1105 | #endif |
---|
[1609] | 1106 | struct roar_audio_info sa, max_sa; |
---|
| 1107 | struct roard_config config; |
---|
[1486] | 1108 | #ifdef ROAR_HAVE_FORK |
---|
[905] | 1109 | int daemon = 0; |
---|
[1486] | 1110 | #endif |
---|
[905] | 1111 | int realtime = 0; |
---|
| 1112 | int sysclocksync = 0; |
---|
[1207] | 1113 | char * driver = NULL; |
---|
| 1114 | char * device = NULL; |
---|
[1503] | 1115 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[1207] | 1116 | char * opts = NULL; |
---|
[1503] | 1117 | #endif |
---|
[60] | 1118 | // char * server = ROAR_DEFAULT_SOCK_GLOBAL; |
---|
[1494] | 1119 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1120 | int port = ROAR_DEFAULT_PORT; |
---|
| 1121 | char * sock_addr = NULL; |
---|
| 1122 | int sock_proto = ROAR_PROTO_ROARAUDIO; |
---|
[3252] | 1123 | int sock_dir = -1; |
---|
| 1124 | struct roar_audio_info sock_info = {0, 0, 0, 0}; |
---|
[1494] | 1125 | #endif |
---|
[0] | 1126 | int drvid; |
---|
[2486] | 1127 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[550] | 1128 | char * s_drv = "cf"; |
---|
[1110] | 1129 | char * s_dev = NULL; |
---|
[444] | 1130 | char * s_con = NULL; |
---|
| 1131 | char * s_opt = NULL; |
---|
| 1132 | int s_prim = 0; |
---|
[2486] | 1133 | #endif |
---|
[1207] | 1134 | char * o_drv = getenv("ROAR_DRIVER"); |
---|
| 1135 | char * o_dev = getenv("ROAR_DEVICE"); |
---|
[932] | 1136 | char * o_opts = NULL; |
---|
[961] | 1137 | int o_prim = 0; |
---|
[1145] | 1138 | int o_count = 0; |
---|
[2494] | 1139 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1923] | 1140 | int light_channels = LIGHT_CHANNELS_DEFAULT; |
---|
[2494] | 1141 | #endif |
---|
[2751] | 1142 | #ifdef ROAR_DEFAULT_SOCKGRP |
---|
[450] | 1143 | char * sock_grp = ROAR_DEFAULT_SOCKGRP; |
---|
[2751] | 1144 | #else |
---|
| 1145 | char * sock_grp = NULL; |
---|
| 1146 | #endif |
---|
[444] | 1147 | char * sock_user = NULL; |
---|
[1494] | 1148 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[517] | 1149 | int sock_type = ROAR_SOCKET_TYPE_UNKNOWN; |
---|
[1494] | 1150 | #endif |
---|
[1993] | 1151 | #ifdef ROAR_HAVE_LIBSLP |
---|
| 1152 | int reg_slp = 0; |
---|
| 1153 | #endif |
---|
[3373] | 1154 | #ifdef ROAR_HAVE_LIBX11 |
---|
| 1155 | int reg_x11 = 0; |
---|
| 1156 | #endif |
---|
[1486] | 1157 | #ifdef ROAR_HAVE_CHROOT |
---|
[444] | 1158 | char * chrootdir = NULL; |
---|
[1486] | 1159 | #endif |
---|
| 1160 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[446] | 1161 | struct group * grp = NULL; |
---|
[1486] | 1162 | #endif |
---|
| 1163 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[446] | 1164 | struct passwd * pwd = NULL; |
---|
[1486] | 1165 | #endif |
---|
| 1166 | #ifdef ROAR_HAVE_GETSERVBYNAME |
---|
[446] | 1167 | struct servent * serv = NULL; |
---|
[1486] | 1168 | #endif |
---|
[0] | 1169 | DRIVER_USERDATA_T drvinst; |
---|
[39] | 1170 | struct roar_client * self = NULL; |
---|
[508] | 1171 | #ifdef ROAR_HAVE_LIBDNET |
---|
| 1172 | char decnethost[80]; |
---|
| 1173 | #endif |
---|
[2104] | 1174 | #ifdef SUPPORT_PIDFILE |
---|
| 1175 | struct roar_vio_calls pidfile_vio; |
---|
| 1176 | #endif |
---|
[0] | 1177 | |
---|
[2784] | 1178 | ROAR_DBG("main(*): starting roard..."); |
---|
| 1179 | |
---|
[0] | 1180 | g_standby = 0; |
---|
[920] | 1181 | g_autostandby = 0; |
---|
[982] | 1182 | alive = 1; |
---|
[1494] | 1183 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[1155] | 1184 | g_no_listen = 0; |
---|
[1494] | 1185 | #else |
---|
| 1186 | g_terminate = 1; |
---|
| 1187 | #endif |
---|
[0] | 1188 | |
---|
[2970] | 1189 | g_verbose = ROAR_DBG_INFO_NONE; |
---|
| 1190 | |
---|
[0] | 1191 | sa.bits = ROAR_BITS_DEFAULT; |
---|
| 1192 | sa.channels = ROAR_CHANNELS_DEFAULT; |
---|
| 1193 | sa.rate = ROAR_RATE_DEFAULT; |
---|
| 1194 | sa.codec = ROAR_CODEC_DEFAULT; |
---|
| 1195 | |
---|
[1609] | 1196 | g_sa = &sa; |
---|
| 1197 | g_max_sa = &max_sa; |
---|
| 1198 | |
---|
| 1199 | memcpy(g_max_sa, g_sa, sizeof(max_sa)); |
---|
| 1200 | |
---|
| 1201 | g_config = &config; |
---|
| 1202 | |
---|
| 1203 | if ( init_config() == -1 ) { |
---|
| 1204 | ROAR_ERR("Can not init default config!"); |
---|
| 1205 | return 1; |
---|
| 1206 | } |
---|
[0] | 1207 | |
---|
[2968] | 1208 | // load config |
---|
| 1209 | roar_libroar_get_config(); |
---|
| 1210 | |
---|
[2530] | 1211 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 1212 | if ( init_listening() == -1 ) { |
---|
| 1213 | ROAR_ERR("Can not init listening sockets!"); |
---|
| 1214 | return 1; |
---|
| 1215 | } |
---|
| 1216 | #endif |
---|
| 1217 | |
---|
[2500] | 1218 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[1924] | 1219 | if ( midi_init_config() == -1 ) { |
---|
| 1220 | ROAR_ERR("Can not init MIDI config!"); |
---|
| 1221 | return 1; |
---|
| 1222 | } |
---|
[2500] | 1223 | #endif |
---|
[60] | 1224 | |
---|
[2489] | 1225 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
[2451] | 1226 | if ( ssynth_init_config() == -1 ) { |
---|
| 1227 | ROAR_ERR("Can not init ssynth config!"); |
---|
| 1228 | return 1; |
---|
| 1229 | } |
---|
[2489] | 1230 | #endif |
---|
[2451] | 1231 | |
---|
[2718] | 1232 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1233 | if ( rdtcs_init_config() == -1 ) { |
---|
| 1234 | ROAR_ERR("Can not init RDTCS config!"); |
---|
| 1235 | return 1; |
---|
| 1236 | } |
---|
| 1237 | #endif |
---|
| 1238 | |
---|
[3354] | 1239 | if ( plugins_preinit() == -1 ) { |
---|
| 1240 | ROAR_ERR("Can not pre-init plugins!"); |
---|
| 1241 | return 1; |
---|
| 1242 | } |
---|
| 1243 | |
---|
[1494] | 1244 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2767] | 1245 | #ifndef ROAR_TARGET_WIN32 |
---|
[2530] | 1246 | sock_addr = ROAR_DEFAULT_SOCK_GLOBAL; |
---|
[2767] | 1247 | #else |
---|
| 1248 | sock_addr = ROAR_DEFAULT_HOST; |
---|
| 1249 | #endif |
---|
| 1250 | |
---|
[1753] | 1251 | #ifdef ROAR_HAVE_GETUID |
---|
[1486] | 1252 | if ( getuid() != 0 && getenv("HOME") != NULL ) { |
---|
[3959] | 1253 | /* |
---|
[1486] | 1254 | snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER); |
---|
[3959] | 1255 | */ |
---|
| 1256 | roar_env_render_path_r(user_sock, sizeof(user_sock), "~/" ROAR_DEFAULT_SOCK_USER); |
---|
[2530] | 1257 | sock_addr = user_sock; |
---|
[3959] | 1258 | ROAR_DBG("main(*): setting sock_addr='%s'", sock_addr); |
---|
[60] | 1259 | } |
---|
[1753] | 1260 | #endif |
---|
[60] | 1261 | |
---|
[279] | 1262 | if ( getenv("ROAR_SERVER") != NULL ) |
---|
[2530] | 1263 | sock_addr = getenv("ROAR_SERVER"); |
---|
[1494] | 1264 | #endif |
---|
[279] | 1265 | |
---|
[63] | 1266 | if ( clients_init() == -1 ) { |
---|
| 1267 | ROAR_ERR("Can not init clients!"); |
---|
| 1268 | return 1; |
---|
| 1269 | } |
---|
| 1270 | |
---|
| 1271 | if ( streams_init() == -1 ) { |
---|
| 1272 | ROAR_ERR("Can not init streams!"); |
---|
| 1273 | return 1; |
---|
| 1274 | } |
---|
| 1275 | |
---|
[64] | 1276 | if ( (g_self_client = clients_new()) == -1 ) { |
---|
| 1277 | ROAR_ERR("Can not create self client!"); |
---|
| 1278 | return 1; |
---|
| 1279 | } |
---|
| 1280 | |
---|
[2485] | 1281 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[0] | 1282 | if ( sources_init() == -1 ) { |
---|
| 1283 | ROAR_ERR("Can not init sources!"); |
---|
| 1284 | return 1; |
---|
| 1285 | } |
---|
| 1286 | |
---|
[64] | 1287 | if ( (sources_set_client(g_self_client)) == -1 ) { |
---|
| 1288 | ROAR_ERR("Can not init set source client!"); |
---|
| 1289 | return 1; |
---|
| 1290 | } |
---|
[2485] | 1291 | #endif |
---|
[64] | 1292 | |
---|
[1503] | 1293 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 1294 | for (i = 1; i < argc; i++) { |
---|
| 1295 | k = argv[i]; |
---|
| 1296 | |
---|
| 1297 | if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) { |
---|
| 1298 | usage(); |
---|
| 1299 | return 0; |
---|
| 1300 | |
---|
[2109] | 1301 | } else if ( strcmp(k, "--start") == 0 ) { |
---|
| 1302 | // this is a no op |
---|
[579] | 1303 | } else if ( strcmp(k, "--restart") == 0 ) { |
---|
[1494] | 1304 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1305 | if ( restart_server(sock_addr, 1) == -1 ) { |
---|
| 1306 | ROAR_WARN("Can not terminate old server (not running at %s?), tring to continue anyway", sock_addr); |
---|
[579] | 1307 | } |
---|
[1494] | 1308 | #else |
---|
| 1309 | ROAR_ERR("--restart not supported"); |
---|
| 1310 | #endif |
---|
[2109] | 1311 | } else if ( strcmp(k, "--shutdown") == 0 ) { |
---|
| 1312 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1313 | if ( restart_server(sock_addr, 1) == -1 ) { |
---|
| 1314 | ROAR_WARN("Can not terminate old server (not running at %s?)", sock_addr); |
---|
[2109] | 1315 | return 1; |
---|
| 1316 | } |
---|
| 1317 | return 0; |
---|
| 1318 | #else |
---|
| 1319 | ROAR_ERR("--shutdown not supported"); |
---|
| 1320 | return 1; |
---|
| 1321 | #endif |
---|
| 1322 | } else if ( strcmp(k, "--stop") == 0 ) { |
---|
| 1323 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1324 | if ( restart_server(sock_addr, 0) == -1 ) { |
---|
| 1325 | ROAR_WARN("Can not stop old server (not running at %s?)", sock_addr); |
---|
[2109] | 1326 | return 1; |
---|
| 1327 | } |
---|
| 1328 | return 0; |
---|
| 1329 | #else |
---|
| 1330 | ROAR_ERR("--stop not supported"); |
---|
| 1331 | return 1; |
---|
| 1332 | #endif |
---|
| 1333 | |
---|
[579] | 1334 | |
---|
[775] | 1335 | } else if ( strcmp(k, "--demon") == 0 || strcmp(k, "--daemon") == 0 ) { |
---|
[1486] | 1336 | #ifdef ROAR_HAVE_FORK |
---|
[775] | 1337 | daemon = 1; |
---|
[1486] | 1338 | #else |
---|
| 1339 | ROAR_ERR("--daemon not supported"); |
---|
| 1340 | #endif |
---|
[2970] | 1341 | } else if ( strcmp(k, "--verbose") == 0 ) { |
---|
| 1342 | g_verbose++; |
---|
[71] | 1343 | } else if ( strcmp(k, "--terminate") == 0 ) { |
---|
| 1344 | g_terminate = 1; |
---|
[905] | 1345 | } else if ( strcmp(k, "--sysclocksync") == 0 ) { |
---|
| 1346 | sysclocksync = 1000; |
---|
[275] | 1347 | } else if ( strcmp(k, "--realtime") == 0 ) { |
---|
[276] | 1348 | realtime++; |
---|
[444] | 1349 | } else if ( strcmp(k, "--chroot") == 0 ) { |
---|
[1486] | 1350 | #ifdef ROAR_HAVE_CHROOT |
---|
[444] | 1351 | chrootdir = argv[++i]; |
---|
[1486] | 1352 | #else |
---|
| 1353 | ROAR_ERR("--chroot not supported"); |
---|
| 1354 | i++; |
---|
| 1355 | #endif |
---|
[444] | 1356 | } else if ( strcmp(k, "--setgid") == 0 ) { |
---|
[1486] | 1357 | #ifdef ROAR_HAVE_SETGID |
---|
[444] | 1358 | setids |= R_SETGID; |
---|
[1486] | 1359 | #else |
---|
| 1360 | ROAR_ERR("--setgid not supported"); |
---|
| 1361 | #endif |
---|
[444] | 1362 | } else if ( strcmp(k, "--setuid") == 0 ) { |
---|
[1486] | 1363 | #ifdef ROAR_HAVE_SETUID |
---|
[444] | 1364 | setids |= R_SETUID; |
---|
[1486] | 1365 | #else |
---|
| 1366 | ROAR_ERR("--setuid not supported"); |
---|
| 1367 | #endif |
---|
[2017] | 1368 | } else if ( strcmp(k, "--location") == 0 ) { |
---|
| 1369 | g_config->location = argv[++i]; |
---|
[2104] | 1370 | } else if ( strcmp(k, "--pidfile") == 0 ) { |
---|
| 1371 | #ifdef SUPPORT_PIDFILE |
---|
| 1372 | pidfile = argv[++i]; |
---|
| 1373 | #else |
---|
| 1374 | ROAR_ERR("--pidfile not supported"); |
---|
| 1375 | i++; |
---|
| 1376 | #endif |
---|
[3688] | 1377 | } else if ( strcmp(k, "--log-syslog") == 0 ) { |
---|
| 1378 | #ifdef ROAR_HAVE_SYSLOG |
---|
| 1379 | roar_debug_set_stderr_mode(ROAR_DEBUG_MODE_SYSLOG); |
---|
| 1380 | #else |
---|
| 1381 | ROAR_ERR("--log-syslog not supported"); |
---|
| 1382 | #endif |
---|
| 1383 | |
---|
[68] | 1384 | |
---|
[3356] | 1385 | } else if ( strcmp(k, "--plugin-load") == 0 ) { |
---|
| 1386 | if ( plugins_load(argv[++i]) == -1 ) { |
---|
| 1387 | ROAR_ERR("Can not load plugin"); |
---|
| 1388 | } |
---|
| 1389 | |
---|
[280] | 1390 | } else if ( strcmp(k, "--list-cf") == 0 ) { |
---|
| 1391 | print_codecfilterlist(); |
---|
| 1392 | return 0; |
---|
| 1393 | |
---|
[0] | 1394 | } else if ( strcmp(k, "-R") == 0 || strcmp(k, "--rate") == 0 ) { |
---|
| 1395 | sa.rate = atoi(argv[++i]); |
---|
| 1396 | } else if ( strcmp(k, "-B") == 0 || strcmp(k, "--bits") == 0 ) { |
---|
| 1397 | sa.bits = atoi(argv[++i]); |
---|
| 1398 | } else if ( strcmp(k, "-C") == 0 || strcmp(k, "--chans") == 0 ) { |
---|
| 1399 | sa.channels = atoi(argv[++i]); |
---|
| 1400 | |
---|
[3962] | 1401 | } else if ( strcmp(k, "--aiprofile") == 0 ) { |
---|
| 1402 | if ( roar_profile2info(&sa, argv[++i]) == -1 ) { |
---|
| 1403 | ROAR_ERR("Unknown audio profile: %s", argv[i]); |
---|
| 1404 | return 1; |
---|
| 1405 | } |
---|
| 1406 | sa.codec = ROAR_CODEC_DEFAULT; |
---|
| 1407 | |
---|
[2339] | 1408 | } else if ( strcmp(k, "--stream-flags") == 0 ) { |
---|
| 1409 | if ( update_stream_flags(argv[++i]) == -1 ) { |
---|
| 1410 | ROAR_ERR("Can not set stream flags"); |
---|
| 1411 | return 1; |
---|
| 1412 | } |
---|
| 1413 | |
---|
[0] | 1414 | } else if ( strcmp(k, "-d") == 0 || strcmp(k, "--driver") == 0 ) { |
---|
| 1415 | driver = argv[++i]; |
---|
| 1416 | if ( strcmp(driver, "list") == 0 ) { |
---|
[974] | 1417 | ROAR_WARN("The option is obsolete, use --list-driver!"); |
---|
[0] | 1418 | print_driverlist(); |
---|
[973] | 1419 | return 0; |
---|
[0] | 1420 | } |
---|
| 1421 | } else if ( strcmp(k, "-D") == 0 || strcmp(k, "--device") == 0 ) { |
---|
| 1422 | device = argv[++i]; |
---|
| 1423 | } else if ( strcmp(k, "-dO") == 0 ) { |
---|
| 1424 | opts = argv[++i]; |
---|
[973] | 1425 | } else if ( strcmp(k, "--list-driver") == 0 ) { |
---|
| 1426 | print_driverlist(); |
---|
| 1427 | return 0; |
---|
[0] | 1428 | |
---|
[932] | 1429 | } else if ( strcmp(k, "-o") == 0 || strcmp(k, "--odriver") == 0 ) { |
---|
| 1430 | o_drv = argv[++i]; |
---|
| 1431 | } else if ( strcmp(k, "-O") == 0 || strcmp(k, "--odevice") == 0 ) { |
---|
| 1432 | o_dev = argv[++i]; |
---|
| 1433 | } else if ( strcmp(k, "-oO") == 0 ) { |
---|
| 1434 | o_opts = argv[++i]; |
---|
[961] | 1435 | } else if ( strcmp(k, "-oP") == 0 ) { |
---|
| 1436 | o_prim = 1; |
---|
[932] | 1437 | } else if ( strcmp(k, "-oN") == 0 ) { |
---|
[1145] | 1438 | if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 ) |
---|
| 1439 | o_count++; |
---|
| 1440 | |
---|
[961] | 1441 | o_drv = o_dev = o_opts = NULL; |
---|
| 1442 | o_prim = 0; |
---|
[932] | 1443 | |
---|
[0] | 1444 | } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) { |
---|
[2485] | 1445 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[550] | 1446 | s_drv = argv[++i]; |
---|
[2485] | 1447 | #else |
---|
| 1448 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
| 1449 | #endif |
---|
[550] | 1450 | } else if ( strcmp(k, "-S") == 0 ) { |
---|
[2485] | 1451 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[1110] | 1452 | s_dev = argv[++i]; |
---|
[2485] | 1453 | #else |
---|
| 1454 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
| 1455 | #endif |
---|
[0] | 1456 | } else if ( strcmp(k, "-sO") == 0 ) { |
---|
[2485] | 1457 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[0] | 1458 | s_opt = argv[++i]; |
---|
[2485] | 1459 | #else |
---|
| 1460 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
| 1461 | #endif |
---|
[0] | 1462 | } else if ( strcmp(k, "-sC") == 0 ) { |
---|
[2485] | 1463 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[0] | 1464 | s_con = argv[++i]; |
---|
[2485] | 1465 | #else |
---|
| 1466 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
| 1467 | #endif |
---|
[0] | 1468 | } else if ( strcmp(k, "-sP") == 0 ) { |
---|
[2485] | 1469 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[0] | 1470 | s_prim = 1; |
---|
[2485] | 1471 | #else |
---|
| 1472 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
| 1473 | #endif |
---|
[1110] | 1474 | } else if ( strcmp(k, "-sN") == 0 ) { |
---|
[2485] | 1475 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[1110] | 1476 | if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) { |
---|
| 1477 | ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv); |
---|
| 1478 | } |
---|
| 1479 | s_opt = s_dev = s_con = NULL; |
---|
| 1480 | s_drv = "cf"; |
---|
| 1481 | s_prim = 0; |
---|
[2485] | 1482 | #else |
---|
| 1483 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
| 1484 | #endif |
---|
[2270] | 1485 | } else if ( strcmp(k, "--list-sources") == 0 ) { |
---|
[2485] | 1486 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[2270] | 1487 | print_sourcelist(); |
---|
| 1488 | return 0; |
---|
[2485] | 1489 | #else |
---|
| 1490 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
[2504] | 1491 | return 1; |
---|
[2485] | 1492 | #endif |
---|
[0] | 1493 | |
---|
[1923] | 1494 | } else if ( strcmp(k, "--light-channels") == 0 ) { |
---|
[2494] | 1495 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1923] | 1496 | light_channels = atoi(argv[++i]); |
---|
[2494] | 1497 | #else |
---|
| 1498 | ROAR_WARN("main(*): no light subsystem compiled in"); |
---|
| 1499 | #endif |
---|
[1923] | 1500 | |
---|
[2725] | 1501 | } else if ( strcmp(k, "--rds-pi") == 0 ) { |
---|
| 1502 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1503 | g_rdtcs.rds.pi = atoi(argv[++i]); |
---|
| 1504 | #else |
---|
| 1505 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
| 1506 | #endif |
---|
[2728] | 1507 | } else if ( strcmp(k, "--rds-ps") == 0 ) { |
---|
| 1508 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1509 | if ( rdtcs_rds_set_ps(argv[++i]) == -1 ) { |
---|
[2729] | 1510 | ROAR_ERR("Can not set RDS PS to '%s' (longer than 8 chars?)", argv[i]); |
---|
[2728] | 1511 | return 1; |
---|
| 1512 | } |
---|
| 1513 | #else |
---|
| 1514 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
| 1515 | #endif |
---|
| 1516 | } else if ( strcmp(k, "--rds-pty") == 0 ) { |
---|
| 1517 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1518 | if ( rdtcs_rds_set_pty(argv[++i]) == -1 ) { |
---|
[2729] | 1519 | ROAR_ERR("Can not set RDS PTY to '%s'", argv[i]); |
---|
[2728] | 1520 | return 1; |
---|
| 1521 | } |
---|
| 1522 | #else |
---|
| 1523 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
| 1524 | #endif |
---|
| 1525 | } else if ( strcmp(k, "--rds-tp") == 0 ) { |
---|
| 1526 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1527 | if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_TP, 0) == -1 ) { |
---|
| 1528 | ROAR_ERR("Can not set RDS TP flag"); |
---|
| 1529 | return 1; |
---|
| 1530 | } |
---|
| 1531 | #else |
---|
| 1532 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
| 1533 | #endif |
---|
| 1534 | } else if ( strcmp(k, "--rds-ct") == 0 ) { |
---|
| 1535 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1536 | if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_CT, 0) == -1 ) { |
---|
| 1537 | ROAR_ERR("Can not set RDS CT flag"); |
---|
| 1538 | return 1; |
---|
| 1539 | } |
---|
| 1540 | #else |
---|
| 1541 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
| 1542 | #endif |
---|
| 1543 | |
---|
[2725] | 1544 | |
---|
[1924] | 1545 | } else if ( strcmp(k, "--midi-no-console") == 0 ) { |
---|
[2487] | 1546 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
[1924] | 1547 | midi_config.init_cb = 0; |
---|
[2487] | 1548 | #else |
---|
| 1549 | // no warning here as this is the disable option |
---|
| 1550 | #endif |
---|
[2444] | 1551 | } else if ( strcmp(k, "--midi-console-enable") == 0 ) { |
---|
[2487] | 1552 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
[2444] | 1553 | midi_config.init_cb = 1; |
---|
[2487] | 1554 | #else |
---|
| 1555 | ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in"); |
---|
| 1556 | #endif |
---|
[1924] | 1557 | } else if ( strcmp(k, "--midi-console") == 0 ) { |
---|
[2487] | 1558 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
[1924] | 1559 | midi_config.console_dev = argv[++i]; |
---|
[2444] | 1560 | midi_config.init_cb = 1; |
---|
[2487] | 1561 | #else |
---|
| 1562 | ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in"); |
---|
| 1563 | #endif |
---|
[1924] | 1564 | |
---|
[2451] | 1565 | } else if ( strcmp(k, "--ssynth-enable") == 0 ) { |
---|
[2489] | 1566 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
[2451] | 1567 | ssynth_conf.enable = 1; |
---|
[2489] | 1568 | #else |
---|
| 1569 | ROAR_ERR("main(*): No support for ssynth compiled in"); |
---|
| 1570 | #endif |
---|
[2451] | 1571 | } else if ( strcmp(k, "--ssynth-disable") == 0 ) { |
---|
[2489] | 1572 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
[2451] | 1573 | ssynth_conf.enable = 0; |
---|
[2489] | 1574 | #else |
---|
| 1575 | // we can safely ignore the disable |
---|
| 1576 | #endif |
---|
[2451] | 1577 | |
---|
[3374] | 1578 | } else if ( strcmp(k, "--x11-display") == 0 || strcmp(k, "--display") == 0 ) { |
---|
| 1579 | #ifdef ROAR_HAVE_LIBX11 |
---|
| 1580 | x11display = argv[++i]; |
---|
| 1581 | #else |
---|
| 1582 | ROAR_ERR("No X11 support compiled in!"); |
---|
| 1583 | return 1; |
---|
| 1584 | #endif |
---|
| 1585 | |
---|
| 1586 | |
---|
[0] | 1587 | } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--port") == 0 ) { |
---|
[447] | 1588 | // This is only usefull in INET not UNIX mode. |
---|
[1494] | 1589 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1590 | if ( *sock_addr == '/' ) |
---|
| 1591 | sock_addr = ROAR_DEFAULT_HOST; |
---|
[447] | 1592 | |
---|
[446] | 1593 | errno = 0; |
---|
| 1594 | if ( (port = atoi(argv[++i])) < 1 ) { |
---|
[1486] | 1595 | #ifdef ROAR_HAVE_GETSERVBYNAME |
---|
[446] | 1596 | if ( (serv = getservbyname(argv[i], "tcp")) == NULL ) { |
---|
| 1597 | ROAR_ERR("Unknown service: %s: %s", argv[i], strerror(errno)); |
---|
| 1598 | return 1; |
---|
| 1599 | } |
---|
| 1600 | // NOTE: we need to use ROAR_NET2HOST16() here even if s_port is of type int! |
---|
| 1601 | ROAR_DBG("main(*): serv = {s_name='%s', s_aliases={...}, s_port=%i, s_proto='%s'}", |
---|
| 1602 | serv->s_name, ROAR_NET2HOST16(serv->s_port), serv->s_proto); |
---|
| 1603 | port = ROAR_NET2HOST16(serv->s_port); |
---|
[1486] | 1604 | #else |
---|
| 1605 | ROAR_ERR("invalite port number: %s", argv[i]); |
---|
| 1606 | return 1; |
---|
| 1607 | #endif |
---|
[446] | 1608 | } |
---|
[1494] | 1609 | #endif |
---|
[1115] | 1610 | } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) { |
---|
[1494] | 1611 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1612 | sock_addr = argv[++i]; |
---|
| 1613 | #endif |
---|
| 1614 | |
---|
| 1615 | } else if ( strcmp(k, "--proto") == 0 ) { |
---|
| 1616 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2549] | 1617 | if ( (sock_proto = roar_str2proto(argv[++i])) == -1 ) { |
---|
[2530] | 1618 | ROAR_ERR("Unknown protocol: %s", argv[i]); |
---|
| 1619 | return 1; |
---|
| 1620 | } |
---|
[1494] | 1621 | #endif |
---|
[3252] | 1622 | } else if ( strcmp(k, "--proto-dir") == 0 ) { |
---|
| 1623 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 1624 | if ( (sock_dir = roar_str2dir(argv[++i])) == -1 ) { |
---|
| 1625 | ROAR_ERR("Unknown stream direction: %s", argv[i]); |
---|
| 1626 | return 1; |
---|
| 1627 | } |
---|
| 1628 | #endif |
---|
| 1629 | } else if ( strcmp(k, "--proto-rate") == 0 ) { |
---|
| 1630 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 1631 | sock_info.rate = atoi(argv[++i]); |
---|
| 1632 | #endif |
---|
| 1633 | } else if ( strcmp(k, "--proto-bits") == 0 ) { |
---|
| 1634 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 1635 | sock_info.bits = atoi(argv[++i]); |
---|
| 1636 | #endif |
---|
| 1637 | } else if ( strcmp(k, "--proto-chans") == 0 ) { |
---|
| 1638 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 1639 | sock_info.channels = atoi(argv[++i]); |
---|
| 1640 | #endif |
---|
| 1641 | } else if ( strcmp(k, "--proto-codec") == 0 ) { |
---|
| 1642 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 1643 | if ( (sock_info.codec = roar_str2codec(argv[++i])) == -1 ) { |
---|
| 1644 | ROAR_ERR("Unknown codec: %s", argv[i]); |
---|
| 1645 | return 1; |
---|
| 1646 | } |
---|
| 1647 | #endif |
---|
[3954] | 1648 | } else if ( strcmp(k, "--proto-aiprofile") == 0 ) { |
---|
| 1649 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 1650 | if ( roar_profile2info(&sock_info, argv[++i]) == -1 ) { |
---|
| 1651 | ROAR_ERR("Unknown audio profile: %s", argv[i]); |
---|
| 1652 | return 1; |
---|
| 1653 | } |
---|
| 1654 | #endif |
---|
[3956] | 1655 | } else if ( strcmp(k, "--list-profiles") == 0 ) { |
---|
| 1656 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 1657 | listen_listen_profiles(); |
---|
| 1658 | return 0; |
---|
| 1659 | #endif |
---|
| 1660 | } else if ( strcmp(k, "--proto-profile") == 0 ) { |
---|
| 1661 | #ifdef ROAR_SUPPORT_LISTEN |
---|
| 1662 | if ( get_listen_profile(argv[++i], &port, &sock_addr, &sock_type, &sock_proto, &sock_dir, &sock_info) == -1 ) { |
---|
| 1663 | ROAR_ERR("Unknown listen profile: %s", argv[i]); |
---|
| 1664 | return 1; |
---|
| 1665 | } |
---|
| 1666 | #endif |
---|
[3252] | 1667 | |
---|
| 1668 | |
---|
[3127] | 1669 | } else if ( strcmp(k, "--list-proto") == 0 ) { |
---|
| 1670 | list_proto(); |
---|
| 1671 | return 0; |
---|
[518] | 1672 | |
---|
[573] | 1673 | } else if ( strcmp(k, "-t") == 0 || strcmp(k, "--tcp") == 0 ) { |
---|
[1494] | 1674 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[518] | 1675 | if ( sock_type != ROAR_SOCKET_TYPE_TCP && sock_type != ROAR_SOCKET_TYPE_TCP6 ) |
---|
| 1676 | sock_type = ROAR_SOCKET_TYPE_TCP; |
---|
| 1677 | |
---|
[2530] | 1678 | if ( *sock_addr == '/' ) |
---|
| 1679 | sock_addr = ROAR_DEFAULT_HOST; |
---|
[1494] | 1680 | #endif |
---|
[518] | 1681 | |
---|
| 1682 | } else if ( strcmp(k, "-4") == 0 ) { |
---|
[1494] | 1683 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[517] | 1684 | sock_type = ROAR_SOCKET_TYPE_TCP; |
---|
[2530] | 1685 | if ( *sock_addr == '/' ) |
---|
| 1686 | sock_addr = ROAR_DEFAULT_HOST; |
---|
[1494] | 1687 | #endif |
---|
[518] | 1688 | } else if ( strcmp(k, "-6") == 0 ) { |
---|
[1494] | 1689 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[3837] | 1690 | #ifdef AF_INET6 |
---|
[518] | 1691 | sock_type = ROAR_SOCKET_TYPE_TCP6; |
---|
[2530] | 1692 | if ( *sock_addr == '/' ) |
---|
| 1693 | sock_addr = ROAR_DEFAULT_HOST; |
---|
[519] | 1694 | #else |
---|
| 1695 | ROAR_ERR("No IPv6 support compiled in!"); |
---|
| 1696 | return 1; |
---|
| 1697 | #endif |
---|
[1494] | 1698 | #endif |
---|
[518] | 1699 | |
---|
[573] | 1700 | } else if ( strcmp(k, "-u") == 0 || strcmp(k, "--unix") == 0 ) { |
---|
[1494] | 1701 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[62] | 1702 | // ignore this case as it is the default behavor. |
---|
[517] | 1703 | sock_type = ROAR_SOCKET_TYPE_UNIX; |
---|
[1494] | 1704 | #endif |
---|
[518] | 1705 | |
---|
[573] | 1706 | } else if ( strcmp(k, "-n") == 0 || strcmp(k, "--decnet") == 0 ) { |
---|
[1494] | 1707 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[508] | 1708 | #ifdef ROAR_HAVE_LIBDNET |
---|
| 1709 | port = ROAR_DEFAULT_NUM; |
---|
| 1710 | strcpy(decnethost, ROAR_DEFAULT_LISTEN_OBJECT); |
---|
[2530] | 1711 | sock_addr = decnethost; |
---|
[517] | 1712 | sock_type = ROAR_SOCKET_TYPE_DECNET; |
---|
[508] | 1713 | #else |
---|
| 1714 | ROAR_ERR("No DECnet support compiled in!"); |
---|
| 1715 | return 1; |
---|
| 1716 | #endif |
---|
[1494] | 1717 | #endif |
---|
[2530] | 1718 | } else if ( strcmp(k, "--new-sock") == 0 ) { |
---|
| 1719 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[3252] | 1720 | if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) { |
---|
[2530] | 1721 | ROAR_ERR("Can not open listen socket!"); |
---|
| 1722 | return 1; |
---|
| 1723 | } |
---|
| 1724 | #endif |
---|
[518] | 1725 | |
---|
[1993] | 1726 | } else if ( strcmp(k, "--slp") == 0 ) { |
---|
| 1727 | #ifdef ROAR_HAVE_LIBSLP |
---|
| 1728 | reg_slp = 1; |
---|
| 1729 | #else |
---|
[3373] | 1730 | ROAR_ERR("No OpenSLP support compiled in!"); |
---|
| 1731 | return 1; |
---|
[1993] | 1732 | #endif |
---|
| 1733 | |
---|
[3373] | 1734 | } else if ( strcmp(k, "--x11") == 0 ) { |
---|
| 1735 | #ifdef ROAR_HAVE_LIBX11 |
---|
| 1736 | reg_x11 = 1; |
---|
| 1737 | #else |
---|
| 1738 | ROAR_ERR("No X11 support compiled in!"); |
---|
| 1739 | return 1; |
---|
| 1740 | #endif |
---|
| 1741 | |
---|
| 1742 | |
---|
[3039] | 1743 | } else if ( strcmp(k, "--jumbo-mtu") == 0 ) { |
---|
| 1744 | g_config->jumbo_mtu = atoi(argv[++i]); |
---|
| 1745 | |
---|
[60] | 1746 | } else if ( strcmp(k, "-G") == 0 ) { |
---|
[444] | 1747 | sock_grp = argv[++i]; |
---|
| 1748 | } else if ( strcmp(k, "-U") == 0 ) { |
---|
| 1749 | sock_user = argv[++i]; |
---|
[0] | 1750 | |
---|
[68] | 1751 | } else if ( strcmp(k, "--no-listen") == 0 ) { |
---|
[1494] | 1752 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 1753 | sock_addr = ""; |
---|
[548] | 1754 | g_terminate = 1; |
---|
[1155] | 1755 | g_no_listen = 1; |
---|
[1494] | 1756 | #endif |
---|
[68] | 1757 | } else if ( strcmp(k, "--client-fh") == 0 ) { |
---|
[3737] | 1758 | if ( clients_new_from_fh(atoi(argv[++i]), ROAR_PROTO_ROARAUDIO, ROAR_BYTEORDER_NETWORK, 1) == -1 ) { |
---|
[68] | 1759 | ROAR_ERR("main(*): Can not set client's fh"); |
---|
| 1760 | return 1; |
---|
| 1761 | } |
---|
[501] | 1762 | } else if ( strcmp(k, "--close-fh") == 0 ) { |
---|
[1486] | 1763 | #ifdef ROAR_HAVE_IO_POSIX |
---|
[501] | 1764 | close(atoi(argv[++i])); |
---|
[1486] | 1765 | #else |
---|
| 1766 | i++; |
---|
| 1767 | ROAR_WARN("can not close file handle %s (closing not supported)", argv[i]); |
---|
| 1768 | #endif |
---|
[68] | 1769 | |
---|
[920] | 1770 | } else if ( strcmp(k, "--standby") == 0 ) { |
---|
| 1771 | g_standby = 1; |
---|
| 1772 | } else if ( strcmp(k, "--auto-standby") == 0 ) { |
---|
| 1773 | g_autostandby = 1; |
---|
[0] | 1774 | } else { |
---|
| 1775 | usage(); |
---|
| 1776 | return 1; |
---|
| 1777 | } |
---|
| 1778 | |
---|
| 1779 | } |
---|
[1503] | 1780 | #endif |
---|
[0] | 1781 | |
---|
[2485] | 1782 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[1110] | 1783 | if ( s_dev != NULL ) { |
---|
| 1784 | if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) { |
---|
| 1785 | ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv); |
---|
| 1786 | } |
---|
| 1787 | } |
---|
[2485] | 1788 | #endif |
---|
[1110] | 1789 | |
---|
[1145] | 1790 | add_output(o_drv, o_dev, o_opts, o_prim, o_count); |
---|
[932] | 1791 | |
---|
[0] | 1792 | ROAR_DBG("Server config: rate=%i, bits=%i, chans=%i", sa.rate, sa.bits, sa.channels); |
---|
| 1793 | |
---|
[2945] | 1794 | if ( waveform_init() == -1 ) { |
---|
| 1795 | ROAR_ERR("Can not initialize Waveform subsystem"); |
---|
| 1796 | return 1; |
---|
| 1797 | } |
---|
| 1798 | |
---|
[2500] | 1799 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[1819] | 1800 | if ( midi_init() == -1 ) { |
---|
[281] | 1801 | ROAR_ERR("Can not initialize MIDI subsystem"); |
---|
[1819] | 1802 | } |
---|
[2500] | 1803 | #endif |
---|
[1819] | 1804 | |
---|
[2489] | 1805 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
[2451] | 1806 | if ( ssynth_init() == -1 ) { |
---|
| 1807 | ROAR_ERR("Can not initialize ssynth subsystem"); |
---|
| 1808 | } |
---|
[2489] | 1809 | #endif |
---|
[2451] | 1810 | |
---|
[2494] | 1811 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1819] | 1812 | if ( light_init(light_channels) == -1 ) { |
---|
| 1813 | ROAR_ERR("Can not initialize light control subsystem"); |
---|
| 1814 | } |
---|
[2494] | 1815 | #endif |
---|
[281] | 1816 | |
---|
[2718] | 1817 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1818 | if ( rdtcs_init() == -1 ) { |
---|
| 1819 | ROAR_ERR("Can not initialize RDTCS subsystem"); |
---|
| 1820 | } |
---|
| 1821 | #endif |
---|
| 1822 | |
---|
[3354] | 1823 | if ( plugins_init() == -1 ) { |
---|
| 1824 | ROAR_ERR("Can not initialize plugins"); |
---|
| 1825 | } |
---|
| 1826 | |
---|
[1494] | 1827 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[3760] | 1828 | if ( !g_no_listen ) { |
---|
| 1829 | if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) { |
---|
| 1830 | ROAR_ERR("Can not open listen socket!"); |
---|
| 1831 | return 1; |
---|
| 1832 | } |
---|
[60] | 1833 | } |
---|
[1494] | 1834 | #endif |
---|
[60] | 1835 | |
---|
[0] | 1836 | if ( output_buffer_init(&sa) == -1 ) { |
---|
| 1837 | ROAR_ERR("Can not init output buffer!"); |
---|
| 1838 | return 1; |
---|
| 1839 | } |
---|
| 1840 | |
---|
[1145] | 1841 | if ( driver == NULL ) { |
---|
| 1842 | driver = "null"; |
---|
| 1843 | } else { |
---|
| 1844 | ROAR_WARN("Usage of old driver interface. use -o not -d!"); |
---|
| 1845 | } |
---|
| 1846 | |
---|
[0] | 1847 | if ( driver_open(&drvinst, &drvid, driver, device, &sa) == -1 ) { |
---|
| 1848 | ROAR_ERR("Can not open output driver!"); |
---|
| 1849 | return 1; |
---|
| 1850 | } |
---|
| 1851 | |
---|
[44] | 1852 | if ( samples_init() == -1 ) { |
---|
| 1853 | ROAR_ERR("Can not init samples!"); |
---|
| 1854 | return 1; |
---|
| 1855 | } |
---|
| 1856 | |
---|
| 1857 | |
---|
[1486] | 1858 | // we should handle this on microcontrollers, too. |
---|
[1753] | 1859 | #if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_TARGET_WIN32) |
---|
[0] | 1860 | signal(SIGINT, on_sig_int); |
---|
[2732] | 1861 | signal(SIGTERM, on_sig_term); |
---|
[285] | 1862 | signal(SIGCHLD, on_sig_chld); |
---|
[2112] | 1863 | signal(SIGUSR1, on_sig_usr1); |
---|
[0] | 1864 | signal(SIGPIPE, SIG_IGN); // ignore broken pipes |
---|
[1486] | 1865 | #endif |
---|
[0] | 1866 | |
---|
[275] | 1867 | if ( realtime ) { |
---|
[278] | 1868 | #ifdef DEBUG |
---|
| 1869 | ROAR_WARN("compiled with -DDEBUG but realtime is enabled: for real realtime support compiel without -DDEBUG"); |
---|
| 1870 | #endif |
---|
| 1871 | |
---|
[1486] | 1872 | #ifdef ROAR_HAVE_NICE |
---|
[275] | 1873 | errno = 0; |
---|
[276] | 1874 | nice(-5*realtime); // -5 for each --realtime |
---|
[1486] | 1875 | if ( errno ) { |
---|
| 1876 | ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno)); |
---|
| 1877 | } |
---|
| 1878 | #else |
---|
| 1879 | ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno)); |
---|
| 1880 | #endif |
---|
[277] | 1881 | /* |
---|
[276] | 1882 | #ifdef __linux__ |
---|
[277] | 1883 | if ( ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0)) == -1 ) |
---|
| 1884 | ROAR_WARN("Can not set io priority: %s", strerror(errno)); |
---|
[276] | 1885 | #endif |
---|
[277] | 1886 | */ |
---|
[275] | 1887 | } |
---|
| 1888 | |
---|
[2756] | 1889 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[444] | 1890 | if ( setids & R_SETGID ) { |
---|
[2754] | 1891 | if ( sock_grp == NULL ) { |
---|
| 1892 | ROAR_ERR("Can not set GID if no groupname is supplied"); |
---|
| 1893 | return 1; |
---|
| 1894 | } |
---|
[2584] | 1895 | if ( (grp = getgrnam(sock_grp)) == NULL ) { |
---|
| 1896 | ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno)); |
---|
| 1897 | return 1; |
---|
| 1898 | } |
---|
[444] | 1899 | if ( setgroups(0, (const gid_t *) NULL) == -1 ) { |
---|
| 1900 | ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno)); |
---|
| 1901 | } |
---|
[523] | 1902 | if ( !grp || setgid(grp->gr_gid) == -1 ) { |
---|
[444] | 1903 | ROAR_ERR("Can not set GroupID: %s", strerror(errno)); |
---|
| 1904 | } |
---|
| 1905 | } |
---|
[1486] | 1906 | #endif |
---|
[444] | 1907 | |
---|
[0] | 1908 | |
---|
[39] | 1909 | clients_set_pid(g_self_client, getpid()); |
---|
[1753] | 1910 | #ifdef ROAR_HAVE_GETUID |
---|
[440] | 1911 | clients_set_uid(g_self_client, getuid()); |
---|
[1753] | 1912 | #endif |
---|
| 1913 | #ifdef ROAR_HAVE_GETGID |
---|
[440] | 1914 | clients_set_gid(g_self_client, getgid()); |
---|
[1753] | 1915 | #endif |
---|
[39] | 1916 | clients_get(g_self_client, &self); |
---|
[37] | 1917 | |
---|
[39] | 1918 | if ( self == NULL ) { |
---|
| 1919 | ROAR_ERR("Can not get self client!"); |
---|
| 1920 | return 1; |
---|
| 1921 | } |
---|
| 1922 | |
---|
[775] | 1923 | strcpy(self->name, "RoarAudio daemon internal"); |
---|
[68] | 1924 | |
---|
[2815] | 1925 | if ( roar_nnode_free(&(self->nnode)) == -1 ) |
---|
| 1926 | return 1; |
---|
| 1927 | |
---|
| 1928 | // not fully correct but ok as workaorund |
---|
| 1929 | // so tools assume that roard runs on the same machine as |
---|
| 1930 | // they in case they use AF_UNIX: |
---|
| 1931 | if ( roar_nnode_new(&(self->nnode), ROAR_SOCKET_TYPE_UNIX) == -1 ) |
---|
| 1932 | return 1; |
---|
| 1933 | |
---|
[1486] | 1934 | #ifdef ROAR_HAVE_FORK |
---|
[775] | 1935 | if ( daemon ) { |
---|
[3613] | 1936 | #ifdef ROAR_HAVE_SYSLOG |
---|
| 1937 | roar_debug_set_stderr_mode(ROAR_DEBUG_MODE_SYSLOG); |
---|
| 1938 | #else |
---|
[3609] | 1939 | roar_debug_set_stderr_fh(-1); |
---|
[3613] | 1940 | #endif |
---|
[3609] | 1941 | |
---|
[68] | 1942 | close(ROAR_STDIN ); |
---|
| 1943 | close(ROAR_STDOUT); |
---|
| 1944 | close(ROAR_STDERR); |
---|
[1753] | 1945 | |
---|
[68] | 1946 | if ( fork() ) |
---|
[1486] | 1947 | ROAR_U_EXIT(0); |
---|
[1753] | 1948 | |
---|
| 1949 | #ifdef ROAR_HAVE_SETSID |
---|
| 1950 | setsid(); |
---|
| 1951 | #endif |
---|
[1046] | 1952 | clients_set_pid(g_self_client, getpid()); // reset pid as it changed |
---|
[68] | 1953 | } |
---|
[1486] | 1954 | #endif |
---|
[68] | 1955 | |
---|
[2757] | 1956 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
| 1957 | // early test for UID as we need this for the pidfile and the setuid() |
---|
| 1958 | if ( sock_user != NULL ) { |
---|
| 1959 | if ( (pwd = getpwnam(sock_user)) == NULL ) { |
---|
| 1960 | ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno)); |
---|
| 1961 | return 1; |
---|
| 1962 | } |
---|
| 1963 | } |
---|
| 1964 | #endif |
---|
| 1965 | |
---|
[2104] | 1966 | #ifdef SUPPORT_PIDFILE |
---|
[2106] | 1967 | if ( pidfile != NULL ) { |
---|
| 1968 | if ( roar_vio_open_file(&pidfile_vio, pidfile, O_WRONLY|O_CREAT, 0644) == -1 ) { |
---|
| 1969 | ROAR_ERR("Can not write pidfile: %s", pidfile); |
---|
| 1970 | } else { |
---|
| 1971 | roar_vio_printf(&pidfile_vio, "%i\n", getpid()); |
---|
| 1972 | roar_vio_close(&pidfile_vio); |
---|
| 1973 | } |
---|
[2765] | 1974 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[2759] | 1975 | if ( pwd || grp ) { |
---|
| 1976 | if ( chown(pidfile, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 ) { |
---|
| 1977 | ROAR_WARN("Can not change ownership of pidfile: %s: %s", pidfile, strerror(errno)); |
---|
| 1978 | } |
---|
| 1979 | } |
---|
| 1980 | if ( chmod(pidfile, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1 ) { |
---|
| 1981 | ROAR_WARN("Can not change permissions of pidfile: %s: %s", pidfile, strerror(errno)); |
---|
| 1982 | } |
---|
[2765] | 1983 | #endif |
---|
[2104] | 1984 | } |
---|
| 1985 | #endif |
---|
| 1986 | |
---|
[1486] | 1987 | #ifdef ROAR_HAVE_CHROOT |
---|
[444] | 1988 | if (chrootdir) { |
---|
| 1989 | if ( chroot(chrootdir) == -1 ) { |
---|
| 1990 | ROAR_ERR("Can not chroot to %s: %s", chrootdir, strerror(errno)); |
---|
| 1991 | return 2; |
---|
| 1992 | } |
---|
| 1993 | if ( chdir("/") == -1 ) { |
---|
| 1994 | ROAR_ERR("Can not chdir to /: %s", strerror(errno)); |
---|
| 1995 | return 2; |
---|
| 1996 | } |
---|
| 1997 | } |
---|
[1486] | 1998 | #endif |
---|
[444] | 1999 | |
---|
[2756] | 2000 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[444] | 2001 | if ( setids & R_SETUID ) { |
---|
[2752] | 2002 | if ( sock_user == NULL ) { |
---|
| 2003 | ROAR_ERR("Can not set UID if no username is supplied"); |
---|
| 2004 | return 1; |
---|
| 2005 | } |
---|
[444] | 2006 | if ( !pwd || setuid(pwd->pw_uid) == -1 ) { |
---|
| 2007 | ROAR_ERR("Can not set UserID: %s", strerror(errno)); |
---|
| 2008 | return 3; |
---|
| 2009 | } |
---|
[1753] | 2010 | #ifdef ROAR_HAVE_GETUID |
---|
[444] | 2011 | clients_set_uid(g_self_client, getuid()); |
---|
[1753] | 2012 | #endif |
---|
[444] | 2013 | } |
---|
[1486] | 2014 | #endif |
---|
[444] | 2015 | |
---|
[1993] | 2016 | // Register with OpenSLP: |
---|
[2028] | 2017 | #ifdef ROAR_HAVE_LIBSLP |
---|
[1993] | 2018 | if ( reg_slp ) { |
---|
[2530] | 2019 | register_slp(0, sock_addr); |
---|
[1993] | 2020 | } |
---|
[2028] | 2021 | #endif |
---|
[1993] | 2022 | |
---|
[3373] | 2023 | #ifdef ROAR_HAVE_LIBX11 |
---|
| 2024 | if ( reg_x11 ) { |
---|
| 2025 | register_x11(0, sock_addr); |
---|
| 2026 | } |
---|
| 2027 | #endif |
---|
| 2028 | |
---|
[0] | 2029 | // start main loop... |
---|
[905] | 2030 | main_loop(drvid, drvinst, &sa, sysclocksync); |
---|
[0] | 2031 | |
---|
| 2032 | // clean up. |
---|
| 2033 | clean_quit_prep(); |
---|
| 2034 | driver_close(drvinst, drvid); |
---|
| 2035 | output_buffer_free(); |
---|
| 2036 | |
---|
| 2037 | return 0; |
---|
| 2038 | } |
---|
| 2039 | |
---|
[574] | 2040 | void cleanup_listen_socket (int terminate) { |
---|
[2530] | 2041 | int i; |
---|
| 2042 | |
---|
[1993] | 2043 | // Deregister from SLP: |
---|
[2028] | 2044 | #ifdef ROAR_HAVE_LIBSLP |
---|
[1993] | 2045 | register_slp(1, NULL); |
---|
[2028] | 2046 | #endif |
---|
[580] | 2047 | |
---|
[3373] | 2048 | #ifdef ROAR_HAVE_LIBX11 |
---|
| 2049 | register_x11(1, NULL); |
---|
| 2050 | #endif |
---|
| 2051 | |
---|
[1494] | 2052 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[2530] | 2053 | for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) { |
---|
[3802] | 2054 | if ( g_listen[i].used ) { |
---|
| 2055 | roar_vio_close(&(g_listen[i].sock)); |
---|
[60] | 2056 | |
---|
[3802] | 2057 | g_listen[i].used = 0; |
---|
[576] | 2058 | |
---|
[1486] | 2059 | #ifdef ROAR_HAVE_UNIX |
---|
[2530] | 2060 | if ( server[i] != NULL ) |
---|
| 2061 | if ( *(server[i]) == '/' ) |
---|
| 2062 | unlink(server[i]); |
---|
[1486] | 2063 | #endif |
---|
[2530] | 2064 | } |
---|
[580] | 2065 | } |
---|
[60] | 2066 | |
---|
[1494] | 2067 | #endif |
---|
| 2068 | |
---|
[574] | 2069 | if ( terminate ) |
---|
| 2070 | g_terminate = 1; |
---|
| 2071 | } |
---|
| 2072 | |
---|
| 2073 | void clean_quit_prep (void) { |
---|
| 2074 | cleanup_listen_socket(0); |
---|
[60] | 2075 | |
---|
[3354] | 2076 | plugins_free(); |
---|
| 2077 | |
---|
[2485] | 2078 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
[0] | 2079 | sources_free(); |
---|
[2485] | 2080 | #endif |
---|
[0] | 2081 | streams_free(); |
---|
| 2082 | clients_free(); |
---|
[2489] | 2083 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
[2451] | 2084 | ssynth_free(); |
---|
[2489] | 2085 | #endif |
---|
[2487] | 2086 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
[282] | 2087 | midi_cb_stop(); // stop console beep |
---|
[2487] | 2088 | #endif |
---|
[2500] | 2089 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[281] | 2090 | midi_free(); |
---|
[2500] | 2091 | #endif |
---|
[2494] | 2092 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1819] | 2093 | light_free(); |
---|
[2494] | 2094 | #endif |
---|
[2718] | 2095 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 2096 | rdtcs_free(); |
---|
| 2097 | #endif |
---|
[2104] | 2098 | |
---|
[2945] | 2099 | waveform_free(); |
---|
| 2100 | |
---|
[2104] | 2101 | #ifdef SUPPORT_PIDFILE |
---|
| 2102 | if ( pidfile != NULL ) |
---|
| 2103 | unlink(pidfile); |
---|
| 2104 | #endif |
---|
[0] | 2105 | } |
---|
| 2106 | |
---|
| 2107 | void clean_quit (void) { |
---|
| 2108 | clean_quit_prep(); |
---|
| 2109 | // driver_close(drvinst, drvid); |
---|
| 2110 | // output_buffer_free(); |
---|
| 2111 | exit(0); |
---|
| 2112 | } |
---|
| 2113 | |
---|
| 2114 | //ll |
---|