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