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