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