[0] | 1 | //roard.c: |
---|
| 2 | |
---|
[668] | 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
| 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 |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
[0] | 25 | #include "roard.h" |
---|
| 26 | |
---|
[1494] | 27 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[60] | 28 | char * server = ROAR_DEFAULT_SOCK_GLOBAL; // global server address |
---|
[1494] | 29 | #endif |
---|
[60] | 30 | |
---|
[1503] | 31 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 32 | void usage (void) { |
---|
| 33 | printf("Usage: roard [OPTIONS]...\n\n"); |
---|
| 34 | |
---|
[68] | 35 | printf("Misc Options:\n\n"); |
---|
| 36 | printf( |
---|
[775] | 37 | " --daemon - Bring the server into background after init\n" |
---|
[71] | 38 | " --terminate - Terminate after last client quited\n" |
---|
[274] | 39 | " --restart - Trys to stop an old instance and start a new with new settings\n" |
---|
[276] | 40 | " --realtime - Trys to get realtime priority,\n" |
---|
| 41 | " give multible times for being more realtime\n" |
---|
[444] | 42 | " --chroot DIR - chroots to the given dir\n" |
---|
| 43 | " --setgid - GroupID to the audio group as specified via -G\n" |
---|
| 44 | " --setuid - UserID to the audio user as specified via -U\n" |
---|
[905] | 45 | " --sysclocksync - calculate exact sample rate using the system clock\n" |
---|
[68] | 46 | ); |
---|
| 47 | |
---|
| 48 | printf("\nAudio Options:\n\n"); |
---|
[0] | 49 | printf( |
---|
| 50 | " -R --rate RATE - Set server rate\n" |
---|
| 51 | " -B --bits BITS - Set server bits\n" |
---|
| 52 | " -C --chans CHANNELS - Set server channels\n" |
---|
| 53 | ); |
---|
| 54 | |
---|
| 55 | printf("\nDriver Options:\n\n"); |
---|
[974] | 56 | printf(" -d --driver DRV - Set the driver (default: %s)\n", ROAR_DRIVER_DEFAULT); |
---|
[0] | 57 | printf(" -D --device DEV - Set the device\n"); |
---|
| 58 | printf(" -dO OPTS - Set output options\n"); |
---|
[973] | 59 | printf(" --list-driver - List all drivers\n"); |
---|
[0] | 60 | |
---|
[932] | 61 | printf("\nOutput Options:\n\n"); |
---|
[974] | 62 | printf(" -o --odriver DRV - Set the driver, use '--list-driver' to get a list\n"); |
---|
[932] | 63 | printf(" -O --odevice DEV - Set the device\n"); |
---|
| 64 | printf(" -oO OPTS - Set output options\n"); |
---|
| 65 | printf(" -oN - Adds another output\n"); |
---|
[961] | 66 | printf(" -oP - Mark output as primary\n"); |
---|
[932] | 67 | |
---|
[0] | 68 | printf("\nSource Options:\n\n"); |
---|
| 69 | printf(" -s --source DRV - Use DRV as input driver\n" |
---|
| 70 | " -S DEV - Use DEV as input device\n" |
---|
| 71 | " -sO OPTS - Use OPTS as input options\n" |
---|
[1512] | 72 | " -sN - Adds another source\n" |
---|
[0] | 73 | " -sP - Make souce as primary\n" |
---|
| 74 | ); |
---|
| 75 | |
---|
[280] | 76 | printf("\nCodec Filter Options:\n\n"); |
---|
| 77 | printf(" --list-cf - List all codec filter\n" |
---|
| 78 | ); |
---|
[0] | 79 | |
---|
| 80 | printf("\nServer Options:\n\n"); |
---|
| 81 | printf(" -t --tcp - Use TCP listen socket\n" |
---|
| 82 | " -u --unix - Use UNIX Domain listen socket (default)\n" |
---|
[508] | 83 | #ifdef ROAR_HAVE_LIBDNET |
---|
| 84 | " -n --decnet - use DECnet listen socket\n" |
---|
| 85 | #endif |
---|
[518] | 86 | " -4 - Use IPv4 connections (implies -t)\n" |
---|
| 87 | #ifdef PF_INET6 |
---|
| 88 | " -6 - Use IPv6 connections (implies -t)\n" |
---|
| 89 | #endif |
---|
| 90 | #ifdef IPV6_ADDRFORM |
---|
| 91 | " -64 - Try to downgrade sockets from IPv6 into IPv4,\n" |
---|
| 92 | " this is normaly not usefull.\n" |
---|
| 93 | #endif |
---|
[0] | 94 | " -p --port - TCP Port to bind to\n" |
---|
| 95 | " -b --bind - IP/Hostname to bind to\n" |
---|
[1115] | 96 | " --sock - Filename for UNIX Domain Socket\n" |
---|
[450] | 97 | " -G GROUP - Sets the group for the UNIX Domain Socket, (default: %s)\n" |
---|
[60] | 98 | " You need the permittions to change the GID\n" |
---|
[444] | 99 | " -U USER - Sets the user for the UNIX Domain Socket, (default: do not set)\n" |
---|
| 100 | " You need the permittions to change the UID (normaly only root has)\n" |
---|
[548] | 101 | " --no-listen - Do not listen for new clients\n" |
---|
| 102 | " (only usefull for relaing, impleys --terminate)\n" |
---|
[274] | 103 | " --client-fh - Comunicate with a client over this handle\n" |
---|
[501] | 104 | " (only usefull for relaing)\n" |
---|
[920] | 105 | " --close-fh - Closes the given fh\n" |
---|
| 106 | " --standby - Start in standby state\n" |
---|
| 107 | " --auto-standby - Automatical goes into standby if there are no streams\n", |
---|
[450] | 108 | ROAR_DEFAULT_SOCKGRP |
---|
[0] | 109 | ); |
---|
| 110 | // printf("\n Options:\n\n"); |
---|
| 111 | printf("\n"); |
---|
| 112 | } |
---|
[1503] | 113 | #endif |
---|
[0] | 114 | |
---|
[579] | 115 | int restart_server (char * server) { |
---|
| 116 | struct roar_connection con; |
---|
| 117 | if ( roar_connect(&con, server) == -1 ) { |
---|
| 118 | return -1; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | if ( roar_terminate(&con, 1) == -1 ) { |
---|
| 122 | return -1; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | return roar_disconnect(&con); |
---|
| 126 | } |
---|
| 127 | |
---|
[444] | 128 | #define R_SETUID 1 |
---|
| 129 | #define R_SETGID 2 |
---|
| 130 | |
---|
[1145] | 131 | int add_output (char * drv, char * dev, char * opts, int prim, int count) { |
---|
[933] | 132 | int stream; |
---|
| 133 | struct roar_stream * s; |
---|
| 134 | struct roar_stream_server * ss; |
---|
[938] | 135 | char * k, * v; |
---|
[1208] | 136 | #ifdef ROAR_DRIVER_CODEC |
---|
| 137 | char * to_free = NULL; |
---|
| 138 | #endif |
---|
[938] | 139 | int codec; |
---|
[1117] | 140 | int sync = 0; |
---|
[1522] | 141 | int32_t blocks = -1, blocksize = -1; |
---|
[933] | 142 | |
---|
[938] | 143 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
[933] | 144 | |
---|
[1145] | 145 | if ( drv == NULL && count == 0 ) { |
---|
| 146 | drv = ROAR_DRIVER_DEFAULT; |
---|
| 147 | prim = 1; |
---|
| 148 | sync = 1; |
---|
[1208] | 149 | |
---|
| 150 | #ifdef ROAR_DRIVER_CODEC |
---|
| 151 | if ( opts == NULL ) { |
---|
| 152 | opts = to_free = strdup("codec=" ROAR_DRIVER_CODEC); |
---|
| 153 | } |
---|
| 154 | #endif |
---|
[1145] | 155 | } |
---|
| 156 | |
---|
[1227] | 157 | if ( opts == NULL && count == 0 ) { |
---|
| 158 | sync = 1; |
---|
| 159 | prim = 1; // if ( prim == 0 ) prim = 1; -> prim allways = 1 |
---|
| 160 | } |
---|
| 161 | |
---|
[933] | 162 | if ( (stream = streams_new()) == -1 ) { |
---|
[938] | 163 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts); |
---|
[982] | 164 | if ( prim ) alive = 0; |
---|
[933] | 165 | return -1; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | streams_get(stream, &ss); |
---|
| 169 | s = ROAR_STREAM(ss); |
---|
| 170 | |
---|
| 171 | memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info)); |
---|
| 172 | |
---|
| 173 | s->dir = ROAR_DIR_OUTPUT; |
---|
| 174 | s->pos_rel_id = -1; |
---|
| 175 | // s->info.codec = codec; |
---|
| 176 | |
---|
[938] | 177 | codec = s->info.codec; |
---|
| 178 | |
---|
| 179 | k = strtok(opts, ","); |
---|
| 180 | while (k != NULL) { |
---|
| 181 | // ROAR_WARN("add_output(*): opts: %s", k); |
---|
| 182 | |
---|
| 183 | if ( (v = strstr(k, "=")) != NULL ) { |
---|
| 184 | *v++ = 0; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | ROAR_DBG("add_output(*): opts: k='%s', v='%s'", k, v); |
---|
| 188 | if ( strcmp(k, "rate") == 0 ) { |
---|
| 189 | s->info.rate = atoi(v); |
---|
| 190 | } else if ( strcmp(k, "channels") == 0 ) { |
---|
| 191 | s->info.channels = atoi(v); |
---|
| 192 | } else if ( strcmp(k, "bits") == 0 ) { |
---|
| 193 | s->info.bits = atoi(v); |
---|
| 194 | } else if ( strcmp(k, "codec") == 0 ) { |
---|
| 195 | if ( (codec = roar_str2codec(v)) == -1 ) { |
---|
| 196 | ROAR_ERR("add_output(*): unknown codec '%s'", v); |
---|
| 197 | streams_delete(stream); |
---|
[982] | 198 | if ( prim ) alive = 0; |
---|
[1208] | 199 | #ifdef ROAR_DRIVER_CODEC |
---|
| 200 | if ( to_free != NULL ) |
---|
| 201 | free(to_free); |
---|
| 202 | #endif |
---|
[938] | 203 | return -1; |
---|
| 204 | } |
---|
[1221] | 205 | } else if ( strcmp(k, "blocks") == 0 ) { |
---|
| 206 | blocks = atoi(v); |
---|
[1522] | 207 | } else if ( strcmp(k, "blocksize") == 0 ) { |
---|
| 208 | blocksize = atoi(v); |
---|
[1032] | 209 | } else if ( strcmp(k, "meta") == 0 ) { |
---|
| 210 | streams_set_flag(stream, ROAR_FLAG_META); |
---|
[1117] | 211 | } else if ( strcmp(k, "sync") == 0 ) { |
---|
| 212 | sync = 1; |
---|
[1221] | 213 | } else if ( strcmp(k, "primary") == 0 ) { |
---|
| 214 | prim = 1; |
---|
| 215 | |
---|
| 216 | } else if ( strcmp(k, "cleanmeta") == 0 ) { |
---|
| 217 | streams_set_flag(stream, ROAR_FLAG_CLEANMETA); |
---|
| 218 | } else if ( strcmp(k, "autoconf") == 0 ) { |
---|
[1531] | 219 | streams_set_flag(stream, ROAR_FLAG_AUTOCONF); |
---|
[938] | 220 | } else { |
---|
| 221 | ROAR_ERR("add_output(*): unknown option '%s'", k); |
---|
| 222 | streams_delete(stream); |
---|
[982] | 223 | if ( prim ) alive = 0; |
---|
[1208] | 224 | #ifdef ROAR_DRIVER_CODEC |
---|
| 225 | if ( to_free != NULL ) |
---|
| 226 | free(to_free); |
---|
| 227 | #endif |
---|
[938] | 228 | return -1; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | k = strtok(NULL, ","); |
---|
| 232 | } |
---|
| 233 | |
---|
[1208] | 234 | #ifdef ROAR_DRIVER_CODEC |
---|
| 235 | if ( to_free != NULL ) |
---|
| 236 | free(to_free); |
---|
| 237 | #endif |
---|
| 238 | |
---|
[941] | 239 | if ( codec == ROAR_CODEC_ALAW || codec == ROAR_CODEC_MULAW ) |
---|
| 240 | s->info.bits = 8; // needed to open OSS driver, will be overriden by codecfilter |
---|
| 241 | |
---|
[938] | 242 | s->info.codec = codec; |
---|
| 243 | ROAR_STREAM_SERVER(s)->codec_orgi = codec; |
---|
[933] | 244 | |
---|
[1145] | 245 | if ( driver_openvio(&(ss->vio), &(ss->driver_id), drv, dev, &(s->info), -1) == -1 ) { |
---|
[933] | 246 | streams_delete(stream); |
---|
[938] | 247 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts); |
---|
[982] | 248 | if ( prim ) alive = 0; |
---|
[933] | 249 | return -1; |
---|
| 250 | } |
---|
| 251 | |
---|
[1528] | 252 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAMID, &stream); // ignore errors here |
---|
| 253 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAM, s); // ignore errors here |
---|
| 254 | |
---|
[1221] | 255 | if ( blocks != -1 ) |
---|
| 256 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLOCKS, &blocks); |
---|
| 257 | |
---|
[1522] | 258 | if ( blocksize != -1 ) |
---|
| 259 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLKSIZE, &blocksize); |
---|
| 260 | |
---|
[1156] | 261 | ROAR_DBG("add_output(*): ss->driver_id=%i", ss->driver_id); |
---|
| 262 | |
---|
[938] | 263 | streams_set_fh(stream, -1); // update some internal structures |
---|
| 264 | |
---|
[933] | 265 | client_stream_add(g_source_client, stream); |
---|
| 266 | |
---|
[1200] | 267 | if ( prim ) { |
---|
[961] | 268 | streams_mark_primary(stream); |
---|
[1200] | 269 | s->pos_rel_id = stream; |
---|
| 270 | } |
---|
[961] | 271 | |
---|
[1120] | 272 | if ( sync ) { |
---|
[1117] | 273 | streams_set_flag(stream, ROAR_FLAG_SYNC); |
---|
[1120] | 274 | } else { |
---|
| 275 | streams_reset_flag(stream, ROAR_FLAG_SYNC); |
---|
| 276 | } |
---|
[1117] | 277 | |
---|
[933] | 278 | return 0; |
---|
[932] | 279 | } |
---|
| 280 | |
---|
[1503] | 281 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 282 | int main (int argc, char * argv[]) { |
---|
[1503] | 283 | #else |
---|
| 284 | int main (void) { |
---|
| 285 | #endif |
---|
| 286 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 287 | int i; |
---|
| 288 | char * k; |
---|
[1503] | 289 | #endif |
---|
[1494] | 290 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[905] | 291 | char user_sock[80] = {0}; |
---|
[1494] | 292 | #endif |
---|
[0] | 293 | struct roar_audio_info sa; |
---|
[1486] | 294 | #ifdef ROAR_HAVE_FORK |
---|
[905] | 295 | int daemon = 0; |
---|
[1486] | 296 | #endif |
---|
[905] | 297 | int realtime = 0; |
---|
| 298 | int sysclocksync = 0; |
---|
[1207] | 299 | char * driver = NULL; |
---|
| 300 | char * device = NULL; |
---|
[1503] | 301 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[1207] | 302 | char * opts = NULL; |
---|
[1503] | 303 | #endif |
---|
[60] | 304 | // char * server = ROAR_DEFAULT_SOCK_GLOBAL; |
---|
[1494] | 305 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[1207] | 306 | int port = ROAR_DEFAULT_PORT; |
---|
[1494] | 307 | #endif |
---|
[0] | 308 | int drvid; |
---|
[550] | 309 | char * s_drv = "cf"; |
---|
[1110] | 310 | char * s_dev = NULL; |
---|
[444] | 311 | char * s_con = NULL; |
---|
| 312 | char * s_opt = NULL; |
---|
| 313 | int s_prim = 0; |
---|
[1207] | 314 | char * o_drv = getenv("ROAR_DRIVER"); |
---|
| 315 | char * o_dev = getenv("ROAR_DEVICE"); |
---|
[932] | 316 | char * o_opts = NULL; |
---|
[961] | 317 | int o_prim = 0; |
---|
[1145] | 318 | int o_count = 0; |
---|
[450] | 319 | char * sock_grp = ROAR_DEFAULT_SOCKGRP; |
---|
[444] | 320 | char * sock_user = NULL; |
---|
[1494] | 321 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[517] | 322 | int sock_type = ROAR_SOCKET_TYPE_UNKNOWN; |
---|
[1494] | 323 | #endif |
---|
[1486] | 324 | #ifdef ROAR_HAVE_CHROOT |
---|
[444] | 325 | char * chrootdir = NULL; |
---|
[1486] | 326 | #endif |
---|
| 327 | #if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID) |
---|
[444] | 328 | int setids = 0; |
---|
[1486] | 329 | #endif |
---|
| 330 | #ifdef ROAR_HAVE_UNIX |
---|
[1011] | 331 | char * env_roar_proxy_backup; |
---|
[1486] | 332 | #endif |
---|
| 333 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[446] | 334 | struct group * grp = NULL; |
---|
[1486] | 335 | #endif |
---|
| 336 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[446] | 337 | struct passwd * pwd = NULL; |
---|
[1486] | 338 | #endif |
---|
| 339 | #ifdef ROAR_HAVE_GETSERVBYNAME |
---|
[446] | 340 | struct servent * serv = NULL; |
---|
[1486] | 341 | #endif |
---|
[0] | 342 | DRIVER_USERDATA_T drvinst; |
---|
[39] | 343 | struct roar_client * self = NULL; |
---|
[508] | 344 | #ifdef ROAR_HAVE_LIBDNET |
---|
| 345 | char decnethost[80]; |
---|
| 346 | #endif |
---|
[0] | 347 | |
---|
| 348 | g_standby = 0; |
---|
[920] | 349 | g_autostandby = 0; |
---|
[982] | 350 | alive = 1; |
---|
[1494] | 351 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[1155] | 352 | g_no_listen = 0; |
---|
[1494] | 353 | g_listen_socket = -1; |
---|
| 354 | #else |
---|
| 355 | g_terminate = 1; |
---|
| 356 | #endif |
---|
[0] | 357 | |
---|
| 358 | sa.bits = ROAR_BITS_DEFAULT; |
---|
| 359 | sa.channels = ROAR_CHANNELS_DEFAULT; |
---|
| 360 | sa.rate = ROAR_RATE_DEFAULT; |
---|
| 361 | sa.codec = ROAR_CODEC_DEFAULT; |
---|
| 362 | |
---|
| 363 | g_sa = &sa; |
---|
| 364 | |
---|
[60] | 365 | |
---|
[1494] | 366 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[1486] | 367 | if ( getuid() != 0 && getenv("HOME") != NULL ) { |
---|
| 368 | snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER); |
---|
[60] | 369 | server = user_sock; |
---|
| 370 | } |
---|
| 371 | |
---|
[279] | 372 | if ( getenv("ROAR_SERVER") != NULL ) |
---|
| 373 | server = getenv("ROAR_SERVER"); |
---|
[1494] | 374 | #endif |
---|
[279] | 375 | |
---|
[63] | 376 | if ( clients_init() == -1 ) { |
---|
| 377 | ROAR_ERR("Can not init clients!"); |
---|
| 378 | return 1; |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | if ( streams_init() == -1 ) { |
---|
| 382 | ROAR_ERR("Can not init streams!"); |
---|
| 383 | return 1; |
---|
| 384 | } |
---|
| 385 | |
---|
[64] | 386 | if ( (g_self_client = clients_new()) == -1 ) { |
---|
| 387 | ROAR_ERR("Can not create self client!"); |
---|
| 388 | return 1; |
---|
| 389 | } |
---|
| 390 | |
---|
[0] | 391 | if ( sources_init() == -1 ) { |
---|
| 392 | ROAR_ERR("Can not init sources!"); |
---|
| 393 | return 1; |
---|
| 394 | } |
---|
| 395 | |
---|
[64] | 396 | if ( (sources_set_client(g_self_client)) == -1 ) { |
---|
| 397 | ROAR_ERR("Can not init set source client!"); |
---|
| 398 | return 1; |
---|
| 399 | } |
---|
| 400 | |
---|
[1503] | 401 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 402 | for (i = 1; i < argc; i++) { |
---|
| 403 | k = argv[i]; |
---|
| 404 | |
---|
| 405 | if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) { |
---|
| 406 | usage(); |
---|
| 407 | return 0; |
---|
| 408 | |
---|
[579] | 409 | } else if ( strcmp(k, "--restart") == 0 ) { |
---|
[1494] | 410 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[579] | 411 | if ( restart_server(server) == -1 ) { |
---|
| 412 | ROAR_WARN("Can not terminate old server (not running at %s?), tring to continue anyway", server); |
---|
| 413 | } |
---|
[1494] | 414 | #else |
---|
| 415 | ROAR_ERR("--restart not supported"); |
---|
| 416 | #endif |
---|
[579] | 417 | |
---|
[775] | 418 | } else if ( strcmp(k, "--demon") == 0 || strcmp(k, "--daemon") == 0 ) { |
---|
[1486] | 419 | #ifdef ROAR_HAVE_FORK |
---|
[775] | 420 | daemon = 1; |
---|
[1486] | 421 | #else |
---|
| 422 | ROAR_ERR("--daemon not supported"); |
---|
| 423 | #endif |
---|
[71] | 424 | } else if ( strcmp(k, "--terminate") == 0 ) { |
---|
| 425 | g_terminate = 1; |
---|
[905] | 426 | } else if ( strcmp(k, "--sysclocksync") == 0 ) { |
---|
| 427 | sysclocksync = 1000; |
---|
[275] | 428 | } else if ( strcmp(k, "--realtime") == 0 ) { |
---|
[276] | 429 | realtime++; |
---|
[444] | 430 | } else if ( strcmp(k, "--chroot") == 0 ) { |
---|
[1486] | 431 | #ifdef ROAR_HAVE_CHROOT |
---|
[444] | 432 | chrootdir = argv[++i]; |
---|
[1486] | 433 | #else |
---|
| 434 | ROAR_ERR("--chroot not supported"); |
---|
| 435 | i++; |
---|
| 436 | #endif |
---|
[444] | 437 | } else if ( strcmp(k, "--setgid") == 0 ) { |
---|
[1486] | 438 | #ifdef ROAR_HAVE_SETGID |
---|
[444] | 439 | setids |= R_SETGID; |
---|
[1486] | 440 | #else |
---|
| 441 | ROAR_ERR("--setgid not supported"); |
---|
| 442 | #endif |
---|
[444] | 443 | } else if ( strcmp(k, "--setuid") == 0 ) { |
---|
[1486] | 444 | #ifdef ROAR_HAVE_SETUID |
---|
[444] | 445 | setids |= R_SETUID; |
---|
[1486] | 446 | #else |
---|
| 447 | ROAR_ERR("--setuid not supported"); |
---|
| 448 | #endif |
---|
[68] | 449 | |
---|
[280] | 450 | } else if ( strcmp(k, "--list-cf") == 0 ) { |
---|
| 451 | print_codecfilterlist(); |
---|
| 452 | return 0; |
---|
| 453 | |
---|
[0] | 454 | } else if ( strcmp(k, "-R") == 0 || strcmp(k, "--rate") == 0 ) { |
---|
| 455 | sa.rate = atoi(argv[++i]); |
---|
| 456 | } else if ( strcmp(k, "-B") == 0 || strcmp(k, "--bits") == 0 ) { |
---|
| 457 | sa.bits = atoi(argv[++i]); |
---|
| 458 | } else if ( strcmp(k, "-C") == 0 || strcmp(k, "--chans") == 0 ) { |
---|
| 459 | sa.channels = atoi(argv[++i]); |
---|
| 460 | |
---|
| 461 | } else if ( strcmp(k, "-d") == 0 || strcmp(k, "--driver") == 0 ) { |
---|
| 462 | driver = argv[++i]; |
---|
| 463 | if ( strcmp(driver, "list") == 0 ) { |
---|
[974] | 464 | ROAR_WARN("The option is obsolete, use --list-driver!"); |
---|
[0] | 465 | print_driverlist(); |
---|
[973] | 466 | return 0; |
---|
[0] | 467 | } |
---|
| 468 | } else if ( strcmp(k, "-D") == 0 || strcmp(k, "--device") == 0 ) { |
---|
| 469 | device = argv[++i]; |
---|
| 470 | } else if ( strcmp(k, "-dO") == 0 ) { |
---|
| 471 | opts = argv[++i]; |
---|
[973] | 472 | } else if ( strcmp(k, "--list-driver") == 0 ) { |
---|
| 473 | print_driverlist(); |
---|
| 474 | return 0; |
---|
[0] | 475 | |
---|
[932] | 476 | } else if ( strcmp(k, "-o") == 0 || strcmp(k, "--odriver") == 0 ) { |
---|
| 477 | o_drv = argv[++i]; |
---|
| 478 | } else if ( strcmp(k, "-O") == 0 || strcmp(k, "--odevice") == 0 ) { |
---|
| 479 | o_dev = argv[++i]; |
---|
| 480 | } else if ( strcmp(k, "-oO") == 0 ) { |
---|
| 481 | o_opts = argv[++i]; |
---|
[961] | 482 | } else if ( strcmp(k, "-oP") == 0 ) { |
---|
| 483 | o_prim = 1; |
---|
[932] | 484 | } else if ( strcmp(k, "-oN") == 0 ) { |
---|
[1145] | 485 | if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 ) |
---|
| 486 | o_count++; |
---|
| 487 | |
---|
[961] | 488 | o_drv = o_dev = o_opts = NULL; |
---|
| 489 | o_prim = 0; |
---|
[932] | 490 | |
---|
[0] | 491 | } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) { |
---|
[550] | 492 | s_drv = argv[++i]; |
---|
| 493 | } else if ( strcmp(k, "-S") == 0 ) { |
---|
[1110] | 494 | s_dev = argv[++i]; |
---|
[0] | 495 | } else if ( strcmp(k, "-sO") == 0 ) { |
---|
| 496 | s_opt = argv[++i]; |
---|
| 497 | } else if ( strcmp(k, "-sC") == 0 ) { |
---|
| 498 | s_con = argv[++i]; |
---|
| 499 | } else if ( strcmp(k, "-sP") == 0 ) { |
---|
| 500 | s_prim = 1; |
---|
[1110] | 501 | } else if ( strcmp(k, "-sN") == 0 ) { |
---|
| 502 | if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) { |
---|
| 503 | ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv); |
---|
| 504 | } |
---|
| 505 | s_opt = s_dev = s_con = NULL; |
---|
| 506 | s_drv = "cf"; |
---|
| 507 | s_prim = 0; |
---|
[0] | 508 | |
---|
| 509 | } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--port") == 0 ) { |
---|
[447] | 510 | // This is only usefull in INET not UNIX mode. |
---|
[1494] | 511 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[447] | 512 | if ( *server == '/' ) |
---|
| 513 | server = ROAR_DEFAULT_HOST; |
---|
| 514 | |
---|
[446] | 515 | errno = 0; |
---|
| 516 | if ( (port = atoi(argv[++i])) < 1 ) { |
---|
[1486] | 517 | #ifdef ROAR_HAVE_GETSERVBYNAME |
---|
[446] | 518 | if ( (serv = getservbyname(argv[i], "tcp")) == NULL ) { |
---|
| 519 | ROAR_ERR("Unknown service: %s: %s", argv[i], strerror(errno)); |
---|
| 520 | return 1; |
---|
| 521 | } |
---|
| 522 | // NOTE: we need to use ROAR_NET2HOST16() here even if s_port is of type int! |
---|
| 523 | ROAR_DBG("main(*): serv = {s_name='%s', s_aliases={...}, s_port=%i, s_proto='%s'}", |
---|
| 524 | serv->s_name, ROAR_NET2HOST16(serv->s_port), serv->s_proto); |
---|
| 525 | port = ROAR_NET2HOST16(serv->s_port); |
---|
[1486] | 526 | #else |
---|
| 527 | ROAR_ERR("invalite port number: %s", argv[i]); |
---|
| 528 | return 1; |
---|
| 529 | #endif |
---|
[446] | 530 | } |
---|
[1494] | 531 | #endif |
---|
[1115] | 532 | } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) { |
---|
[1494] | 533 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[0] | 534 | server = argv[++i]; |
---|
[1494] | 535 | #endif |
---|
[518] | 536 | |
---|
[573] | 537 | } else if ( strcmp(k, "-t") == 0 || strcmp(k, "--tcp") == 0 ) { |
---|
[1494] | 538 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[518] | 539 | if ( sock_type != ROAR_SOCKET_TYPE_TCP && sock_type != ROAR_SOCKET_TYPE_TCP6 ) |
---|
| 540 | sock_type = ROAR_SOCKET_TYPE_TCP; |
---|
| 541 | |
---|
| 542 | if ( *server == '/' ) |
---|
| 543 | server = ROAR_DEFAULT_HOST; |
---|
[1494] | 544 | #endif |
---|
[518] | 545 | |
---|
| 546 | } else if ( strcmp(k, "-4") == 0 ) { |
---|
[1494] | 547 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[517] | 548 | sock_type = ROAR_SOCKET_TYPE_TCP; |
---|
[447] | 549 | if ( *server == '/' ) |
---|
| 550 | server = ROAR_DEFAULT_HOST; |
---|
[1494] | 551 | #endif |
---|
[518] | 552 | } else if ( strcmp(k, "-6") == 0 ) { |
---|
[1494] | 553 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[519] | 554 | #ifdef PF_INET6 |
---|
[518] | 555 | sock_type = ROAR_SOCKET_TYPE_TCP6; |
---|
| 556 | if ( *server == '/' ) |
---|
| 557 | server = ROAR_DEFAULT_HOST; |
---|
[519] | 558 | #else |
---|
| 559 | ROAR_ERR("No IPv6 support compiled in!"); |
---|
| 560 | return 1; |
---|
| 561 | #endif |
---|
[1494] | 562 | #endif |
---|
[518] | 563 | |
---|
[573] | 564 | } else if ( strcmp(k, "-u") == 0 || strcmp(k, "--unix") == 0 ) { |
---|
[1494] | 565 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[62] | 566 | // ignore this case as it is the default behavor. |
---|
[517] | 567 | sock_type = ROAR_SOCKET_TYPE_UNIX; |
---|
[1494] | 568 | #endif |
---|
[518] | 569 | |
---|
[573] | 570 | } else if ( strcmp(k, "-n") == 0 || strcmp(k, "--decnet") == 0 ) { |
---|
[1494] | 571 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[508] | 572 | #ifdef ROAR_HAVE_LIBDNET |
---|
| 573 | port = ROAR_DEFAULT_NUM; |
---|
| 574 | strcpy(decnethost, ROAR_DEFAULT_LISTEN_OBJECT); |
---|
| 575 | server = decnethost; |
---|
[517] | 576 | sock_type = ROAR_SOCKET_TYPE_DECNET; |
---|
[508] | 577 | #else |
---|
| 578 | ROAR_ERR("No DECnet support compiled in!"); |
---|
| 579 | return 1; |
---|
| 580 | #endif |
---|
[1494] | 581 | #endif |
---|
[518] | 582 | |
---|
[60] | 583 | } else if ( strcmp(k, "-G") == 0 ) { |
---|
[444] | 584 | sock_grp = argv[++i]; |
---|
| 585 | } else if ( strcmp(k, "-U") == 0 ) { |
---|
| 586 | sock_user = argv[++i]; |
---|
[0] | 587 | |
---|
[68] | 588 | } else if ( strcmp(k, "--no-listen") == 0 ) { |
---|
[1494] | 589 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[548] | 590 | *server = 0; |
---|
| 591 | g_terminate = 1; |
---|
[1155] | 592 | g_no_listen = 1; |
---|
[1494] | 593 | #endif |
---|
[68] | 594 | } else if ( strcmp(k, "--client-fh") == 0 ) { |
---|
| 595 | if ( clients_set_fh(clients_new(), atoi(argv[++i])) == -1 ) { |
---|
| 596 | ROAR_ERR("main(*): Can not set client's fh"); |
---|
| 597 | return 1; |
---|
| 598 | } |
---|
[501] | 599 | } else if ( strcmp(k, "--close-fh") == 0 ) { |
---|
[1486] | 600 | #ifdef ROAR_HAVE_IO_POSIX |
---|
[501] | 601 | close(atoi(argv[++i])); |
---|
[1486] | 602 | #else |
---|
| 603 | i++; |
---|
| 604 | ROAR_WARN("can not close file handle %s (closing not supported)", argv[i]); |
---|
| 605 | #endif |
---|
[68] | 606 | |
---|
[920] | 607 | } else if ( strcmp(k, "--standby") == 0 ) { |
---|
| 608 | g_standby = 1; |
---|
| 609 | } else if ( strcmp(k, "--auto-standby") == 0 ) { |
---|
| 610 | g_autostandby = 1; |
---|
[0] | 611 | } else { |
---|
| 612 | usage(); |
---|
| 613 | return 1; |
---|
| 614 | } |
---|
| 615 | |
---|
| 616 | } |
---|
[1503] | 617 | #endif |
---|
[0] | 618 | |
---|
[1110] | 619 | if ( s_dev != NULL ) { |
---|
| 620 | if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) { |
---|
| 621 | ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv); |
---|
| 622 | } |
---|
| 623 | } |
---|
| 624 | |
---|
[1145] | 625 | add_output(o_drv, o_dev, o_opts, o_prim, o_count); |
---|
[932] | 626 | |
---|
[0] | 627 | ROAR_DBG("Server config: rate=%i, bits=%i, chans=%i", sa.rate, sa.bits, sa.channels); |
---|
| 628 | |
---|
[281] | 629 | if ( midi_init() == -1 ) |
---|
| 630 | ROAR_ERR("Can not initialize MIDI subsystem"); |
---|
| 631 | |
---|
[1494] | 632 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[68] | 633 | if ( *server != 0 ) { |
---|
[517] | 634 | if ( (g_listen_socket = roar_socket_listen(sock_type, server, port)) == -1 ) { |
---|
[1486] | 635 | #ifdef ROAR_HAVE_UNIX |
---|
[286] | 636 | if ( *server == '/' ) { |
---|
[1011] | 637 | if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) { |
---|
| 638 | env_roar_proxy_backup = strdup(env_roar_proxy_backup); |
---|
| 639 | unsetenv("ROAR_PROXY"); |
---|
| 640 | } |
---|
[286] | 641 | if ( (i = roar_socket_connect(server, port)) != -1 ) { |
---|
| 642 | close(i); |
---|
| 643 | ROAR_ERR("Can not open listen socket!"); |
---|
| 644 | return 1; |
---|
| 645 | } else { |
---|
| 646 | unlink(server); |
---|
[517] | 647 | if ( (g_listen_socket = roar_socket_listen(sock_type, server, port)) == -1 ) { |
---|
[286] | 648 | ROAR_ERR("Can not open listen socket!"); |
---|
| 649 | return 1; |
---|
| 650 | } |
---|
| 651 | } |
---|
[1011] | 652 | if ( env_roar_proxy_backup != NULL ) { |
---|
| 653 | setenv("ROAR_PROXY", env_roar_proxy_backup, 0); |
---|
| 654 | free(env_roar_proxy_backup); |
---|
| 655 | } |
---|
[1486] | 656 | #else |
---|
| 657 | if (0) { // noop |
---|
| 658 | #endif |
---|
[286] | 659 | } else { |
---|
| 660 | ROAR_ERR("Can not open listen socket!"); |
---|
| 661 | return 1; |
---|
| 662 | } |
---|
[68] | 663 | } |
---|
[0] | 664 | |
---|
[1486] | 665 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[523] | 666 | if ( (grp = getgrnam(sock_grp)) == NULL ) { |
---|
| 667 | ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno)); |
---|
| 668 | } |
---|
[1486] | 669 | #endif |
---|
| 670 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[523] | 671 | if ( sock_user || (setids & R_SETUID) ) { |
---|
| 672 | if ( (pwd = getpwnam(sock_user)) == NULL ) { |
---|
| 673 | ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno)); |
---|
| 674 | } |
---|
| 675 | } |
---|
[1486] | 676 | #endif |
---|
[523] | 677 | |
---|
[1516] | 678 | #if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_UNIX) |
---|
[68] | 679 | if ( *server == '/' ) { |
---|
[523] | 680 | if ( grp ) { |
---|
[444] | 681 | if ( pwd ) { |
---|
| 682 | chown(server, pwd->pw_uid, grp->gr_gid); |
---|
| 683 | } else { |
---|
| 684 | chown(server, -1, grp->gr_gid); |
---|
| 685 | } |
---|
[68] | 686 | if ( getuid() == 0 ) |
---|
| 687 | chmod(server, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP); |
---|
| 688 | } |
---|
[60] | 689 | } |
---|
[1486] | 690 | #endif |
---|
[60] | 691 | } |
---|
[1494] | 692 | #endif |
---|
[60] | 693 | |
---|
[0] | 694 | if ( output_buffer_init(&sa) == -1 ) { |
---|
| 695 | ROAR_ERR("Can not init output buffer!"); |
---|
| 696 | return 1; |
---|
| 697 | } |
---|
| 698 | |
---|
[1145] | 699 | if ( driver == NULL ) { |
---|
| 700 | driver = "null"; |
---|
| 701 | } else { |
---|
| 702 | ROAR_WARN("Usage of old driver interface. use -o not -d!"); |
---|
| 703 | } |
---|
| 704 | |
---|
[0] | 705 | if ( driver_open(&drvinst, &drvid, driver, device, &sa) == -1 ) { |
---|
| 706 | ROAR_ERR("Can not open output driver!"); |
---|
| 707 | return 1; |
---|
| 708 | } |
---|
| 709 | |
---|
[44] | 710 | if ( samples_init() == -1 ) { |
---|
| 711 | ROAR_ERR("Can not init samples!"); |
---|
| 712 | return 1; |
---|
| 713 | } |
---|
| 714 | |
---|
| 715 | |
---|
[1486] | 716 | // we should handle this on microcontrollers, too. |
---|
| 717 | #if !defined(ROAR_TARGET_MICROCONTROLLER) |
---|
[0] | 718 | signal(SIGINT, on_sig_int); |
---|
[285] | 719 | signal(SIGCHLD, on_sig_chld); |
---|
[0] | 720 | signal(SIGPIPE, SIG_IGN); // ignore broken pipes |
---|
[1486] | 721 | #endif |
---|
[0] | 722 | |
---|
[275] | 723 | if ( realtime ) { |
---|
[278] | 724 | #ifdef DEBUG |
---|
| 725 | ROAR_WARN("compiled with -DDEBUG but realtime is enabled: for real realtime support compiel without -DDEBUG"); |
---|
| 726 | #endif |
---|
| 727 | |
---|
[1486] | 728 | #ifdef ROAR_HAVE_NICE |
---|
[275] | 729 | errno = 0; |
---|
[276] | 730 | nice(-5*realtime); // -5 for each --realtime |
---|
[1486] | 731 | if ( errno ) { |
---|
| 732 | ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno)); |
---|
| 733 | } |
---|
| 734 | #else |
---|
| 735 | ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno)); |
---|
| 736 | #endif |
---|
[277] | 737 | /* |
---|
[276] | 738 | #ifdef __linux__ |
---|
[277] | 739 | if ( ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0)) == -1 ) |
---|
| 740 | ROAR_WARN("Can not set io priority: %s", strerror(errno)); |
---|
[276] | 741 | #endif |
---|
[277] | 742 | */ |
---|
[275] | 743 | } |
---|
| 744 | |
---|
[1486] | 745 | #ifdef ROAR_HAVE_SETGID |
---|
[444] | 746 | if ( setids & R_SETGID ) { |
---|
| 747 | if ( setgroups(0, (const gid_t *) NULL) == -1 ) { |
---|
| 748 | ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno)); |
---|
| 749 | } |
---|
[523] | 750 | if ( !grp || setgid(grp->gr_gid) == -1 ) { |
---|
[444] | 751 | ROAR_ERR("Can not set GroupID: %s", strerror(errno)); |
---|
| 752 | } |
---|
| 753 | } |
---|
[1486] | 754 | #endif |
---|
[444] | 755 | |
---|
[0] | 756 | |
---|
[39] | 757 | clients_set_pid(g_self_client, getpid()); |
---|
[440] | 758 | clients_set_uid(g_self_client, getuid()); |
---|
| 759 | clients_set_gid(g_self_client, getgid()); |
---|
[39] | 760 | clients_get(g_self_client, &self); |
---|
[37] | 761 | |
---|
[39] | 762 | if ( self == NULL ) { |
---|
| 763 | ROAR_ERR("Can not get self client!"); |
---|
| 764 | return 1; |
---|
| 765 | } |
---|
| 766 | |
---|
[775] | 767 | strcpy(self->name, "RoarAudio daemon internal"); |
---|
[68] | 768 | |
---|
[1486] | 769 | #ifdef ROAR_HAVE_FORK |
---|
[775] | 770 | if ( daemon ) { |
---|
[68] | 771 | close(ROAR_STDIN ); |
---|
| 772 | close(ROAR_STDOUT); |
---|
| 773 | close(ROAR_STDERR); |
---|
[422] | 774 | setsid(); |
---|
[68] | 775 | if ( fork() ) |
---|
[1486] | 776 | ROAR_U_EXIT(0); |
---|
[1046] | 777 | clients_set_pid(g_self_client, getpid()); // reset pid as it changed |
---|
[68] | 778 | } |
---|
[1486] | 779 | #endif |
---|
[68] | 780 | |
---|
[1486] | 781 | #ifdef ROAR_HAVE_CHROOT |
---|
[444] | 782 | if (chrootdir) { |
---|
| 783 | if ( chroot(chrootdir) == -1 ) { |
---|
| 784 | ROAR_ERR("Can not chroot to %s: %s", chrootdir, strerror(errno)); |
---|
| 785 | return 2; |
---|
| 786 | } |
---|
| 787 | if ( chdir("/") == -1 ) { |
---|
| 788 | ROAR_ERR("Can not chdir to /: %s", strerror(errno)); |
---|
| 789 | return 2; |
---|
| 790 | } |
---|
| 791 | } |
---|
[1486] | 792 | #endif |
---|
[444] | 793 | |
---|
[1486] | 794 | #ifdef ROAR_HAVE_SETUID |
---|
[444] | 795 | if ( setids & R_SETUID ) { |
---|
| 796 | if ( !pwd || setuid(pwd->pw_uid) == -1 ) { |
---|
| 797 | ROAR_ERR("Can not set UserID: %s", strerror(errno)); |
---|
| 798 | return 3; |
---|
| 799 | } |
---|
| 800 | clients_set_uid(g_self_client, getuid()); |
---|
| 801 | } |
---|
[1486] | 802 | #endif |
---|
[444] | 803 | |
---|
[0] | 804 | // start main loop... |
---|
[905] | 805 | main_loop(drvid, drvinst, &sa, sysclocksync); |
---|
[0] | 806 | |
---|
| 807 | // clean up. |
---|
| 808 | clean_quit_prep(); |
---|
| 809 | driver_close(drvinst, drvid); |
---|
| 810 | output_buffer_free(); |
---|
| 811 | |
---|
| 812 | return 0; |
---|
| 813 | } |
---|
| 814 | |
---|
[574] | 815 | void cleanup_listen_socket (int terminate) { |
---|
[580] | 816 | |
---|
[1494] | 817 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[580] | 818 | if ( g_listen_socket != -1 ) { |
---|
[1486] | 819 | #ifdef ROAR_HAVE_IO_POSIX |
---|
[580] | 820 | close(g_listen_socket); |
---|
[1486] | 821 | #endif // #else is useless because we are in void context. |
---|
[60] | 822 | |
---|
[580] | 823 | g_listen_socket = -1; |
---|
[576] | 824 | |
---|
[1486] | 825 | #ifdef ROAR_HAVE_UNIX |
---|
[580] | 826 | if ( *server == '/' ) |
---|
| 827 | unlink(server); |
---|
[1486] | 828 | #endif |
---|
[580] | 829 | } |
---|
[60] | 830 | |
---|
[1494] | 831 | #endif |
---|
| 832 | |
---|
[574] | 833 | if ( terminate ) |
---|
| 834 | g_terminate = 1; |
---|
| 835 | } |
---|
| 836 | |
---|
| 837 | void clean_quit_prep (void) { |
---|
| 838 | cleanup_listen_socket(0); |
---|
[60] | 839 | |
---|
[0] | 840 | sources_free(); |
---|
| 841 | streams_free(); |
---|
| 842 | clients_free(); |
---|
[282] | 843 | midi_cb_stop(); // stop console beep |
---|
[281] | 844 | midi_free(); |
---|
[0] | 845 | } |
---|
| 846 | |
---|
| 847 | void clean_quit (void) { |
---|
| 848 | clean_quit_prep(); |
---|
| 849 | // driver_close(drvinst, drvid); |
---|
| 850 | // output_buffer_free(); |
---|
| 851 | exit(0); |
---|
| 852 | } |
---|
| 853 | |
---|
| 854 | //ll |
---|