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