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