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