[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 | |
---|
| 219 | /* ignore this for the moment ... */ |
---|
| 220 | } else if ( strcmp(k, "autoconf") == 0 ) { |
---|
[938] | 221 | } else { |
---|
| 222 | ROAR_ERR("add_output(*): unknown option '%s'", k); |
---|
| 223 | streams_delete(stream); |
---|
[982] | 224 | if ( prim ) alive = 0; |
---|
[1208] | 225 | #ifdef ROAR_DRIVER_CODEC |
---|
| 226 | if ( to_free != NULL ) |
---|
| 227 | free(to_free); |
---|
| 228 | #endif |
---|
[938] | 229 | return -1; |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | k = strtok(NULL, ","); |
---|
| 233 | } |
---|
| 234 | |
---|
[1208] | 235 | #ifdef ROAR_DRIVER_CODEC |
---|
| 236 | if ( to_free != NULL ) |
---|
| 237 | free(to_free); |
---|
| 238 | #endif |
---|
| 239 | |
---|
[941] | 240 | if ( codec == ROAR_CODEC_ALAW || codec == ROAR_CODEC_MULAW ) |
---|
| 241 | s->info.bits = 8; // needed to open OSS driver, will be overriden by codecfilter |
---|
| 242 | |
---|
[938] | 243 | s->info.codec = codec; |
---|
| 244 | ROAR_STREAM_SERVER(s)->codec_orgi = codec; |
---|
[933] | 245 | |
---|
[1145] | 246 | if ( driver_openvio(&(ss->vio), &(ss->driver_id), drv, dev, &(s->info), -1) == -1 ) { |
---|
[933] | 247 | streams_delete(stream); |
---|
[938] | 248 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts); |
---|
[982] | 249 | if ( prim ) alive = 0; |
---|
[933] | 250 | return -1; |
---|
| 251 | } |
---|
| 252 | |
---|
[1528] | 253 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAMID, &stream); // ignore errors here |
---|
| 254 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAM, s); // ignore errors here |
---|
| 255 | |
---|
[1221] | 256 | if ( blocks != -1 ) |
---|
| 257 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLOCKS, &blocks); |
---|
| 258 | |
---|
[1522] | 259 | if ( blocksize != -1 ) |
---|
| 260 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLKSIZE, &blocksize); |
---|
| 261 | |
---|
[1156] | 262 | ROAR_DBG("add_output(*): ss->driver_id=%i", ss->driver_id); |
---|
| 263 | |
---|
[938] | 264 | streams_set_fh(stream, -1); // update some internal structures |
---|
| 265 | |
---|
[933] | 266 | client_stream_add(g_source_client, stream); |
---|
| 267 | |
---|
[1200] | 268 | if ( prim ) { |
---|
[961] | 269 | streams_mark_primary(stream); |
---|
[1200] | 270 | s->pos_rel_id = stream; |
---|
| 271 | } |
---|
[961] | 272 | |
---|
[1120] | 273 | if ( sync ) { |
---|
[1117] | 274 | streams_set_flag(stream, ROAR_FLAG_SYNC); |
---|
[1120] | 275 | } else { |
---|
| 276 | streams_reset_flag(stream, ROAR_FLAG_SYNC); |
---|
| 277 | } |
---|
[1117] | 278 | |
---|
[933] | 279 | return 0; |
---|
[932] | 280 | } |
---|
| 281 | |
---|
[1503] | 282 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 283 | int main (int argc, char * argv[]) { |
---|
[1503] | 284 | #else |
---|
| 285 | int main (void) { |
---|
| 286 | #endif |
---|
| 287 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 288 | int i; |
---|
| 289 | char * k; |
---|
[1503] | 290 | #endif |
---|
[1494] | 291 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[905] | 292 | char user_sock[80] = {0}; |
---|
[1494] | 293 | #endif |
---|
[0] | 294 | struct roar_audio_info sa; |
---|
[1486] | 295 | #ifdef ROAR_HAVE_FORK |
---|
[905] | 296 | int daemon = 0; |
---|
[1486] | 297 | #endif |
---|
[905] | 298 | int realtime = 0; |
---|
| 299 | int sysclocksync = 0; |
---|
[1207] | 300 | char * driver = NULL; |
---|
| 301 | char * device = NULL; |
---|
[1503] | 302 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[1207] | 303 | char * opts = NULL; |
---|
[1503] | 304 | #endif |
---|
[60] | 305 | // char * server = ROAR_DEFAULT_SOCK_GLOBAL; |
---|
[1494] | 306 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[1207] | 307 | int port = ROAR_DEFAULT_PORT; |
---|
[1494] | 308 | #endif |
---|
[0] | 309 | int drvid; |
---|
[550] | 310 | char * s_drv = "cf"; |
---|
[1110] | 311 | char * s_dev = NULL; |
---|
[444] | 312 | char * s_con = NULL; |
---|
| 313 | char * s_opt = NULL; |
---|
| 314 | int s_prim = 0; |
---|
[1207] | 315 | char * o_drv = getenv("ROAR_DRIVER"); |
---|
| 316 | char * o_dev = getenv("ROAR_DEVICE"); |
---|
[932] | 317 | char * o_opts = NULL; |
---|
[961] | 318 | int o_prim = 0; |
---|
[1145] | 319 | int o_count = 0; |
---|
[450] | 320 | char * sock_grp = ROAR_DEFAULT_SOCKGRP; |
---|
[444] | 321 | char * sock_user = NULL; |
---|
[1494] | 322 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[517] | 323 | int sock_type = ROAR_SOCKET_TYPE_UNKNOWN; |
---|
[1494] | 324 | #endif |
---|
[1486] | 325 | #ifdef ROAR_HAVE_CHROOT |
---|
[444] | 326 | char * chrootdir = NULL; |
---|
[1486] | 327 | #endif |
---|
| 328 | #if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID) |
---|
[444] | 329 | int setids = 0; |
---|
[1486] | 330 | #endif |
---|
| 331 | #ifdef ROAR_HAVE_UNIX |
---|
[1011] | 332 | char * env_roar_proxy_backup; |
---|
[1486] | 333 | #endif |
---|
| 334 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[446] | 335 | struct group * grp = NULL; |
---|
[1486] | 336 | #endif |
---|
| 337 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[446] | 338 | struct passwd * pwd = NULL; |
---|
[1486] | 339 | #endif |
---|
| 340 | #ifdef ROAR_HAVE_GETSERVBYNAME |
---|
[446] | 341 | struct servent * serv = NULL; |
---|
[1486] | 342 | #endif |
---|
[0] | 343 | DRIVER_USERDATA_T drvinst; |
---|
[39] | 344 | struct roar_client * self = NULL; |
---|
[508] | 345 | #ifdef ROAR_HAVE_LIBDNET |
---|
| 346 | char decnethost[80]; |
---|
| 347 | #endif |
---|
[0] | 348 | |
---|
| 349 | g_standby = 0; |
---|
[920] | 350 | g_autostandby = 0; |
---|
[982] | 351 | alive = 1; |
---|
[1494] | 352 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[1155] | 353 | g_no_listen = 0; |
---|
[1494] | 354 | g_listen_socket = -1; |
---|
| 355 | #else |
---|
| 356 | g_terminate = 1; |
---|
| 357 | #endif |
---|
[0] | 358 | |
---|
| 359 | sa.bits = ROAR_BITS_DEFAULT; |
---|
| 360 | sa.channels = ROAR_CHANNELS_DEFAULT; |
---|
| 361 | sa.rate = ROAR_RATE_DEFAULT; |
---|
| 362 | sa.codec = ROAR_CODEC_DEFAULT; |
---|
| 363 | |
---|
| 364 | g_sa = &sa; |
---|
| 365 | |
---|
[60] | 366 | |
---|
[1494] | 367 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[1486] | 368 | if ( getuid() != 0 && getenv("HOME") != NULL ) { |
---|
| 369 | snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER); |
---|
[60] | 370 | server = user_sock; |
---|
| 371 | } |
---|
| 372 | |
---|
[279] | 373 | if ( getenv("ROAR_SERVER") != NULL ) |
---|
| 374 | server = getenv("ROAR_SERVER"); |
---|
[1494] | 375 | #endif |
---|
[279] | 376 | |
---|
[63] | 377 | if ( clients_init() == -1 ) { |
---|
| 378 | ROAR_ERR("Can not init clients!"); |
---|
| 379 | return 1; |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | if ( streams_init() == -1 ) { |
---|
| 383 | ROAR_ERR("Can not init streams!"); |
---|
| 384 | return 1; |
---|
| 385 | } |
---|
| 386 | |
---|
[64] | 387 | if ( (g_self_client = clients_new()) == -1 ) { |
---|
| 388 | ROAR_ERR("Can not create self client!"); |
---|
| 389 | return 1; |
---|
| 390 | } |
---|
| 391 | |
---|
[0] | 392 | if ( sources_init() == -1 ) { |
---|
| 393 | ROAR_ERR("Can not init sources!"); |
---|
| 394 | return 1; |
---|
| 395 | } |
---|
| 396 | |
---|
[64] | 397 | if ( (sources_set_client(g_self_client)) == -1 ) { |
---|
| 398 | ROAR_ERR("Can not init set source client!"); |
---|
| 399 | return 1; |
---|
| 400 | } |
---|
| 401 | |
---|
[1503] | 402 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
[0] | 403 | for (i = 1; i < argc; i++) { |
---|
| 404 | k = argv[i]; |
---|
| 405 | |
---|
| 406 | if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) { |
---|
| 407 | usage(); |
---|
| 408 | return 0; |
---|
| 409 | |
---|
[579] | 410 | } else if ( strcmp(k, "--restart") == 0 ) { |
---|
[1494] | 411 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[579] | 412 | if ( restart_server(server) == -1 ) { |
---|
| 413 | ROAR_WARN("Can not terminate old server (not running at %s?), tring to continue anyway", server); |
---|
| 414 | } |
---|
[1494] | 415 | #else |
---|
| 416 | ROAR_ERR("--restart not supported"); |
---|
| 417 | #endif |
---|
[579] | 418 | |
---|
[775] | 419 | } else if ( strcmp(k, "--demon") == 0 || strcmp(k, "--daemon") == 0 ) { |
---|
[1486] | 420 | #ifdef ROAR_HAVE_FORK |
---|
[775] | 421 | daemon = 1; |
---|
[1486] | 422 | #else |
---|
| 423 | ROAR_ERR("--daemon not supported"); |
---|
| 424 | #endif |
---|
[71] | 425 | } else if ( strcmp(k, "--terminate") == 0 ) { |
---|
| 426 | g_terminate = 1; |
---|
[905] | 427 | } else if ( strcmp(k, "--sysclocksync") == 0 ) { |
---|
| 428 | sysclocksync = 1000; |
---|
[275] | 429 | } else if ( strcmp(k, "--realtime") == 0 ) { |
---|
[276] | 430 | realtime++; |
---|
[444] | 431 | } else if ( strcmp(k, "--chroot") == 0 ) { |
---|
[1486] | 432 | #ifdef ROAR_HAVE_CHROOT |
---|
[444] | 433 | chrootdir = argv[++i]; |
---|
[1486] | 434 | #else |
---|
| 435 | ROAR_ERR("--chroot not supported"); |
---|
| 436 | i++; |
---|
| 437 | #endif |
---|
[444] | 438 | } else if ( strcmp(k, "--setgid") == 0 ) { |
---|
[1486] | 439 | #ifdef ROAR_HAVE_SETGID |
---|
[444] | 440 | setids |= R_SETGID; |
---|
[1486] | 441 | #else |
---|
| 442 | ROAR_ERR("--setgid not supported"); |
---|
| 443 | #endif |
---|
[444] | 444 | } else if ( strcmp(k, "--setuid") == 0 ) { |
---|
[1486] | 445 | #ifdef ROAR_HAVE_SETUID |
---|
[444] | 446 | setids |= R_SETUID; |
---|
[1486] | 447 | #else |
---|
| 448 | ROAR_ERR("--setuid not supported"); |
---|
| 449 | #endif |
---|
[68] | 450 | |
---|
[280] | 451 | } else if ( strcmp(k, "--list-cf") == 0 ) { |
---|
| 452 | print_codecfilterlist(); |
---|
| 453 | return 0; |
---|
| 454 | |
---|
[0] | 455 | } else if ( strcmp(k, "-R") == 0 || strcmp(k, "--rate") == 0 ) { |
---|
| 456 | sa.rate = atoi(argv[++i]); |
---|
| 457 | } else if ( strcmp(k, "-B") == 0 || strcmp(k, "--bits") == 0 ) { |
---|
| 458 | sa.bits = atoi(argv[++i]); |
---|
| 459 | } else if ( strcmp(k, "-C") == 0 || strcmp(k, "--chans") == 0 ) { |
---|
| 460 | sa.channels = atoi(argv[++i]); |
---|
| 461 | |
---|
| 462 | } else if ( strcmp(k, "-d") == 0 || strcmp(k, "--driver") == 0 ) { |
---|
| 463 | driver = argv[++i]; |
---|
| 464 | if ( strcmp(driver, "list") == 0 ) { |
---|
[974] | 465 | ROAR_WARN("The option is obsolete, use --list-driver!"); |
---|
[0] | 466 | print_driverlist(); |
---|
[973] | 467 | return 0; |
---|
[0] | 468 | } |
---|
| 469 | } else if ( strcmp(k, "-D") == 0 || strcmp(k, "--device") == 0 ) { |
---|
| 470 | device = argv[++i]; |
---|
| 471 | } else if ( strcmp(k, "-dO") == 0 ) { |
---|
| 472 | opts = argv[++i]; |
---|
[973] | 473 | } else if ( strcmp(k, "--list-driver") == 0 ) { |
---|
| 474 | print_driverlist(); |
---|
| 475 | return 0; |
---|
[0] | 476 | |
---|
[932] | 477 | } else if ( strcmp(k, "-o") == 0 || strcmp(k, "--odriver") == 0 ) { |
---|
| 478 | o_drv = argv[++i]; |
---|
| 479 | } else if ( strcmp(k, "-O") == 0 || strcmp(k, "--odevice") == 0 ) { |
---|
| 480 | o_dev = argv[++i]; |
---|
| 481 | } else if ( strcmp(k, "-oO") == 0 ) { |
---|
| 482 | o_opts = argv[++i]; |
---|
[961] | 483 | } else if ( strcmp(k, "-oP") == 0 ) { |
---|
| 484 | o_prim = 1; |
---|
[932] | 485 | } else if ( strcmp(k, "-oN") == 0 ) { |
---|
[1145] | 486 | if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 ) |
---|
| 487 | o_count++; |
---|
| 488 | |
---|
[961] | 489 | o_drv = o_dev = o_opts = NULL; |
---|
| 490 | o_prim = 0; |
---|
[932] | 491 | |
---|
[0] | 492 | } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) { |
---|
[550] | 493 | s_drv = argv[++i]; |
---|
| 494 | } else if ( strcmp(k, "-S") == 0 ) { |
---|
[1110] | 495 | s_dev = argv[++i]; |
---|
[0] | 496 | } else if ( strcmp(k, "-sO") == 0 ) { |
---|
| 497 | s_opt = argv[++i]; |
---|
| 498 | } else if ( strcmp(k, "-sC") == 0 ) { |
---|
| 499 | s_con = argv[++i]; |
---|
| 500 | } else if ( strcmp(k, "-sP") == 0 ) { |
---|
| 501 | s_prim = 1; |
---|
[1110] | 502 | } else if ( strcmp(k, "-sN") == 0 ) { |
---|
| 503 | if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) { |
---|
| 504 | ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv); |
---|
| 505 | } |
---|
| 506 | s_opt = s_dev = s_con = NULL; |
---|
| 507 | s_drv = "cf"; |
---|
| 508 | s_prim = 0; |
---|
[0] | 509 | |
---|
| 510 | } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--port") == 0 ) { |
---|
[447] | 511 | // This is only usefull in INET not UNIX mode. |
---|
[1494] | 512 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[447] | 513 | if ( *server == '/' ) |
---|
| 514 | server = ROAR_DEFAULT_HOST; |
---|
| 515 | |
---|
[446] | 516 | errno = 0; |
---|
| 517 | if ( (port = atoi(argv[++i])) < 1 ) { |
---|
[1486] | 518 | #ifdef ROAR_HAVE_GETSERVBYNAME |
---|
[446] | 519 | if ( (serv = getservbyname(argv[i], "tcp")) == NULL ) { |
---|
| 520 | ROAR_ERR("Unknown service: %s: %s", argv[i], strerror(errno)); |
---|
| 521 | return 1; |
---|
| 522 | } |
---|
| 523 | // NOTE: we need to use ROAR_NET2HOST16() here even if s_port is of type int! |
---|
| 524 | ROAR_DBG("main(*): serv = {s_name='%s', s_aliases={...}, s_port=%i, s_proto='%s'}", |
---|
| 525 | serv->s_name, ROAR_NET2HOST16(serv->s_port), serv->s_proto); |
---|
| 526 | port = ROAR_NET2HOST16(serv->s_port); |
---|
[1486] | 527 | #else |
---|
| 528 | ROAR_ERR("invalite port number: %s", argv[i]); |
---|
| 529 | return 1; |
---|
| 530 | #endif |
---|
[446] | 531 | } |
---|
[1494] | 532 | #endif |
---|
[1115] | 533 | } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) { |
---|
[1494] | 534 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[0] | 535 | server = argv[++i]; |
---|
[1494] | 536 | #endif |
---|
[518] | 537 | |
---|
[573] | 538 | } else if ( strcmp(k, "-t") == 0 || strcmp(k, "--tcp") == 0 ) { |
---|
[1494] | 539 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[518] | 540 | if ( sock_type != ROAR_SOCKET_TYPE_TCP && sock_type != ROAR_SOCKET_TYPE_TCP6 ) |
---|
| 541 | sock_type = ROAR_SOCKET_TYPE_TCP; |
---|
| 542 | |
---|
| 543 | if ( *server == '/' ) |
---|
| 544 | server = ROAR_DEFAULT_HOST; |
---|
[1494] | 545 | #endif |
---|
[518] | 546 | |
---|
| 547 | } else if ( strcmp(k, "-4") == 0 ) { |
---|
[1494] | 548 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[517] | 549 | sock_type = ROAR_SOCKET_TYPE_TCP; |
---|
[447] | 550 | if ( *server == '/' ) |
---|
| 551 | server = ROAR_DEFAULT_HOST; |
---|
[1494] | 552 | #endif |
---|
[518] | 553 | } else if ( strcmp(k, "-6") == 0 ) { |
---|
[1494] | 554 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[519] | 555 | #ifdef PF_INET6 |
---|
[518] | 556 | sock_type = ROAR_SOCKET_TYPE_TCP6; |
---|
| 557 | if ( *server == '/' ) |
---|
| 558 | server = ROAR_DEFAULT_HOST; |
---|
[519] | 559 | #else |
---|
| 560 | ROAR_ERR("No IPv6 support compiled in!"); |
---|
| 561 | return 1; |
---|
| 562 | #endif |
---|
[1494] | 563 | #endif |
---|
[518] | 564 | |
---|
[573] | 565 | } else if ( strcmp(k, "-u") == 0 || strcmp(k, "--unix") == 0 ) { |
---|
[1494] | 566 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[62] | 567 | // ignore this case as it is the default behavor. |
---|
[517] | 568 | sock_type = ROAR_SOCKET_TYPE_UNIX; |
---|
[1494] | 569 | #endif |
---|
[518] | 570 | |
---|
[573] | 571 | } else if ( strcmp(k, "-n") == 0 || strcmp(k, "--decnet") == 0 ) { |
---|
[1494] | 572 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[508] | 573 | #ifdef ROAR_HAVE_LIBDNET |
---|
| 574 | port = ROAR_DEFAULT_NUM; |
---|
| 575 | strcpy(decnethost, ROAR_DEFAULT_LISTEN_OBJECT); |
---|
| 576 | server = decnethost; |
---|
[517] | 577 | sock_type = ROAR_SOCKET_TYPE_DECNET; |
---|
[508] | 578 | #else |
---|
| 579 | ROAR_ERR("No DECnet support compiled in!"); |
---|
| 580 | return 1; |
---|
| 581 | #endif |
---|
[1494] | 582 | #endif |
---|
[518] | 583 | |
---|
[60] | 584 | } else if ( strcmp(k, "-G") == 0 ) { |
---|
[444] | 585 | sock_grp = argv[++i]; |
---|
| 586 | } else if ( strcmp(k, "-U") == 0 ) { |
---|
| 587 | sock_user = argv[++i]; |
---|
[0] | 588 | |
---|
[68] | 589 | } else if ( strcmp(k, "--no-listen") == 0 ) { |
---|
[1494] | 590 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[548] | 591 | *server = 0; |
---|
| 592 | g_terminate = 1; |
---|
[1155] | 593 | g_no_listen = 1; |
---|
[1494] | 594 | #endif |
---|
[68] | 595 | } else if ( strcmp(k, "--client-fh") == 0 ) { |
---|
| 596 | if ( clients_set_fh(clients_new(), atoi(argv[++i])) == -1 ) { |
---|
| 597 | ROAR_ERR("main(*): Can not set client's fh"); |
---|
| 598 | return 1; |
---|
| 599 | } |
---|
[501] | 600 | } else if ( strcmp(k, "--close-fh") == 0 ) { |
---|
[1486] | 601 | #ifdef ROAR_HAVE_IO_POSIX |
---|
[501] | 602 | close(atoi(argv[++i])); |
---|
[1486] | 603 | #else |
---|
| 604 | i++; |
---|
| 605 | ROAR_WARN("can not close file handle %s (closing not supported)", argv[i]); |
---|
| 606 | #endif |
---|
[68] | 607 | |
---|
[920] | 608 | } else if ( strcmp(k, "--standby") == 0 ) { |
---|
| 609 | g_standby = 1; |
---|
| 610 | } else if ( strcmp(k, "--auto-standby") == 0 ) { |
---|
| 611 | g_autostandby = 1; |
---|
[0] | 612 | } else { |
---|
| 613 | usage(); |
---|
| 614 | return 1; |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | } |
---|
[1503] | 618 | #endif |
---|
[0] | 619 | |
---|
[1110] | 620 | if ( s_dev != NULL ) { |
---|
| 621 | if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) { |
---|
| 622 | ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv); |
---|
| 623 | } |
---|
| 624 | } |
---|
| 625 | |
---|
[1145] | 626 | add_output(o_drv, o_dev, o_opts, o_prim, o_count); |
---|
[932] | 627 | |
---|
[0] | 628 | ROAR_DBG("Server config: rate=%i, bits=%i, chans=%i", sa.rate, sa.bits, sa.channels); |
---|
| 629 | |
---|
[281] | 630 | if ( midi_init() == -1 ) |
---|
| 631 | ROAR_ERR("Can not initialize MIDI subsystem"); |
---|
| 632 | |
---|
[1494] | 633 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[68] | 634 | if ( *server != 0 ) { |
---|
[517] | 635 | if ( (g_listen_socket = roar_socket_listen(sock_type, server, port)) == -1 ) { |
---|
[1486] | 636 | #ifdef ROAR_HAVE_UNIX |
---|
[286] | 637 | if ( *server == '/' ) { |
---|
[1011] | 638 | if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) { |
---|
| 639 | env_roar_proxy_backup = strdup(env_roar_proxy_backup); |
---|
| 640 | unsetenv("ROAR_PROXY"); |
---|
| 641 | } |
---|
[286] | 642 | if ( (i = roar_socket_connect(server, port)) != -1 ) { |
---|
| 643 | close(i); |
---|
| 644 | ROAR_ERR("Can not open listen socket!"); |
---|
| 645 | return 1; |
---|
| 646 | } else { |
---|
| 647 | unlink(server); |
---|
[517] | 648 | if ( (g_listen_socket = roar_socket_listen(sock_type, server, port)) == -1 ) { |
---|
[286] | 649 | ROAR_ERR("Can not open listen socket!"); |
---|
| 650 | return 1; |
---|
| 651 | } |
---|
| 652 | } |
---|
[1011] | 653 | if ( env_roar_proxy_backup != NULL ) { |
---|
| 654 | setenv("ROAR_PROXY", env_roar_proxy_backup, 0); |
---|
| 655 | free(env_roar_proxy_backup); |
---|
| 656 | } |
---|
[1486] | 657 | #else |
---|
| 658 | if (0) { // noop |
---|
| 659 | #endif |
---|
[286] | 660 | } else { |
---|
| 661 | ROAR_ERR("Can not open listen socket!"); |
---|
| 662 | return 1; |
---|
| 663 | } |
---|
[68] | 664 | } |
---|
[0] | 665 | |
---|
[1486] | 666 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[523] | 667 | if ( (grp = getgrnam(sock_grp)) == NULL ) { |
---|
| 668 | ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno)); |
---|
| 669 | } |
---|
[1486] | 670 | #endif |
---|
| 671 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
[523] | 672 | if ( sock_user || (setids & R_SETUID) ) { |
---|
| 673 | if ( (pwd = getpwnam(sock_user)) == NULL ) { |
---|
| 674 | ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno)); |
---|
| 675 | } |
---|
| 676 | } |
---|
[1486] | 677 | #endif |
---|
[523] | 678 | |
---|
[1516] | 679 | #if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_UNIX) |
---|
[68] | 680 | if ( *server == '/' ) { |
---|
[523] | 681 | if ( grp ) { |
---|
[444] | 682 | if ( pwd ) { |
---|
| 683 | chown(server, pwd->pw_uid, grp->gr_gid); |
---|
| 684 | } else { |
---|
| 685 | chown(server, -1, grp->gr_gid); |
---|
| 686 | } |
---|
[68] | 687 | if ( getuid() == 0 ) |
---|
| 688 | chmod(server, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP); |
---|
| 689 | } |
---|
[60] | 690 | } |
---|
[1486] | 691 | #endif |
---|
[60] | 692 | } |
---|
[1494] | 693 | #endif |
---|
[60] | 694 | |
---|
[0] | 695 | if ( output_buffer_init(&sa) == -1 ) { |
---|
| 696 | ROAR_ERR("Can not init output buffer!"); |
---|
| 697 | return 1; |
---|
| 698 | } |
---|
| 699 | |
---|
[1145] | 700 | if ( driver == NULL ) { |
---|
| 701 | driver = "null"; |
---|
| 702 | } else { |
---|
| 703 | ROAR_WARN("Usage of old driver interface. use -o not -d!"); |
---|
| 704 | } |
---|
| 705 | |
---|
[0] | 706 | if ( driver_open(&drvinst, &drvid, driver, device, &sa) == -1 ) { |
---|
| 707 | ROAR_ERR("Can not open output driver!"); |
---|
| 708 | return 1; |
---|
| 709 | } |
---|
| 710 | |
---|
[44] | 711 | if ( samples_init() == -1 ) { |
---|
| 712 | ROAR_ERR("Can not init samples!"); |
---|
| 713 | return 1; |
---|
| 714 | } |
---|
| 715 | |
---|
| 716 | |
---|
[1486] | 717 | // we should handle this on microcontrollers, too. |
---|
| 718 | #if !defined(ROAR_TARGET_MICROCONTROLLER) |
---|
[0] | 719 | signal(SIGINT, on_sig_int); |
---|
[285] | 720 | signal(SIGCHLD, on_sig_chld); |
---|
[0] | 721 | signal(SIGPIPE, SIG_IGN); // ignore broken pipes |
---|
[1486] | 722 | #endif |
---|
[0] | 723 | |
---|
[275] | 724 | if ( realtime ) { |
---|
[278] | 725 | #ifdef DEBUG |
---|
| 726 | ROAR_WARN("compiled with -DDEBUG but realtime is enabled: for real realtime support compiel without -DDEBUG"); |
---|
| 727 | #endif |
---|
| 728 | |
---|
[1486] | 729 | #ifdef ROAR_HAVE_NICE |
---|
[275] | 730 | errno = 0; |
---|
[276] | 731 | nice(-5*realtime); // -5 for each --realtime |
---|
[1486] | 732 | if ( errno ) { |
---|
| 733 | ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno)); |
---|
| 734 | } |
---|
| 735 | #else |
---|
| 736 | ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno)); |
---|
| 737 | #endif |
---|
[277] | 738 | /* |
---|
[276] | 739 | #ifdef __linux__ |
---|
[277] | 740 | if ( ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0)) == -1 ) |
---|
| 741 | ROAR_WARN("Can not set io priority: %s", strerror(errno)); |
---|
[276] | 742 | #endif |
---|
[277] | 743 | */ |
---|
[275] | 744 | } |
---|
| 745 | |
---|
[1486] | 746 | #ifdef ROAR_HAVE_SETGID |
---|
[444] | 747 | if ( setids & R_SETGID ) { |
---|
| 748 | if ( setgroups(0, (const gid_t *) NULL) == -1 ) { |
---|
| 749 | ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno)); |
---|
| 750 | } |
---|
[523] | 751 | if ( !grp || setgid(grp->gr_gid) == -1 ) { |
---|
[444] | 752 | ROAR_ERR("Can not set GroupID: %s", strerror(errno)); |
---|
| 753 | } |
---|
| 754 | } |
---|
[1486] | 755 | #endif |
---|
[444] | 756 | |
---|
[0] | 757 | |
---|
[39] | 758 | clients_set_pid(g_self_client, getpid()); |
---|
[440] | 759 | clients_set_uid(g_self_client, getuid()); |
---|
| 760 | clients_set_gid(g_self_client, getgid()); |
---|
[39] | 761 | clients_get(g_self_client, &self); |
---|
[37] | 762 | |
---|
[39] | 763 | if ( self == NULL ) { |
---|
| 764 | ROAR_ERR("Can not get self client!"); |
---|
| 765 | return 1; |
---|
| 766 | } |
---|
| 767 | |
---|
[775] | 768 | strcpy(self->name, "RoarAudio daemon internal"); |
---|
[68] | 769 | |
---|
[1486] | 770 | #ifdef ROAR_HAVE_FORK |
---|
[775] | 771 | if ( daemon ) { |
---|
[68] | 772 | close(ROAR_STDIN ); |
---|
| 773 | close(ROAR_STDOUT); |
---|
| 774 | close(ROAR_STDERR); |
---|
[422] | 775 | setsid(); |
---|
[68] | 776 | if ( fork() ) |
---|
[1486] | 777 | ROAR_U_EXIT(0); |
---|
[1046] | 778 | clients_set_pid(g_self_client, getpid()); // reset pid as it changed |
---|
[68] | 779 | } |
---|
[1486] | 780 | #endif |
---|
[68] | 781 | |
---|
[1486] | 782 | #ifdef ROAR_HAVE_CHROOT |
---|
[444] | 783 | if (chrootdir) { |
---|
| 784 | if ( chroot(chrootdir) == -1 ) { |
---|
| 785 | ROAR_ERR("Can not chroot to %s: %s", chrootdir, strerror(errno)); |
---|
| 786 | return 2; |
---|
| 787 | } |
---|
| 788 | if ( chdir("/") == -1 ) { |
---|
| 789 | ROAR_ERR("Can not chdir to /: %s", strerror(errno)); |
---|
| 790 | return 2; |
---|
| 791 | } |
---|
| 792 | } |
---|
[1486] | 793 | #endif |
---|
[444] | 794 | |
---|
[1486] | 795 | #ifdef ROAR_HAVE_SETUID |
---|
[444] | 796 | if ( setids & R_SETUID ) { |
---|
| 797 | if ( !pwd || setuid(pwd->pw_uid) == -1 ) { |
---|
| 798 | ROAR_ERR("Can not set UserID: %s", strerror(errno)); |
---|
| 799 | return 3; |
---|
| 800 | } |
---|
| 801 | clients_set_uid(g_self_client, getuid()); |
---|
| 802 | } |
---|
[1486] | 803 | #endif |
---|
[444] | 804 | |
---|
[0] | 805 | // start main loop... |
---|
[905] | 806 | main_loop(drvid, drvinst, &sa, sysclocksync); |
---|
[0] | 807 | |
---|
| 808 | // clean up. |
---|
| 809 | clean_quit_prep(); |
---|
| 810 | driver_close(drvinst, drvid); |
---|
| 811 | output_buffer_free(); |
---|
| 812 | |
---|
| 813 | return 0; |
---|
| 814 | } |
---|
| 815 | |
---|
[574] | 816 | void cleanup_listen_socket (int terminate) { |
---|
[580] | 817 | |
---|
[1494] | 818 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[580] | 819 | if ( g_listen_socket != -1 ) { |
---|
[1486] | 820 | #ifdef ROAR_HAVE_IO_POSIX |
---|
[580] | 821 | close(g_listen_socket); |
---|
[1486] | 822 | #endif // #else is useless because we are in void context. |
---|
[60] | 823 | |
---|
[580] | 824 | g_listen_socket = -1; |
---|
[576] | 825 | |
---|
[1486] | 826 | #ifdef ROAR_HAVE_UNIX |
---|
[580] | 827 | if ( *server == '/' ) |
---|
| 828 | unlink(server); |
---|
[1486] | 829 | #endif |
---|
[580] | 830 | } |
---|
[60] | 831 | |
---|
[1494] | 832 | #endif |
---|
| 833 | |
---|
[574] | 834 | if ( terminate ) |
---|
| 835 | g_terminate = 1; |
---|
| 836 | } |
---|
| 837 | |
---|
| 838 | void clean_quit_prep (void) { |
---|
| 839 | cleanup_listen_socket(0); |
---|
[60] | 840 | |
---|
[0] | 841 | sources_free(); |
---|
| 842 | streams_free(); |
---|
| 843 | clients_free(); |
---|
[282] | 844 | midi_cb_stop(); // stop console beep |
---|
[281] | 845 | midi_free(); |
---|
[0] | 846 | } |
---|
| 847 | |
---|
| 848 | void clean_quit (void) { |
---|
| 849 | clean_quit_prep(); |
---|
| 850 | // driver_close(drvinst, drvid); |
---|
| 851 | // output_buffer_free(); |
---|
| 852 | exit(0); |
---|
| 853 | } |
---|
| 854 | |
---|
| 855 | //ll |
---|