1 | //roard.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
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, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include "roard.h" |
---|
27 | |
---|
28 | #ifdef ROAR_SUPPORT_LISTEN |
---|
29 | char * server[ROAR_MAX_LISTEN_SOCKETS]; |
---|
30 | #endif |
---|
31 | |
---|
32 | #if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_FS_POSIX) |
---|
33 | #define SUPPORT_PIDFILE |
---|
34 | char * pidfile = NULL; |
---|
35 | #endif |
---|
36 | |
---|
37 | #if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID) |
---|
38 | int setids = 0; |
---|
39 | #endif |
---|
40 | |
---|
41 | #ifdef ROAR_HAVE_LIBX11 |
---|
42 | char * x11display = NULL; |
---|
43 | #endif |
---|
44 | |
---|
45 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
46 | void usage (void) { |
---|
47 | printf("Usage: roard [OPTIONS]...\n\n"); |
---|
48 | |
---|
49 | printf("Misc Options:\n\n"); |
---|
50 | printf( |
---|
51 | " --daemon - Bring the server into background after init\n" |
---|
52 | " --verbose - Be more verbose, can be used multiple times\n" |
---|
53 | " --terminate - Terminate after last client quited\n" |
---|
54 | " --start - No op parameter (starting roard is default operation)\n" |
---|
55 | " --restart - Trys to stop an old instance and start a new with new settings\n" |
---|
56 | " --stop - Stops a running roard (provide --pidfile!)\n" |
---|
57 | " --shutdown - Terminates a running roard (provide --pidfile!)\n" |
---|
58 | " --realtime - Trys to get realtime priority,\n" |
---|
59 | " give multible times for being more realtime\n" |
---|
60 | " --chroot DIR - chroots to the given dir\n" |
---|
61 | " --setgid - GroupID to the audio group as specified via -G\n" |
---|
62 | " --setuid - UserID to the audio user as specified via -U\n" |
---|
63 | " --sysclocksync - calculate exact sample rate using the system clock\n" |
---|
64 | " --location LOC - Set lion readable location of server\n" |
---|
65 | #ifdef SUPPORT_PIDFILE |
---|
66 | " --pidfile PIDFILE - Write a pidfile at PIDFILE\n" |
---|
67 | #endif |
---|
68 | #ifdef ROAR_HAVE_SYSLOG |
---|
69 | " --log-syslog - Log Warnings, Errors, ... to syslog\n" |
---|
70 | #endif |
---|
71 | ); |
---|
72 | |
---|
73 | printf("\nPlugin Options:\n\n"); |
---|
74 | printf( |
---|
75 | " --plugin-load FILE - Load plugin FILE\n" |
---|
76 | ); |
---|
77 | |
---|
78 | printf("\nAudio Options:\n\n"); |
---|
79 | printf( |
---|
80 | " -R --rate RATE - Set server rate\n" |
---|
81 | " -B --bits BITS - Set server bits\n" |
---|
82 | " -C --chans CHANNELS - Set server channels\n" |
---|
83 | ); |
---|
84 | |
---|
85 | printf("\nStream Options:\n\n"); |
---|
86 | printf( |
---|
87 | " --stream-flags D=F - Set default flags for stream directions\n" |
---|
88 | " D is the stream direction and F is a comma seperated\n" |
---|
89 | " list of flags in form +flag or -flag to set or unset\n" |
---|
90 | " a flag as default or remove it from the default\n" |
---|
91 | ); |
---|
92 | |
---|
93 | printf("\nDriver Options: (obsolete, do not use, Use Ouput Options)\n\n"); |
---|
94 | printf(" -d --driver DRV - Set the driver (default: %s)\n", ROAR_DRIVER_DEFAULT); |
---|
95 | printf(" -D --device DEV - Set the device\n"); |
---|
96 | printf(" -dO OPTS - Set output options\n"); |
---|
97 | printf(" --list-driver - List all drivers\n"); |
---|
98 | |
---|
99 | printf("\nOutput Options:\n\n"); |
---|
100 | printf(" -o --odriver DRV - Set the driver, use '--list-driver' to get a list\n"); |
---|
101 | printf(" -O --odevice DEV - Set the device\n"); |
---|
102 | printf(" -oO OPTS - Set output options\n"); |
---|
103 | printf(" -oN - Adds another output\n"); |
---|
104 | printf(" -oP - Mark output as primary\n"); |
---|
105 | |
---|
106 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
107 | printf("\nSource Options:\n\n"); |
---|
108 | printf(" -s --source DRV - Use DRV as input driver\n" |
---|
109 | " -S DEV - Use DEV as input device\n" |
---|
110 | " -sO OPTS - Use OPTS as input options\n" |
---|
111 | " -sN - Adds another source\n" |
---|
112 | " -sP - Make souce as primary\n" |
---|
113 | ); |
---|
114 | printf(" --list-sources - List all sources\n"); |
---|
115 | #endif |
---|
116 | |
---|
117 | printf("\nCodec Filter Options:\n\n"); |
---|
118 | printf(" --list-cf - List all codec filter\n" |
---|
119 | ); |
---|
120 | |
---|
121 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
122 | printf("\nMIDI Options:\n\n"); |
---|
123 | printf(" --midi-no-console - Disable console based MIDI synth\n" |
---|
124 | " --midi-console-enable - Enables the console based MIDI synth\n" |
---|
125 | " --midi-console DEV - Set device for MIDI console\n" |
---|
126 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
127 | " --ssynth-enable - Enable simple software synth\n" |
---|
128 | " --ssynth-disable - Disable simple software synth\n" |
---|
129 | #endif |
---|
130 | ); |
---|
131 | #endif |
---|
132 | |
---|
133 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
134 | printf("\nLight Control Options:\n\n"); |
---|
135 | printf(" --light-channels NUM - Sets the number of channels for Light control (default: %i)\n", |
---|
136 | LIGHT_CHANNELS_DEFAULT |
---|
137 | ); |
---|
138 | #endif |
---|
139 | |
---|
140 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
141 | printf("\nRadio Data and Transmitter Control System Options:\n\n"); |
---|
142 | printf(" --rds-pi PI - Sets the RDS Programme Identification (PI)\n" |
---|
143 | " --rds-ps PS - Sets the RDS Programme Service Name (PS)\n" |
---|
144 | " --rds-pty PTY - Sets the RDS Programme Type (PTY)\n" |
---|
145 | " --rds-tp - Sets the RDS Traffic Programme (TP) flag\n" |
---|
146 | " --rds-ct - Enables sending of RDS Clock Time (CT)\n" |
---|
147 | ); |
---|
148 | #endif |
---|
149 | |
---|
150 | #ifdef ROAR_HAVE_LIBX11 |
---|
151 | printf("\nX11 Options:\n\n"); |
---|
152 | printf( |
---|
153 | " --x11-display DISPLAY - Set display for X11\n" |
---|
154 | " --display DISPLAY - Set display for X11\n" |
---|
155 | ); |
---|
156 | #endif |
---|
157 | |
---|
158 | printf("\nServer Options:\n\n"); |
---|
159 | printf(" -t --tcp - Use TCP listen socket\n" |
---|
160 | " -u --unix - Use UNIX Domain listen socket (default)\n" |
---|
161 | #ifdef ROAR_HAVE_LIBDNET |
---|
162 | " -n --decnet - use DECnet listen socket\n" |
---|
163 | #endif |
---|
164 | " -4 - Use IPv4 connections (implies -t)\n" |
---|
165 | #ifdef PF_INET6 |
---|
166 | " -6 - Use IPv6 connections (implies -t)\n" |
---|
167 | #endif |
---|
168 | #ifdef IPV6_ADDRFORM |
---|
169 | " -64 - Try to downgrade sockets from IPv6 into IPv4,\n" |
---|
170 | " this is normaly not usefull.\n" |
---|
171 | #endif |
---|
172 | " -p --port - TCP Port to bind to\n" |
---|
173 | " -b --bind - IP/Hostname to bind to\n" |
---|
174 | " --sock - Filename for UNIX Domain Socket\n" |
---|
175 | " --proto PROTO - Use PROTO as protocol on Socket\n" |
---|
176 | " --proto-dir DIR - Set direction parameter for protocol\n" |
---|
177 | " --proto-rate RATE - Set sample rate parameter for protocol\n" |
---|
178 | " --proto-bits BITS - Set bits per sample parameter for protocol\n" |
---|
179 | " --proto-codec E - Set codec parameter for protocol\n" |
---|
180 | " --proto-chans C - Set number of channels paramter for protocol\n" |
---|
181 | " --list-proto - List supported protocols\n" |
---|
182 | " --new-sock - Parameters for new socket follows\n" |
---|
183 | #ifdef ROAR_HAVE_LIBSLP |
---|
184 | " --slp - Enable OpenSLP support\n" |
---|
185 | #endif |
---|
186 | #ifdef ROAR_HAVE_LIBX11 |
---|
187 | " --x11 - Enable X11 support\n" |
---|
188 | #endif |
---|
189 | " --jumbo-mtu MTU - Sets the MTU for Jumbo Packets\n" |
---|
190 | " -G GROUP - Sets the group for the UNIX Domain Socket, (default: %s)\n" |
---|
191 | " You need the permissions to change the GID\n" |
---|
192 | " -U USER - Sets the user for the UNIX Domain Socket, (default: do not set)\n" |
---|
193 | " You need the permissions to change the UID (normaly only root has)\n" |
---|
194 | " --no-listen - Do not listen for new clients\n" |
---|
195 | " (only usefull for relaing, impleys --terminate)\n" |
---|
196 | " --client-fh - Comunicate with a client over this handle\n" |
---|
197 | " (only usefull for relaing)\n" |
---|
198 | " --close-fh - Closes the given fh\n" |
---|
199 | " --standby - Start in standby state\n" |
---|
200 | " --auto-standby - Automatical goes into standby if there are no streams\n", |
---|
201 | #ifdef ROAR_DEFAULT_SOCKGRP |
---|
202 | ROAR_DEFAULT_SOCKGRP |
---|
203 | #else |
---|
204 | "(none)" |
---|
205 | #endif |
---|
206 | ); |
---|
207 | // printf("\n Options:\n\n"); |
---|
208 | printf("\n"); |
---|
209 | } |
---|
210 | |
---|
211 | static void list_proto (void) { |
---|
212 | printf(" Protocol Flag Subsys - Description\n"); |
---|
213 | printf("------------------------------------------------------\n"); |
---|
214 | printf(" roar WM LRX - RoarAudio native protocol\n"); |
---|
215 | #if !defined(ROAR_WITHOUT_DCOMP_EMUL_ESD) && defined(ROAR_HAVE_H_ESD) |
---|
216 | printf(" esd W - EsounD emulation\n"); |
---|
217 | #endif |
---|
218 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE |
---|
219 | printf(" simple WM LRX - PulseAudio simple protocol\n"); |
---|
220 | #endif |
---|
221 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND |
---|
222 | printf(" rsound W - RSound emulation\n"); |
---|
223 | #endif |
---|
224 | } |
---|
225 | |
---|
226 | #endif |
---|
227 | |
---|
228 | int restart_server (char * server, int terminate) { |
---|
229 | struct roar_connection con; |
---|
230 | #ifdef ROAR_HAVE_KILL |
---|
231 | char buf[80]; |
---|
232 | ssize_t l; |
---|
233 | struct roar_vio_calls fh; |
---|
234 | pid_t pid; |
---|
235 | int ok; |
---|
236 | |
---|
237 | if ( pidfile != NULL ) { |
---|
238 | if ( roar_vio_open_file(&fh, pidfile, O_RDONLY, 0644) == -1 ) { |
---|
239 | ROAR_WARN("restart_server(*): Can not read pidfile: %s", pidfile); |
---|
240 | } else { |
---|
241 | l = roar_vio_read(&fh, buf, 80); |
---|
242 | roar_vio_close(&fh); |
---|
243 | if ( l > 0 ) { |
---|
244 | buf[l-1] = 0; |
---|
245 | buf[79] = 0; |
---|
246 | pid = atoi(buf); |
---|
247 | if ( terminate ) { |
---|
248 | ok = kill(pid, SIGUSR1); |
---|
249 | } else { |
---|
250 | ok = kill(pid, SIGINT); |
---|
251 | } |
---|
252 | if ( ok == 0 ) { |
---|
253 | return 0; |
---|
254 | } else { |
---|
255 | ROAR_WARN("restart_server(*): Can not kill roard by pidfile"); |
---|
256 | } |
---|
257 | } else { |
---|
258 | ROAR_WARN("restart_server(*): Can not find a PID in the pidfile"); |
---|
259 | } |
---|
260 | } |
---|
261 | } |
---|
262 | #endif |
---|
263 | |
---|
264 | if ( roar_connect(&con, server) == -1 ) { |
---|
265 | return -1; |
---|
266 | } |
---|
267 | |
---|
268 | if ( roar_terminate(&con, terminate) == -1 ) { |
---|
269 | return -1; |
---|
270 | } |
---|
271 | |
---|
272 | return roar_disconnect(&con); |
---|
273 | } |
---|
274 | |
---|
275 | #define R_SETUID 1 |
---|
276 | #define R_SETGID 2 |
---|
277 | |
---|
278 | int init_config (void) { |
---|
279 | int i; |
---|
280 | |
---|
281 | memset(g_config, 0, sizeof(struct roard_config)); |
---|
282 | |
---|
283 | for (i = 0; i < ROAR_DIR_DIRIDS; i++) { |
---|
284 | g_config->streams[i].mixer_channels = 1; |
---|
285 | g_config->streams[i].mixer.rpg_mul = 1; |
---|
286 | g_config->streams[i].mixer.rpg_div = 1; |
---|
287 | g_config->streams[i].mixer.scale = 65535; |
---|
288 | g_config->streams[i].mixer.mixer[0] = g_config->streams[i].mixer.scale; |
---|
289 | } |
---|
290 | |
---|
291 | g_config->streams[ROAR_DIR_PLAY ].flags = ROAR_FLAG_META; |
---|
292 | g_config->streams[ROAR_DIR_OUTPUT ].flags = ROAR_FLAG_PASSMIXER; |
---|
293 | g_config->streams[ROAR_DIR_FILTER ].flags = ROAR_FLAG_SYNC; |
---|
294 | g_config->streams[ROAR_DIR_MIDI_OUT].flags = ROAR_FLAG_SYNC; |
---|
295 | g_config->streams[ROAR_DIR_BIDIR ].flags = ROAR_FLAG_ANTIECHO; |
---|
296 | |
---|
297 | g_config->location = "***default***"; |
---|
298 | |
---|
299 | return 0; |
---|
300 | } |
---|
301 | |
---|
302 | #ifdef ROAR_SUPPORT_LISTEN |
---|
303 | int init_listening (void) { |
---|
304 | int i; |
---|
305 | |
---|
306 | memset(g_listen, 0, sizeof(g_listen)); |
---|
307 | |
---|
308 | for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) { |
---|
309 | g_listen[i].socket = -1; |
---|
310 | g_listen[i].proto = ROAR_PROTO_ROARAUDIO; |
---|
311 | server[i] = NULL; |
---|
312 | } |
---|
313 | |
---|
314 | return 0; |
---|
315 | } |
---|
316 | |
---|
317 | int get_listen(struct roard_listen ** sock, char *** sockname) { |
---|
318 | int i; |
---|
319 | |
---|
320 | if ( sock == NULL ) |
---|
321 | return -1; |
---|
322 | |
---|
323 | for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) { |
---|
324 | if ( g_listen[i].socket == -1 ) { |
---|
325 | server[i] = NULL; |
---|
326 | *sock = &(g_listen[i]); |
---|
327 | |
---|
328 | if ( sockname != NULL ) |
---|
329 | *sockname = &(server[i]); |
---|
330 | |
---|
331 | return 0; |
---|
332 | } |
---|
333 | } |
---|
334 | |
---|
335 | return -1; |
---|
336 | } |
---|
337 | |
---|
338 | int add_listen (char * addr, int port, int sock_type, char * user, char * group, int proto, int dir, struct roar_audio_info * info) { |
---|
339 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
340 | struct group * grp = NULL; |
---|
341 | #endif |
---|
342 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
343 | struct passwd * pwd = NULL; |
---|
344 | #endif |
---|
345 | #ifdef ROAR_HAVE_UNIX |
---|
346 | char * env_roar_proxy_backup; |
---|
347 | #endif |
---|
348 | int sockid = -1; |
---|
349 | int sock; |
---|
350 | int i; |
---|
351 | |
---|
352 | if ( *addr != 0 ) { |
---|
353 | for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) { |
---|
354 | if ( g_listen[i].socket == -1 ) { |
---|
355 | sockid = i; |
---|
356 | break; |
---|
357 | } |
---|
358 | } |
---|
359 | |
---|
360 | if ( sockid == -1 ) |
---|
361 | return -1; |
---|
362 | |
---|
363 | g_listen[sockid].proto = proto; |
---|
364 | |
---|
365 | ROAR_DBG("add_listen(*): proto=0x%.4x", proto); |
---|
366 | |
---|
367 | if ( (g_listen[sockid].socket = roar_socket_listen(sock_type, addr, port)) == -1 ) { |
---|
368 | #ifdef ROAR_HAVE_UNIX |
---|
369 | if ( *addr == '/' ) { |
---|
370 | if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) { |
---|
371 | env_roar_proxy_backup = strdup(env_roar_proxy_backup); |
---|
372 | unsetenv("ROAR_PROXY"); |
---|
373 | } |
---|
374 | if ( (sock = roar_socket_connect(addr, port)) != -1 ) { |
---|
375 | close(sock); |
---|
376 | ROAR_ERR("Can not open listen socket: Socket allready in use"); |
---|
377 | return 1; |
---|
378 | } else { |
---|
379 | unlink(addr); |
---|
380 | if ( (g_listen[sockid].socket = roar_socket_listen(sock_type, addr, port)) == -1 ) { |
---|
381 | ROAR_ERR("Can not open listen socket: %s", strerror(errno)); |
---|
382 | return 1; |
---|
383 | } |
---|
384 | } |
---|
385 | if ( env_roar_proxy_backup != NULL ) { |
---|
386 | setenv("ROAR_PROXY", env_roar_proxy_backup, 0); |
---|
387 | free(env_roar_proxy_backup); |
---|
388 | } |
---|
389 | #else |
---|
390 | if (0) { // noop |
---|
391 | #endif |
---|
392 | } else { |
---|
393 | ROAR_ERR("Can not open listen socket: %s", strerror(errno)); |
---|
394 | return 1; |
---|
395 | } |
---|
396 | } |
---|
397 | |
---|
398 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
399 | if ( group != NULL ) { |
---|
400 | if ( (grp = getgrnam(group)) == NULL ) { |
---|
401 | ROAR_ERR("Can not get GID for group %s: %s", group, strerror(errno)); |
---|
402 | } |
---|
403 | } |
---|
404 | #endif |
---|
405 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
406 | if ( user ) { |
---|
407 | if ( (pwd = getpwnam(user)) == NULL ) { |
---|
408 | ROAR_ERR("Can not get UID for user %s: %s", user, strerror(errno)); |
---|
409 | } |
---|
410 | } |
---|
411 | #endif |
---|
412 | |
---|
413 | #if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_UNIX) |
---|
414 | if ( *addr == '/' ) { |
---|
415 | if ( grp || pwd ) { |
---|
416 | if ( chown(addr, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 ) |
---|
417 | return 1; |
---|
418 | } |
---|
419 | #ifdef ROAR_HAVE_GETUID |
---|
420 | if ( grp ) { |
---|
421 | if ( getuid() == 0 ) |
---|
422 | if ( chmod(addr, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1 ) |
---|
423 | return 1; |
---|
424 | } |
---|
425 | #endif |
---|
426 | } |
---|
427 | #endif |
---|
428 | } |
---|
429 | |
---|
430 | // in case we opened the listening socket correctly. |
---|
431 | if ( dir == -1 ) |
---|
432 | dir = ROAR_DIR_PLAY; |
---|
433 | |
---|
434 | g_listen[sockid].inst.stpl.dir = dir; |
---|
435 | memcpy(&(g_listen[sockid].inst.stpl.info), info, sizeof(struct roar_audio_info)); |
---|
436 | |
---|
437 | switch (dir) { |
---|
438 | case ROAR_DIR_PLAY: |
---|
439 | case ROAR_DIR_RECORD: |
---|
440 | case ROAR_DIR_MONITOR: |
---|
441 | case ROAR_DIR_FILTER: |
---|
442 | case ROAR_DIR_BIDIR: |
---|
443 | if ( !g_listen[sockid].inst.stpl.info.rate ) |
---|
444 | g_listen[sockid].inst.stpl.info.rate = g_sa->rate; |
---|
445 | |
---|
446 | if ( !g_listen[sockid].inst.stpl.info.bits ) |
---|
447 | g_listen[sockid].inst.stpl.info.bits = g_sa->bits; |
---|
448 | |
---|
449 | if ( !g_listen[sockid].inst.stpl.info.channels ) |
---|
450 | g_listen[sockid].inst.stpl.info.channels = g_sa->channels; |
---|
451 | |
---|
452 | if ( !g_listen[sockid].inst.stpl.info.codec ) |
---|
453 | g_listen[sockid].inst.stpl.info.codec = g_sa->codec; |
---|
454 | break; |
---|
455 | } |
---|
456 | |
---|
457 | server[sockid] = addr; |
---|
458 | return 0; |
---|
459 | } |
---|
460 | #endif |
---|
461 | |
---|
462 | int update_stream_flags (char * str) { |
---|
463 | int dir; |
---|
464 | char * flags; |
---|
465 | char * k; |
---|
466 | int op; |
---|
467 | int flag; |
---|
468 | |
---|
469 | if ( (flags = strstr(str, "=")) == NULL ) |
---|
470 | return -1; |
---|
471 | |
---|
472 | *flags = 0; |
---|
473 | flags++; |
---|
474 | |
---|
475 | if ( (dir = roar_str2dir(str)) == -1 ) |
---|
476 | return -1; |
---|
477 | |
---|
478 | while (flags != NULL) { |
---|
479 | k = flags; |
---|
480 | flags = strstr(flags, ","); |
---|
481 | |
---|
482 | if ( flags != NULL ) |
---|
483 | *(flags++) = 0; |
---|
484 | |
---|
485 | switch (*k) { |
---|
486 | case '+': k++; op = ROAR_SET_FLAG; break; |
---|
487 | case '-': k++; op = ROAR_RESET_FLAG; break; |
---|
488 | default: |
---|
489 | op = ROAR_SET_FLAG; |
---|
490 | } |
---|
491 | |
---|
492 | flag = 0; |
---|
493 | |
---|
494 | if ( !strcmp(k, "sync") ) { |
---|
495 | flag = ROAR_FLAG_SYNC; |
---|
496 | } else if ( !strcmp(k, "meta") ) { |
---|
497 | flag = ROAR_FLAG_META; |
---|
498 | } else if ( !strcmp(k, "cleanmeta") ) { |
---|
499 | flag = ROAR_FLAG_CLEANMETA; |
---|
500 | } else if ( !strcmp(k, "pause") ) { |
---|
501 | flag = ROAR_FLAG_PAUSE; |
---|
502 | } else if ( !strcmp(k, "mute") ) { |
---|
503 | flag = ROAR_FLAG_MUTE; |
---|
504 | } else if ( !strcmp(k, "antiecho") ) { |
---|
505 | flag = ROAR_FLAG_ANTIECHO; |
---|
506 | } else if ( !strcmp(k, "passmixer") ) { |
---|
507 | flag = ROAR_FLAG_PASSMIXER; |
---|
508 | } else { |
---|
509 | return -1; |
---|
510 | } |
---|
511 | |
---|
512 | g_config->streams[dir].flags |= flag; |
---|
513 | |
---|
514 | if ( op == ROAR_RESET_FLAG ) |
---|
515 | g_config->streams[dir].flags -= flag; |
---|
516 | } |
---|
517 | |
---|
518 | return 0; |
---|
519 | } |
---|
520 | |
---|
521 | int add_output (char * drv, char * dev, char * opts, int prim, int count) { |
---|
522 | int stream; |
---|
523 | struct roar_stream * s; |
---|
524 | struct roar_stream_server * ss; |
---|
525 | char * k, * v; |
---|
526 | #ifdef ROAR_DRIVER_CODEC |
---|
527 | char * to_free = NULL; |
---|
528 | #endif |
---|
529 | int sync = 0, f_mmap = 0; |
---|
530 | int32_t blocks = -1, blocksize = -1; |
---|
531 | int dir = ROAR_DIR_OUTPUT; |
---|
532 | int error = 0; |
---|
533 | // DMX: |
---|
534 | int32_t channel = -1; |
---|
535 | int32_t universe = -1; |
---|
536 | uint16_t tu16; |
---|
537 | float q = -32e6; |
---|
538 | |
---|
539 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
540 | |
---|
541 | if ( drv == NULL && count == 0 ) { |
---|
542 | drv = ROAR_DRIVER_DEFAULT; |
---|
543 | prim = 1; |
---|
544 | sync = 1; |
---|
545 | |
---|
546 | #ifdef ROAR_DRIVER_CODEC |
---|
547 | if ( opts == NULL ) { |
---|
548 | opts = to_free = strdup("codec=" ROAR_DRIVER_CODEC); |
---|
549 | } |
---|
550 | #endif |
---|
551 | } |
---|
552 | |
---|
553 | if ( opts == NULL && count == 0 ) { |
---|
554 | sync = 1; |
---|
555 | prim = 1; // if ( prim == 0 ) prim = 1; -> prim allways = 1 |
---|
556 | } |
---|
557 | |
---|
558 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
559 | |
---|
560 | if ( (stream = streams_new()) == -1 ) { |
---|
561 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts); |
---|
562 | if ( prim ) alive = 0; |
---|
563 | return -1; |
---|
564 | } |
---|
565 | |
---|
566 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
567 | |
---|
568 | streams_get(stream, &ss); |
---|
569 | s = ROAR_STREAM(ss); |
---|
570 | |
---|
571 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
572 | |
---|
573 | memset(&(s->info), 0xFF, sizeof(struct roar_audio_info)); // set everything to -1 |
---|
574 | |
---|
575 | s->pos_rel_id = -1; |
---|
576 | // s->info.codec = codec; |
---|
577 | |
---|
578 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
579 | |
---|
580 | if ( opts == NULL ) { |
---|
581 | k = NULL; |
---|
582 | } else { |
---|
583 | k = strtok(opts, ","); |
---|
584 | } |
---|
585 | |
---|
586 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s'): initial k='%s'(%p)", drv, dev, opts, k, k); |
---|
587 | |
---|
588 | while (k != NULL) { |
---|
589 | // ROAR_WARN("add_output(*): opts: %s", k); |
---|
590 | |
---|
591 | if ( (v = strstr(k, "=")) != NULL ) { |
---|
592 | *v++ = 0; |
---|
593 | } |
---|
594 | |
---|
595 | ROAR_DBG("add_output(*): opts: k='%s', v='%s'", k, v); |
---|
596 | if ( strcmp(k, "rate") == 0 ) { |
---|
597 | s->info.rate = atoi(v); |
---|
598 | } else if ( strcmp(k, "channels") == 0 ) { |
---|
599 | s->info.channels = atoi(v); |
---|
600 | } else if ( strcmp(k, "bits") == 0 ) { |
---|
601 | s->info.bits = atoi(v); |
---|
602 | } else if ( strcmp(k, "codec") == 0 ) { |
---|
603 | if ( (s->info.codec = roar_str2codec(v)) == -1 ) { |
---|
604 | ROAR_ERR("add_output(*): unknown codec '%s'", v); |
---|
605 | error++; |
---|
606 | } |
---|
607 | } else if ( strcmp(k, "q") == 0 ) { |
---|
608 | q = atof(v); |
---|
609 | } else if ( strcmp(k, "blocks") == 0 ) { |
---|
610 | blocks = atoi(v); |
---|
611 | } else if ( strcmp(k, "blocksize") == 0 ) { |
---|
612 | blocksize = atoi(v); |
---|
613 | } else if ( strcmp(k, "mmap") == 0 ) { |
---|
614 | f_mmap = 1; |
---|
615 | } else if ( strcmp(k, "subsystem") == 0 ) { |
---|
616 | if ( !strcasecmp(v, "wave") || !strcasecmp(v, "waveform") ) { |
---|
617 | dir = ROAR_DIR_OUTPUT; |
---|
618 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
619 | } else if ( !strcasecmp(v, "midi") ) { |
---|
620 | dir = ROAR_DIR_MIDI_OUT; |
---|
621 | #endif |
---|
622 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
623 | } else if ( !strcasecmp(v, "light") ) { |
---|
624 | dir = ROAR_DIR_LIGHT_OUT; |
---|
625 | #endif |
---|
626 | #ifndef ROAR_WITHOUT_DCOMP_RAW |
---|
627 | } else if ( !strcasecmp(v, "raw") ) { |
---|
628 | dir = ROAR_DIR_RAW_OUT; |
---|
629 | #endif |
---|
630 | } else if ( !strcasecmp(v, "complex") ) { |
---|
631 | dir = ROAR_DIR_COMPLEX_OUT; |
---|
632 | } else { |
---|
633 | ROAR_ERR("add_output(*): unknown/unsupported subsystem '%s'", k); |
---|
634 | error++; |
---|
635 | } |
---|
636 | // DMX: |
---|
637 | } else if ( strcmp(k, "channel") == 0 ) { |
---|
638 | channel = atoi(v); |
---|
639 | if ( channel < 0 || channel > 65535 ) { |
---|
640 | ROAR_ERR("add_output(*): Invalide channel (not within 0..65535): %i", channel); |
---|
641 | channel = -1; |
---|
642 | error++; |
---|
643 | } |
---|
644 | } else if ( strcmp(k, "universe") == 0 ) { |
---|
645 | universe = atoi(v); |
---|
646 | if ( universe < 0 || universe > 255 ) { |
---|
647 | ROAR_ERR("add_output(*): Invalide universe (not within 0..255): %i", universe); |
---|
648 | universe = -1; |
---|
649 | error++; |
---|
650 | } |
---|
651 | |
---|
652 | } else if ( strcmp(k, "name") == 0 ) { |
---|
653 | if ( streams_set_name(stream, v) == -1 ) { |
---|
654 | ROAR_ERR("add_output(*): Can not set Stream name"); |
---|
655 | error++; |
---|
656 | } |
---|
657 | |
---|
658 | } else if ( strcmp(k, "meta") == 0 ) { |
---|
659 | streams_set_flag(stream, ROAR_FLAG_META); |
---|
660 | } else if ( strcmp(k, "sync") == 0 ) { |
---|
661 | sync = 1; |
---|
662 | } else if ( strcmp(k, "primary") == 0 ) { |
---|
663 | prim = 1; |
---|
664 | |
---|
665 | } else if ( strcmp(k, "cleanmeta") == 0 ) { |
---|
666 | streams_set_flag(stream, ROAR_FLAG_CLEANMETA); |
---|
667 | } else if ( strcmp(k, "autoconf") == 0 ) { |
---|
668 | streams_set_flag(stream, ROAR_FLAG_AUTOCONF); |
---|
669 | } else if ( strcmp(k, "recsource") == 0 ) { |
---|
670 | streams_set_flag(stream, ROAR_FLAG_RECSOURCE); |
---|
671 | } else if ( strcmp(k, "passmixer") == 0 ) { |
---|
672 | streams_set_flag(stream, ROAR_FLAG_PASSMIXER); |
---|
673 | } else { |
---|
674 | ROAR_ERR("add_output(*): unknown option '%s'", k); |
---|
675 | error++; |
---|
676 | } |
---|
677 | |
---|
678 | if ( error ) { |
---|
679 | streams_delete(stream); |
---|
680 | if ( prim ) alive = 0; |
---|
681 | #ifdef ROAR_DRIVER_CODEC |
---|
682 | if ( to_free != NULL ) |
---|
683 | free(to_free); |
---|
684 | #endif |
---|
685 | return -1; |
---|
686 | } |
---|
687 | |
---|
688 | k = strtok(NULL, ","); |
---|
689 | } |
---|
690 | |
---|
691 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts); |
---|
692 | |
---|
693 | // set audio info... |
---|
694 | switch (dir) { |
---|
695 | case ROAR_DIR_LIGHT_OUT: |
---|
696 | switch (s->info.codec) { |
---|
697 | case ROAR_CODEC_DMX512: |
---|
698 | case -1: |
---|
699 | if ( s->info.rate == -1 ) |
---|
700 | s->info.rate = ROAR_OUTPUT_CFREQ; |
---|
701 | |
---|
702 | s->info.channels = 0; |
---|
703 | s->info.bits = 8; |
---|
704 | s->info.codec = ROAR_CODEC_DMX512; // in case codec == -1 |
---|
705 | break; |
---|
706 | } |
---|
707 | break; |
---|
708 | case ROAR_DIR_MIDI_OUT: |
---|
709 | switch (s->info.codec) { |
---|
710 | case ROAR_CODEC_MIDI: |
---|
711 | case -1: |
---|
712 | if ( s->info.rate == -1 ) |
---|
713 | s->info.rate = ROAR_MIDI_TICKS_PER_BEAT; |
---|
714 | |
---|
715 | s->info.channels = ROAR_MIDI_CHANNELS_DEFAULT; |
---|
716 | s->info.bits = ROAR_MIDI_BITS; |
---|
717 | s->info.codec = ROAR_CODEC_MIDI; // in case codec == -1 |
---|
718 | break; |
---|
719 | } |
---|
720 | break; |
---|
721 | case ROAR_DIR_RAW_OUT: |
---|
722 | if ( s->info.rate == -1 ) |
---|
723 | s->info.rate = 0; |
---|
724 | if ( s->info.bits == -1 ) |
---|
725 | s->info.bits = 0; |
---|
726 | if ( s->info.channels == -1 ) |
---|
727 | s->info.channels = 0; |
---|
728 | if ( s->info.codec == -1 ) |
---|
729 | s->info.codec = 0; |
---|
730 | break; |
---|
731 | } |
---|
732 | |
---|
733 | if ( s->info.rate == -1 ) |
---|
734 | s->info.rate = g_sa->rate; |
---|
735 | if ( s->info.bits == -1 ) |
---|
736 | s->info.bits = g_sa->bits; |
---|
737 | if ( s->info.channels == -1 ) |
---|
738 | s->info.channels = g_sa->channels; |
---|
739 | if ( s->info.codec == -1 ) |
---|
740 | s->info.codec = g_sa->codec; |
---|
741 | |
---|
742 | ROAR_DBG("add_output(*): s->info = {.rate=%i, .bits=%i, .channels=%i, .codec=%i}", s->info.rate, s->info.bits, s->info.channels, s->info.codec); |
---|
743 | |
---|
744 | if ( streams_set_dir(stream, dir, 1) == -1 ) { |
---|
745 | streams_delete(stream); |
---|
746 | return -1; |
---|
747 | } |
---|
748 | |
---|
749 | #ifdef ROAR_DRIVER_CODEC |
---|
750 | if ( to_free != NULL ) |
---|
751 | free(to_free); |
---|
752 | #endif |
---|
753 | |
---|
754 | if ( s->info.codec == ROAR_CODEC_ALAW || s->info.codec == ROAR_CODEC_MULAW ) |
---|
755 | s->info.bits = 8; // needed to open OSS driver, will be overriden by codecfilter |
---|
756 | |
---|
757 | ROAR_STREAM_SERVER(s)->codec_orgi = s->info.codec; |
---|
758 | |
---|
759 | if ( driver_openvio(&(ss->vio), &(ss->driver_id), drv, dev, &(s->info), -1, ss) == -1 ) { |
---|
760 | ss->driver_id = -1; // don't close a driver not opened... |
---|
761 | memset(&(ss->vio), 0, sizeof(struct roar_vio_calls)); |
---|
762 | streams_delete(stream); |
---|
763 | ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts); |
---|
764 | if ( prim ) alive = 0; |
---|
765 | return -1; |
---|
766 | } |
---|
767 | |
---|
768 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAMID, &stream); // ignore errors here |
---|
769 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAM, s); // ignore errors here |
---|
770 | |
---|
771 | if ( blocks != -1 ) |
---|
772 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLOCKS, &blocks); |
---|
773 | |
---|
774 | if ( blocksize != -1 ) |
---|
775 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLKSIZE, &blocksize); |
---|
776 | |
---|
777 | // TODO: we shoudld *really* check for errors here... |
---|
778 | if ( channel != -1 ) { |
---|
779 | tu16 = channel; |
---|
780 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXSCHAN, &tu16); |
---|
781 | } |
---|
782 | if ( universe != -1 ) { |
---|
783 | tu16 = universe; |
---|
784 | roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXUNIV, &tu16); |
---|
785 | } |
---|
786 | |
---|
787 | ROAR_DBG("add_output(*): ss->driver_id=%i", ss->driver_id); |
---|
788 | |
---|
789 | streams_set_fh(stream, -1); // update some internal structures |
---|
790 | |
---|
791 | if ( q > -1e6 ) { |
---|
792 | ROAR_DBG("add_output(*): setting q=%f", q); |
---|
793 | streams_ctl(stream, ROAR_CODECFILTER_CTL_SET_Q|ROAR_STREAM_CTL_TYPE_FLOAT, &q); |
---|
794 | } |
---|
795 | |
---|
796 | client_stream_add(g_self_client, stream); |
---|
797 | |
---|
798 | if ( prim ) { |
---|
799 | streams_mark_primary(stream); |
---|
800 | s->pos_rel_id = stream; |
---|
801 | } |
---|
802 | |
---|
803 | if ( sync ) { |
---|
804 | streams_set_flag(stream, ROAR_FLAG_SYNC); |
---|
805 | } else { |
---|
806 | streams_reset_flag(stream, ROAR_FLAG_SYNC); |
---|
807 | } |
---|
808 | |
---|
809 | if ( f_mmap ) |
---|
810 | streams_set_flag(stream, ROAR_FLAG_MMAP); |
---|
811 | |
---|
812 | ROAR_DBG("add_output(*): s->info = {.rate=%i, .bits=%i, .channels=%i, .codec=%i}", s->info.rate, s->info.bits, s->info.channels, s->info.codec); |
---|
813 | return 0; |
---|
814 | } |
---|
815 | |
---|
816 | // X11: |
---|
817 | #ifdef ROAR_HAVE_LIBX11 |
---|
818 | int register_x11 (int unreg, char * sockname) { |
---|
819 | struct roar_x11_connection * x11con = NULL; |
---|
820 | int ret = 0; |
---|
821 | |
---|
822 | if ( (x11con = roar_x11_connect(x11display)) == NULL ) |
---|
823 | return -1; |
---|
824 | |
---|
825 | if ( unreg ) { |
---|
826 | if ( roar_x11_delete_prop(x11con, "ROAR_SERVER") == -1 ) |
---|
827 | ret = -1; |
---|
828 | } else { |
---|
829 | if ( roar_x11_set_prop(x11con, "ROAR_SERVER", sockname) == -1 ) |
---|
830 | ret = -1; |
---|
831 | } |
---|
832 | |
---|
833 | roar_x11_disconnect(x11con); |
---|
834 | |
---|
835 | return ret; |
---|
836 | } |
---|
837 | #endif |
---|
838 | |
---|
839 | // SLP: |
---|
840 | void register_slp_callback(SLPHandle hslp, SLPError errcode, void * cookie) { |
---|
841 | /* return the error code in the cookie */ |
---|
842 | *(SLPError*)cookie = errcode; |
---|
843 | } |
---|
844 | |
---|
845 | int register_slp (int unreg, char * sockname) { |
---|
846 | #ifdef ROAR_HAVE_LIBSLP |
---|
847 | static int regged = 0; |
---|
848 | static char * sn = NULL; |
---|
849 | SLPError err; |
---|
850 | SLPError callbackerr; |
---|
851 | SLPHandle hslp; |
---|
852 | char addr[1024]; |
---|
853 | char attr[1024] = ""; |
---|
854 | char * location; |
---|
855 | |
---|
856 | if ( sockname != NULL ) |
---|
857 | sn = sockname; |
---|
858 | |
---|
859 | snprintf(addr, sizeof(addr), ROAR_SLP_URL_TYPE_ROAR "://%s", sn); |
---|
860 | |
---|
861 | err = SLPOpen("en", SLP_FALSE, &hslp); |
---|
862 | |
---|
863 | if (err != SLP_OK) { |
---|
864 | ROAR_ERR("Error opening slp handle: Error #%i", err); |
---|
865 | return -1; |
---|
866 | } |
---|
867 | |
---|
868 | if (!unreg) { |
---|
869 | |
---|
870 | if ( SLPEscape(g_config->location, &location, SLP_FALSE) != SLP_OK ) { |
---|
871 | ROAR_ERR("Error using SLPEscape() on server location, really bad!"); |
---|
872 | SLPClose(hslp); |
---|
873 | return -1; |
---|
874 | } |
---|
875 | |
---|
876 | snprintf(attr, sizeof(attr), "(wave-rate=%i),(wave-channels=%i),(wave-bits=%i)," |
---|
877 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
878 | "(light-channels=%i)," |
---|
879 | #endif |
---|
880 | "(location=%s)", |
---|
881 | g_sa->rate, g_sa->channels, g_sa->bits, |
---|
882 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
883 | g_light_state.channels, |
---|
884 | #endif |
---|
885 | location |
---|
886 | ); |
---|
887 | |
---|
888 | /* Register a service with SLP */ |
---|
889 | err = SLPReg(hslp, |
---|
890 | addr, |
---|
891 | SLP_LIFETIME_MAXIMUM, |
---|
892 | 0, |
---|
893 | attr, |
---|
894 | SLP_TRUE, |
---|
895 | register_slp_callback, |
---|
896 | &callbackerr); |
---|
897 | regged = 1; |
---|
898 | } else if ( unreg && regged ) { |
---|
899 | err = SLPDereg(hslp, addr, register_slp_callback, &callbackerr); |
---|
900 | regged = 0; |
---|
901 | } else { |
---|
902 | SLPClose(hslp); |
---|
903 | return -1; |
---|
904 | } |
---|
905 | |
---|
906 | /* err may contain an error code that occurred as the slp library */ |
---|
907 | /* _prepared_ to make the call. */ |
---|
908 | if ( err != SLP_OK ) { |
---|
909 | ROAR_ERR("Error (de)registering service with slp: Error #%i", err); |
---|
910 | return -1; |
---|
911 | } |
---|
912 | |
---|
913 | /* callbackerr may contain an error code (that was assigned through */ |
---|
914 | /* the callback cookie) that occurred as slp packets were sent on */ |
---|
915 | /* the wire */ |
---|
916 | if (callbackerr != SLP_OK) { |
---|
917 | ROAR_ERR("Error (de)registering service with slp: Error #%i", callbackerr); |
---|
918 | return -1; |
---|
919 | } |
---|
920 | |
---|
921 | SLPClose(hslp); |
---|
922 | return 0; |
---|
923 | #else |
---|
924 | return -1; |
---|
925 | #endif |
---|
926 | } |
---|
927 | |
---|
928 | |
---|
929 | // MAIN: |
---|
930 | |
---|
931 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
932 | int main (int argc, char * argv[]) { |
---|
933 | #else |
---|
934 | int main (void) { |
---|
935 | #endif |
---|
936 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
937 | int i; |
---|
938 | char * k; |
---|
939 | #endif |
---|
940 | #if defined(ROAR_SUPPORT_LISTEN) && defined(ROAR_HAVE_GETUID) |
---|
941 | char user_sock[80] = {0}; |
---|
942 | #endif |
---|
943 | struct roar_audio_info sa, max_sa; |
---|
944 | struct roard_config config; |
---|
945 | #ifdef ROAR_HAVE_FORK |
---|
946 | int daemon = 0; |
---|
947 | #endif |
---|
948 | int realtime = 0; |
---|
949 | int sysclocksync = 0; |
---|
950 | char * driver = NULL; |
---|
951 | char * device = NULL; |
---|
952 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
953 | char * opts = NULL; |
---|
954 | #endif |
---|
955 | // char * server = ROAR_DEFAULT_SOCK_GLOBAL; |
---|
956 | #ifdef ROAR_SUPPORT_LISTEN |
---|
957 | int port = ROAR_DEFAULT_PORT; |
---|
958 | char * sock_addr = NULL; |
---|
959 | int sock_proto = ROAR_PROTO_ROARAUDIO; |
---|
960 | int sock_dir = -1; |
---|
961 | struct roar_audio_info sock_info = {0, 0, 0, 0}; |
---|
962 | #endif |
---|
963 | int drvid; |
---|
964 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
965 | char * s_drv = "cf"; |
---|
966 | char * s_dev = NULL; |
---|
967 | char * s_con = NULL; |
---|
968 | char * s_opt = NULL; |
---|
969 | int s_prim = 0; |
---|
970 | #endif |
---|
971 | char * o_drv = getenv("ROAR_DRIVER"); |
---|
972 | char * o_dev = getenv("ROAR_DEVICE"); |
---|
973 | char * o_opts = NULL; |
---|
974 | int o_prim = 0; |
---|
975 | int o_count = 0; |
---|
976 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
977 | int light_channels = LIGHT_CHANNELS_DEFAULT; |
---|
978 | #endif |
---|
979 | #ifdef ROAR_DEFAULT_SOCKGRP |
---|
980 | char * sock_grp = ROAR_DEFAULT_SOCKGRP; |
---|
981 | #else |
---|
982 | char * sock_grp = NULL; |
---|
983 | #endif |
---|
984 | char * sock_user = NULL; |
---|
985 | #ifdef ROAR_SUPPORT_LISTEN |
---|
986 | int sock_type = ROAR_SOCKET_TYPE_UNKNOWN; |
---|
987 | #endif |
---|
988 | #ifdef ROAR_HAVE_LIBSLP |
---|
989 | int reg_slp = 0; |
---|
990 | #endif |
---|
991 | #ifdef ROAR_HAVE_LIBX11 |
---|
992 | int reg_x11 = 0; |
---|
993 | #endif |
---|
994 | #ifdef ROAR_HAVE_CHROOT |
---|
995 | char * chrootdir = NULL; |
---|
996 | #endif |
---|
997 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
998 | struct group * grp = NULL; |
---|
999 | #endif |
---|
1000 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
1001 | struct passwd * pwd = NULL; |
---|
1002 | #endif |
---|
1003 | #ifdef ROAR_HAVE_GETSERVBYNAME |
---|
1004 | struct servent * serv = NULL; |
---|
1005 | #endif |
---|
1006 | DRIVER_USERDATA_T drvinst; |
---|
1007 | struct roar_client * self = NULL; |
---|
1008 | #ifdef ROAR_HAVE_LIBDNET |
---|
1009 | char decnethost[80]; |
---|
1010 | #endif |
---|
1011 | #ifdef SUPPORT_PIDFILE |
---|
1012 | struct roar_vio_calls pidfile_vio; |
---|
1013 | #endif |
---|
1014 | |
---|
1015 | ROAR_DBG("main(*): starting roard..."); |
---|
1016 | |
---|
1017 | g_standby = 0; |
---|
1018 | g_autostandby = 0; |
---|
1019 | alive = 1; |
---|
1020 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1021 | g_no_listen = 0; |
---|
1022 | #else |
---|
1023 | g_terminate = 1; |
---|
1024 | #endif |
---|
1025 | |
---|
1026 | g_verbose = ROAR_DBG_INFO_NONE; |
---|
1027 | |
---|
1028 | sa.bits = ROAR_BITS_DEFAULT; |
---|
1029 | sa.channels = ROAR_CHANNELS_DEFAULT; |
---|
1030 | sa.rate = ROAR_RATE_DEFAULT; |
---|
1031 | sa.codec = ROAR_CODEC_DEFAULT; |
---|
1032 | |
---|
1033 | g_sa = &sa; |
---|
1034 | g_max_sa = &max_sa; |
---|
1035 | |
---|
1036 | memcpy(g_max_sa, g_sa, sizeof(max_sa)); |
---|
1037 | |
---|
1038 | g_config = &config; |
---|
1039 | |
---|
1040 | if ( init_config() == -1 ) { |
---|
1041 | ROAR_ERR("Can not init default config!"); |
---|
1042 | return 1; |
---|
1043 | } |
---|
1044 | |
---|
1045 | // load config |
---|
1046 | roar_libroar_get_config(); |
---|
1047 | |
---|
1048 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1049 | if ( init_listening() == -1 ) { |
---|
1050 | ROAR_ERR("Can not init listening sockets!"); |
---|
1051 | return 1; |
---|
1052 | } |
---|
1053 | #endif |
---|
1054 | |
---|
1055 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
1056 | if ( midi_init_config() == -1 ) { |
---|
1057 | ROAR_ERR("Can not init MIDI config!"); |
---|
1058 | return 1; |
---|
1059 | } |
---|
1060 | #endif |
---|
1061 | |
---|
1062 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
1063 | if ( ssynth_init_config() == -1 ) { |
---|
1064 | ROAR_ERR("Can not init ssynth config!"); |
---|
1065 | return 1; |
---|
1066 | } |
---|
1067 | #endif |
---|
1068 | |
---|
1069 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
1070 | if ( rdtcs_init_config() == -1 ) { |
---|
1071 | ROAR_ERR("Can not init RDTCS config!"); |
---|
1072 | return 1; |
---|
1073 | } |
---|
1074 | #endif |
---|
1075 | |
---|
1076 | if ( plugins_preinit() == -1 ) { |
---|
1077 | ROAR_ERR("Can not pre-init plugins!"); |
---|
1078 | return 1; |
---|
1079 | } |
---|
1080 | |
---|
1081 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1082 | #ifndef ROAR_TARGET_WIN32 |
---|
1083 | sock_addr = ROAR_DEFAULT_SOCK_GLOBAL; |
---|
1084 | #else |
---|
1085 | sock_addr = ROAR_DEFAULT_HOST; |
---|
1086 | #endif |
---|
1087 | |
---|
1088 | #ifdef ROAR_HAVE_GETUID |
---|
1089 | if ( getuid() != 0 && getenv("HOME") != NULL ) { |
---|
1090 | snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER); |
---|
1091 | sock_addr = user_sock; |
---|
1092 | } |
---|
1093 | #endif |
---|
1094 | |
---|
1095 | if ( getenv("ROAR_SERVER") != NULL ) |
---|
1096 | sock_addr = getenv("ROAR_SERVER"); |
---|
1097 | #endif |
---|
1098 | |
---|
1099 | if ( clients_init() == -1 ) { |
---|
1100 | ROAR_ERR("Can not init clients!"); |
---|
1101 | return 1; |
---|
1102 | } |
---|
1103 | |
---|
1104 | if ( streams_init() == -1 ) { |
---|
1105 | ROAR_ERR("Can not init streams!"); |
---|
1106 | return 1; |
---|
1107 | } |
---|
1108 | |
---|
1109 | if ( (g_self_client = clients_new()) == -1 ) { |
---|
1110 | ROAR_ERR("Can not create self client!"); |
---|
1111 | return 1; |
---|
1112 | } |
---|
1113 | |
---|
1114 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
1115 | if ( sources_init() == -1 ) { |
---|
1116 | ROAR_ERR("Can not init sources!"); |
---|
1117 | return 1; |
---|
1118 | } |
---|
1119 | |
---|
1120 | if ( (sources_set_client(g_self_client)) == -1 ) { |
---|
1121 | ROAR_ERR("Can not init set source client!"); |
---|
1122 | return 1; |
---|
1123 | } |
---|
1124 | #endif |
---|
1125 | |
---|
1126 | #ifdef ROAR_HAVE_MAIN_ARGS |
---|
1127 | for (i = 1; i < argc; i++) { |
---|
1128 | k = argv[i]; |
---|
1129 | |
---|
1130 | if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) { |
---|
1131 | usage(); |
---|
1132 | return 0; |
---|
1133 | |
---|
1134 | } else if ( strcmp(k, "--start") == 0 ) { |
---|
1135 | // this is a no op |
---|
1136 | } else if ( strcmp(k, "--restart") == 0 ) { |
---|
1137 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1138 | if ( restart_server(sock_addr, 1) == -1 ) { |
---|
1139 | ROAR_WARN("Can not terminate old server (not running at %s?), tring to continue anyway", sock_addr); |
---|
1140 | } |
---|
1141 | #else |
---|
1142 | ROAR_ERR("--restart not supported"); |
---|
1143 | #endif |
---|
1144 | } else if ( strcmp(k, "--shutdown") == 0 ) { |
---|
1145 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1146 | if ( restart_server(sock_addr, 1) == -1 ) { |
---|
1147 | ROAR_WARN("Can not terminate old server (not running at %s?)", sock_addr); |
---|
1148 | return 1; |
---|
1149 | } |
---|
1150 | return 0; |
---|
1151 | #else |
---|
1152 | ROAR_ERR("--shutdown not supported"); |
---|
1153 | return 1; |
---|
1154 | #endif |
---|
1155 | } else if ( strcmp(k, "--stop") == 0 ) { |
---|
1156 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1157 | if ( restart_server(sock_addr, 0) == -1 ) { |
---|
1158 | ROAR_WARN("Can not stop old server (not running at %s?)", sock_addr); |
---|
1159 | return 1; |
---|
1160 | } |
---|
1161 | return 0; |
---|
1162 | #else |
---|
1163 | ROAR_ERR("--stop not supported"); |
---|
1164 | return 1; |
---|
1165 | #endif |
---|
1166 | |
---|
1167 | |
---|
1168 | } else if ( strcmp(k, "--demon") == 0 || strcmp(k, "--daemon") == 0 ) { |
---|
1169 | #ifdef ROAR_HAVE_FORK |
---|
1170 | daemon = 1; |
---|
1171 | #else |
---|
1172 | ROAR_ERR("--daemon not supported"); |
---|
1173 | #endif |
---|
1174 | } else if ( strcmp(k, "--verbose") == 0 ) { |
---|
1175 | g_verbose++; |
---|
1176 | } else if ( strcmp(k, "--terminate") == 0 ) { |
---|
1177 | g_terminate = 1; |
---|
1178 | } else if ( strcmp(k, "--sysclocksync") == 0 ) { |
---|
1179 | sysclocksync = 1000; |
---|
1180 | } else if ( strcmp(k, "--realtime") == 0 ) { |
---|
1181 | realtime++; |
---|
1182 | } else if ( strcmp(k, "--chroot") == 0 ) { |
---|
1183 | #ifdef ROAR_HAVE_CHROOT |
---|
1184 | chrootdir = argv[++i]; |
---|
1185 | #else |
---|
1186 | ROAR_ERR("--chroot not supported"); |
---|
1187 | i++; |
---|
1188 | #endif |
---|
1189 | } else if ( strcmp(k, "--setgid") == 0 ) { |
---|
1190 | #ifdef ROAR_HAVE_SETGID |
---|
1191 | setids |= R_SETGID; |
---|
1192 | #else |
---|
1193 | ROAR_ERR("--setgid not supported"); |
---|
1194 | #endif |
---|
1195 | } else if ( strcmp(k, "--setuid") == 0 ) { |
---|
1196 | #ifdef ROAR_HAVE_SETUID |
---|
1197 | setids |= R_SETUID; |
---|
1198 | #else |
---|
1199 | ROAR_ERR("--setuid not supported"); |
---|
1200 | #endif |
---|
1201 | } else if ( strcmp(k, "--location") == 0 ) { |
---|
1202 | g_config->location = argv[++i]; |
---|
1203 | } else if ( strcmp(k, "--pidfile") == 0 ) { |
---|
1204 | #ifdef SUPPORT_PIDFILE |
---|
1205 | pidfile = argv[++i]; |
---|
1206 | #else |
---|
1207 | ROAR_ERR("--pidfile not supported"); |
---|
1208 | i++; |
---|
1209 | #endif |
---|
1210 | } else if ( strcmp(k, "--log-syslog") == 0 ) { |
---|
1211 | #ifdef ROAR_HAVE_SYSLOG |
---|
1212 | roar_debug_set_stderr_mode(ROAR_DEBUG_MODE_SYSLOG); |
---|
1213 | #else |
---|
1214 | ROAR_ERR("--log-syslog not supported"); |
---|
1215 | #endif |
---|
1216 | |
---|
1217 | |
---|
1218 | } else if ( strcmp(k, "--plugin-load") == 0 ) { |
---|
1219 | if ( plugins_load(argv[++i]) == -1 ) { |
---|
1220 | ROAR_ERR("Can not load plugin"); |
---|
1221 | } |
---|
1222 | |
---|
1223 | } else if ( strcmp(k, "--list-cf") == 0 ) { |
---|
1224 | print_codecfilterlist(); |
---|
1225 | return 0; |
---|
1226 | |
---|
1227 | } else if ( strcmp(k, "-R") == 0 || strcmp(k, "--rate") == 0 ) { |
---|
1228 | sa.rate = atoi(argv[++i]); |
---|
1229 | } else if ( strcmp(k, "-B") == 0 || strcmp(k, "--bits") == 0 ) { |
---|
1230 | sa.bits = atoi(argv[++i]); |
---|
1231 | } else if ( strcmp(k, "-C") == 0 || strcmp(k, "--chans") == 0 ) { |
---|
1232 | sa.channels = atoi(argv[++i]); |
---|
1233 | |
---|
1234 | } else if ( strcmp(k, "--stream-flags") == 0 ) { |
---|
1235 | if ( update_stream_flags(argv[++i]) == -1 ) { |
---|
1236 | ROAR_ERR("Can not set stream flags"); |
---|
1237 | return 1; |
---|
1238 | } |
---|
1239 | |
---|
1240 | } else if ( strcmp(k, "-d") == 0 || strcmp(k, "--driver") == 0 ) { |
---|
1241 | driver = argv[++i]; |
---|
1242 | if ( strcmp(driver, "list") == 0 ) { |
---|
1243 | ROAR_WARN("The option is obsolete, use --list-driver!"); |
---|
1244 | print_driverlist(); |
---|
1245 | return 0; |
---|
1246 | } |
---|
1247 | } else if ( strcmp(k, "-D") == 0 || strcmp(k, "--device") == 0 ) { |
---|
1248 | device = argv[++i]; |
---|
1249 | } else if ( strcmp(k, "-dO") == 0 ) { |
---|
1250 | opts = argv[++i]; |
---|
1251 | } else if ( strcmp(k, "--list-driver") == 0 ) { |
---|
1252 | print_driverlist(); |
---|
1253 | return 0; |
---|
1254 | |
---|
1255 | } else if ( strcmp(k, "-o") == 0 || strcmp(k, "--odriver") == 0 ) { |
---|
1256 | o_drv = argv[++i]; |
---|
1257 | } else if ( strcmp(k, "-O") == 0 || strcmp(k, "--odevice") == 0 ) { |
---|
1258 | o_dev = argv[++i]; |
---|
1259 | } else if ( strcmp(k, "-oO") == 0 ) { |
---|
1260 | o_opts = argv[++i]; |
---|
1261 | } else if ( strcmp(k, "-oP") == 0 ) { |
---|
1262 | o_prim = 1; |
---|
1263 | } else if ( strcmp(k, "-oN") == 0 ) { |
---|
1264 | if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 ) |
---|
1265 | o_count++; |
---|
1266 | |
---|
1267 | o_drv = o_dev = o_opts = NULL; |
---|
1268 | o_prim = 0; |
---|
1269 | |
---|
1270 | } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) { |
---|
1271 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
1272 | s_drv = argv[++i]; |
---|
1273 | #else |
---|
1274 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
1275 | #endif |
---|
1276 | } else if ( strcmp(k, "-S") == 0 ) { |
---|
1277 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
1278 | s_dev = argv[++i]; |
---|
1279 | #else |
---|
1280 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
1281 | #endif |
---|
1282 | } else if ( strcmp(k, "-sO") == 0 ) { |
---|
1283 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
1284 | s_opt = argv[++i]; |
---|
1285 | #else |
---|
1286 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
1287 | #endif |
---|
1288 | } else if ( strcmp(k, "-sC") == 0 ) { |
---|
1289 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
1290 | s_con = argv[++i]; |
---|
1291 | #else |
---|
1292 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
1293 | #endif |
---|
1294 | } else if ( strcmp(k, "-sP") == 0 ) { |
---|
1295 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
1296 | s_prim = 1; |
---|
1297 | #else |
---|
1298 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
1299 | #endif |
---|
1300 | } else if ( strcmp(k, "-sN") == 0 ) { |
---|
1301 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
1302 | if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) { |
---|
1303 | ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv); |
---|
1304 | } |
---|
1305 | s_opt = s_dev = s_con = NULL; |
---|
1306 | s_drv = "cf"; |
---|
1307 | s_prim = 0; |
---|
1308 | #else |
---|
1309 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
1310 | #endif |
---|
1311 | } else if ( strcmp(k, "--list-sources") == 0 ) { |
---|
1312 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
1313 | print_sourcelist(); |
---|
1314 | return 0; |
---|
1315 | #else |
---|
1316 | ROAR_ERR("main(*): No support for sources compiled in"); |
---|
1317 | return 1; |
---|
1318 | #endif |
---|
1319 | |
---|
1320 | } else if ( strcmp(k, "--light-channels") == 0 ) { |
---|
1321 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
1322 | light_channels = atoi(argv[++i]); |
---|
1323 | #else |
---|
1324 | ROAR_WARN("main(*): no light subsystem compiled in"); |
---|
1325 | #endif |
---|
1326 | |
---|
1327 | } else if ( strcmp(k, "--rds-pi") == 0 ) { |
---|
1328 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
1329 | g_rdtcs.rds.pi = atoi(argv[++i]); |
---|
1330 | #else |
---|
1331 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
1332 | #endif |
---|
1333 | } else if ( strcmp(k, "--rds-ps") == 0 ) { |
---|
1334 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
1335 | if ( rdtcs_rds_set_ps(argv[++i]) == -1 ) { |
---|
1336 | ROAR_ERR("Can not set RDS PS to '%s' (longer than 8 chars?)", argv[i]); |
---|
1337 | return 1; |
---|
1338 | } |
---|
1339 | #else |
---|
1340 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
1341 | #endif |
---|
1342 | } else if ( strcmp(k, "--rds-pty") == 0 ) { |
---|
1343 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
1344 | if ( rdtcs_rds_set_pty(argv[++i]) == -1 ) { |
---|
1345 | ROAR_ERR("Can not set RDS PTY to '%s'", argv[i]); |
---|
1346 | return 1; |
---|
1347 | } |
---|
1348 | #else |
---|
1349 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
1350 | #endif |
---|
1351 | } else if ( strcmp(k, "--rds-tp") == 0 ) { |
---|
1352 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
1353 | if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_TP, 0) == -1 ) { |
---|
1354 | ROAR_ERR("Can not set RDS TP flag"); |
---|
1355 | return 1; |
---|
1356 | } |
---|
1357 | #else |
---|
1358 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
1359 | #endif |
---|
1360 | } else if ( strcmp(k, "--rds-ct") == 0 ) { |
---|
1361 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
1362 | if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_CT, 0) == -1 ) { |
---|
1363 | ROAR_ERR("Can not set RDS CT flag"); |
---|
1364 | return 1; |
---|
1365 | } |
---|
1366 | #else |
---|
1367 | ROAR_WARN("main(*): no RDTCS subsystem compiled in"); |
---|
1368 | #endif |
---|
1369 | |
---|
1370 | |
---|
1371 | } else if ( strcmp(k, "--midi-no-console") == 0 ) { |
---|
1372 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
1373 | midi_config.init_cb = 0; |
---|
1374 | #else |
---|
1375 | // no warning here as this is the disable option |
---|
1376 | #endif |
---|
1377 | } else if ( strcmp(k, "--midi-console-enable") == 0 ) { |
---|
1378 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
1379 | midi_config.init_cb = 1; |
---|
1380 | #else |
---|
1381 | ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in"); |
---|
1382 | #endif |
---|
1383 | } else if ( strcmp(k, "--midi-console") == 0 ) { |
---|
1384 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
1385 | midi_config.console_dev = argv[++i]; |
---|
1386 | midi_config.init_cb = 1; |
---|
1387 | #else |
---|
1388 | ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in"); |
---|
1389 | #endif |
---|
1390 | |
---|
1391 | } else if ( strcmp(k, "--ssynth-enable") == 0 ) { |
---|
1392 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
1393 | ssynth_conf.enable = 1; |
---|
1394 | #else |
---|
1395 | ROAR_ERR("main(*): No support for ssynth compiled in"); |
---|
1396 | #endif |
---|
1397 | } else if ( strcmp(k, "--ssynth-disable") == 0 ) { |
---|
1398 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
1399 | ssynth_conf.enable = 0; |
---|
1400 | #else |
---|
1401 | // we can safely ignore the disable |
---|
1402 | #endif |
---|
1403 | |
---|
1404 | } else if ( strcmp(k, "--x11-display") == 0 || strcmp(k, "--display") == 0 ) { |
---|
1405 | #ifdef ROAR_HAVE_LIBX11 |
---|
1406 | x11display = argv[++i]; |
---|
1407 | #else |
---|
1408 | ROAR_ERR("No X11 support compiled in!"); |
---|
1409 | return 1; |
---|
1410 | #endif |
---|
1411 | |
---|
1412 | |
---|
1413 | } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--port") == 0 ) { |
---|
1414 | // This is only usefull in INET not UNIX mode. |
---|
1415 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1416 | if ( *sock_addr == '/' ) |
---|
1417 | sock_addr = ROAR_DEFAULT_HOST; |
---|
1418 | |
---|
1419 | errno = 0; |
---|
1420 | if ( (port = atoi(argv[++i])) < 1 ) { |
---|
1421 | #ifdef ROAR_HAVE_GETSERVBYNAME |
---|
1422 | if ( (serv = getservbyname(argv[i], "tcp")) == NULL ) { |
---|
1423 | ROAR_ERR("Unknown service: %s: %s", argv[i], strerror(errno)); |
---|
1424 | return 1; |
---|
1425 | } |
---|
1426 | // NOTE: we need to use ROAR_NET2HOST16() here even if s_port is of type int! |
---|
1427 | ROAR_DBG("main(*): serv = {s_name='%s', s_aliases={...}, s_port=%i, s_proto='%s'}", |
---|
1428 | serv->s_name, ROAR_NET2HOST16(serv->s_port), serv->s_proto); |
---|
1429 | port = ROAR_NET2HOST16(serv->s_port); |
---|
1430 | #else |
---|
1431 | ROAR_ERR("invalite port number: %s", argv[i]); |
---|
1432 | return 1; |
---|
1433 | #endif |
---|
1434 | } |
---|
1435 | #endif |
---|
1436 | } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) { |
---|
1437 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1438 | sock_addr = argv[++i]; |
---|
1439 | #endif |
---|
1440 | |
---|
1441 | } else if ( strcmp(k, "--proto") == 0 ) { |
---|
1442 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1443 | if ( (sock_proto = roar_str2proto(argv[++i])) == -1 ) { |
---|
1444 | ROAR_ERR("Unknown protocol: %s", argv[i]); |
---|
1445 | return 1; |
---|
1446 | } |
---|
1447 | #endif |
---|
1448 | } else if ( strcmp(k, "--proto-dir") == 0 ) { |
---|
1449 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1450 | if ( (sock_dir = roar_str2dir(argv[++i])) == -1 ) { |
---|
1451 | ROAR_ERR("Unknown stream direction: %s", argv[i]); |
---|
1452 | return 1; |
---|
1453 | } |
---|
1454 | #endif |
---|
1455 | } else if ( strcmp(k, "--proto-rate") == 0 ) { |
---|
1456 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1457 | sock_info.rate = atoi(argv[++i]); |
---|
1458 | #endif |
---|
1459 | } else if ( strcmp(k, "--proto-bits") == 0 ) { |
---|
1460 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1461 | sock_info.bits = atoi(argv[++i]); |
---|
1462 | #endif |
---|
1463 | } else if ( strcmp(k, "--proto-chans") == 0 ) { |
---|
1464 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1465 | sock_info.channels = atoi(argv[++i]); |
---|
1466 | #endif |
---|
1467 | } else if ( strcmp(k, "--proto-codec") == 0 ) { |
---|
1468 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1469 | if ( (sock_info.codec = roar_str2codec(argv[++i])) == -1 ) { |
---|
1470 | ROAR_ERR("Unknown codec: %s", argv[i]); |
---|
1471 | return 1; |
---|
1472 | } |
---|
1473 | #endif |
---|
1474 | |
---|
1475 | |
---|
1476 | } else if ( strcmp(k, "--list-proto") == 0 ) { |
---|
1477 | list_proto(); |
---|
1478 | return 0; |
---|
1479 | |
---|
1480 | } else if ( strcmp(k, "-t") == 0 || strcmp(k, "--tcp") == 0 ) { |
---|
1481 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1482 | if ( sock_type != ROAR_SOCKET_TYPE_TCP && sock_type != ROAR_SOCKET_TYPE_TCP6 ) |
---|
1483 | sock_type = ROAR_SOCKET_TYPE_TCP; |
---|
1484 | |
---|
1485 | if ( *sock_addr == '/' ) |
---|
1486 | sock_addr = ROAR_DEFAULT_HOST; |
---|
1487 | #endif |
---|
1488 | |
---|
1489 | } else if ( strcmp(k, "-4") == 0 ) { |
---|
1490 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1491 | sock_type = ROAR_SOCKET_TYPE_TCP; |
---|
1492 | if ( *sock_addr == '/' ) |
---|
1493 | sock_addr = ROAR_DEFAULT_HOST; |
---|
1494 | #endif |
---|
1495 | } else if ( strcmp(k, "-6") == 0 ) { |
---|
1496 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1497 | #ifdef PF_INET6 |
---|
1498 | sock_type = ROAR_SOCKET_TYPE_TCP6; |
---|
1499 | if ( *sock_addr == '/' ) |
---|
1500 | sock_addr = ROAR_DEFAULT_HOST; |
---|
1501 | #else |
---|
1502 | ROAR_ERR("No IPv6 support compiled in!"); |
---|
1503 | return 1; |
---|
1504 | #endif |
---|
1505 | #endif |
---|
1506 | |
---|
1507 | } else if ( strcmp(k, "-u") == 0 || strcmp(k, "--unix") == 0 ) { |
---|
1508 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1509 | // ignore this case as it is the default behavor. |
---|
1510 | sock_type = ROAR_SOCKET_TYPE_UNIX; |
---|
1511 | #endif |
---|
1512 | |
---|
1513 | } else if ( strcmp(k, "-n") == 0 || strcmp(k, "--decnet") == 0 ) { |
---|
1514 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1515 | #ifdef ROAR_HAVE_LIBDNET |
---|
1516 | port = ROAR_DEFAULT_NUM; |
---|
1517 | strcpy(decnethost, ROAR_DEFAULT_LISTEN_OBJECT); |
---|
1518 | sock_addr = decnethost; |
---|
1519 | sock_type = ROAR_SOCKET_TYPE_DECNET; |
---|
1520 | #else |
---|
1521 | ROAR_ERR("No DECnet support compiled in!"); |
---|
1522 | return 1; |
---|
1523 | #endif |
---|
1524 | #endif |
---|
1525 | } else if ( strcmp(k, "--new-sock") == 0 ) { |
---|
1526 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1527 | if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) { |
---|
1528 | ROAR_ERR("Can not open listen socket!"); |
---|
1529 | return 1; |
---|
1530 | } |
---|
1531 | #endif |
---|
1532 | |
---|
1533 | } else if ( strcmp(k, "--slp") == 0 ) { |
---|
1534 | #ifdef ROAR_HAVE_LIBSLP |
---|
1535 | reg_slp = 1; |
---|
1536 | #else |
---|
1537 | ROAR_ERR("No OpenSLP support compiled in!"); |
---|
1538 | return 1; |
---|
1539 | #endif |
---|
1540 | |
---|
1541 | } else if ( strcmp(k, "--x11") == 0 ) { |
---|
1542 | #ifdef ROAR_HAVE_LIBX11 |
---|
1543 | reg_x11 = 1; |
---|
1544 | #else |
---|
1545 | ROAR_ERR("No X11 support compiled in!"); |
---|
1546 | return 1; |
---|
1547 | #endif |
---|
1548 | |
---|
1549 | |
---|
1550 | } else if ( strcmp(k, "--jumbo-mtu") == 0 ) { |
---|
1551 | g_config->jumbo_mtu = atoi(argv[++i]); |
---|
1552 | |
---|
1553 | } else if ( strcmp(k, "-G") == 0 ) { |
---|
1554 | sock_grp = argv[++i]; |
---|
1555 | } else if ( strcmp(k, "-U") == 0 ) { |
---|
1556 | sock_user = argv[++i]; |
---|
1557 | |
---|
1558 | } else if ( strcmp(k, "--no-listen") == 0 ) { |
---|
1559 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1560 | sock_addr = ""; |
---|
1561 | g_terminate = 1; |
---|
1562 | g_no_listen = 1; |
---|
1563 | #endif |
---|
1564 | } else if ( strcmp(k, "--client-fh") == 0 ) { |
---|
1565 | if ( clients_new_from_fh(atoi(argv[++i]), ROAR_PROTO_ROARAUDIO, ROAR_BYTEORDER_NETWORK, 1) == -1 ) { |
---|
1566 | ROAR_ERR("main(*): Can not set client's fh"); |
---|
1567 | return 1; |
---|
1568 | } |
---|
1569 | } else if ( strcmp(k, "--close-fh") == 0 ) { |
---|
1570 | #ifdef ROAR_HAVE_IO_POSIX |
---|
1571 | close(atoi(argv[++i])); |
---|
1572 | #else |
---|
1573 | i++; |
---|
1574 | ROAR_WARN("can not close file handle %s (closing not supported)", argv[i]); |
---|
1575 | #endif |
---|
1576 | |
---|
1577 | } else if ( strcmp(k, "--standby") == 0 ) { |
---|
1578 | g_standby = 1; |
---|
1579 | } else if ( strcmp(k, "--auto-standby") == 0 ) { |
---|
1580 | g_autostandby = 1; |
---|
1581 | } else { |
---|
1582 | usage(); |
---|
1583 | return 1; |
---|
1584 | } |
---|
1585 | |
---|
1586 | } |
---|
1587 | #endif |
---|
1588 | |
---|
1589 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
1590 | if ( s_dev != NULL ) { |
---|
1591 | if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) { |
---|
1592 | ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv); |
---|
1593 | } |
---|
1594 | } |
---|
1595 | #endif |
---|
1596 | |
---|
1597 | add_output(o_drv, o_dev, o_opts, o_prim, o_count); |
---|
1598 | |
---|
1599 | ROAR_DBG("Server config: rate=%i, bits=%i, chans=%i", sa.rate, sa.bits, sa.channels); |
---|
1600 | |
---|
1601 | if ( waveform_init() == -1 ) { |
---|
1602 | ROAR_ERR("Can not initialize Waveform subsystem"); |
---|
1603 | return 1; |
---|
1604 | } |
---|
1605 | |
---|
1606 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
1607 | if ( midi_init() == -1 ) { |
---|
1608 | ROAR_ERR("Can not initialize MIDI subsystem"); |
---|
1609 | } |
---|
1610 | #endif |
---|
1611 | |
---|
1612 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
1613 | if ( ssynth_init() == -1 ) { |
---|
1614 | ROAR_ERR("Can not initialize ssynth subsystem"); |
---|
1615 | } |
---|
1616 | #endif |
---|
1617 | |
---|
1618 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
1619 | if ( light_init(light_channels) == -1 ) { |
---|
1620 | ROAR_ERR("Can not initialize light control subsystem"); |
---|
1621 | } |
---|
1622 | #endif |
---|
1623 | |
---|
1624 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
1625 | if ( rdtcs_init() == -1 ) { |
---|
1626 | ROAR_ERR("Can not initialize RDTCS subsystem"); |
---|
1627 | } |
---|
1628 | #endif |
---|
1629 | |
---|
1630 | if ( plugins_init() == -1 ) { |
---|
1631 | ROAR_ERR("Can not initialize plugins"); |
---|
1632 | } |
---|
1633 | |
---|
1634 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1635 | if ( !g_no_listen ) { |
---|
1636 | if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) { |
---|
1637 | ROAR_ERR("Can not open listen socket!"); |
---|
1638 | return 1; |
---|
1639 | } |
---|
1640 | } |
---|
1641 | #endif |
---|
1642 | |
---|
1643 | if ( output_buffer_init(&sa) == -1 ) { |
---|
1644 | ROAR_ERR("Can not init output buffer!"); |
---|
1645 | return 1; |
---|
1646 | } |
---|
1647 | |
---|
1648 | if ( driver == NULL ) { |
---|
1649 | driver = "null"; |
---|
1650 | } else { |
---|
1651 | ROAR_WARN("Usage of old driver interface. use -o not -d!"); |
---|
1652 | } |
---|
1653 | |
---|
1654 | if ( driver_open(&drvinst, &drvid, driver, device, &sa) == -1 ) { |
---|
1655 | ROAR_ERR("Can not open output driver!"); |
---|
1656 | return 1; |
---|
1657 | } |
---|
1658 | |
---|
1659 | if ( samples_init() == -1 ) { |
---|
1660 | ROAR_ERR("Can not init samples!"); |
---|
1661 | return 1; |
---|
1662 | } |
---|
1663 | |
---|
1664 | |
---|
1665 | // we should handle this on microcontrollers, too. |
---|
1666 | #if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_TARGET_WIN32) |
---|
1667 | signal(SIGINT, on_sig_int); |
---|
1668 | signal(SIGTERM, on_sig_term); |
---|
1669 | signal(SIGCHLD, on_sig_chld); |
---|
1670 | signal(SIGUSR1, on_sig_usr1); |
---|
1671 | signal(SIGPIPE, SIG_IGN); // ignore broken pipes |
---|
1672 | #endif |
---|
1673 | |
---|
1674 | if ( realtime ) { |
---|
1675 | #ifdef DEBUG |
---|
1676 | ROAR_WARN("compiled with -DDEBUG but realtime is enabled: for real realtime support compiel without -DDEBUG"); |
---|
1677 | #endif |
---|
1678 | |
---|
1679 | #ifdef ROAR_HAVE_NICE |
---|
1680 | errno = 0; |
---|
1681 | nice(-5*realtime); // -5 for each --realtime |
---|
1682 | if ( errno ) { |
---|
1683 | ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno)); |
---|
1684 | } |
---|
1685 | #else |
---|
1686 | ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno)); |
---|
1687 | #endif |
---|
1688 | /* |
---|
1689 | #ifdef __linux__ |
---|
1690 | if ( ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0)) == -1 ) |
---|
1691 | ROAR_WARN("Can not set io priority: %s", strerror(errno)); |
---|
1692 | #endif |
---|
1693 | */ |
---|
1694 | } |
---|
1695 | |
---|
1696 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) |
---|
1697 | if ( setids & R_SETGID ) { |
---|
1698 | if ( sock_grp == NULL ) { |
---|
1699 | ROAR_ERR("Can not set GID if no groupname is supplied"); |
---|
1700 | return 1; |
---|
1701 | } |
---|
1702 | if ( (grp = getgrnam(sock_grp)) == NULL ) { |
---|
1703 | ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno)); |
---|
1704 | return 1; |
---|
1705 | } |
---|
1706 | if ( setgroups(0, (const gid_t *) NULL) == -1 ) { |
---|
1707 | ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno)); |
---|
1708 | } |
---|
1709 | if ( !grp || setgid(grp->gr_gid) == -1 ) { |
---|
1710 | ROAR_ERR("Can not set GroupID: %s", strerror(errno)); |
---|
1711 | } |
---|
1712 | } |
---|
1713 | #endif |
---|
1714 | |
---|
1715 | |
---|
1716 | clients_set_pid(g_self_client, getpid()); |
---|
1717 | #ifdef ROAR_HAVE_GETUID |
---|
1718 | clients_set_uid(g_self_client, getuid()); |
---|
1719 | #endif |
---|
1720 | #ifdef ROAR_HAVE_GETGID |
---|
1721 | clients_set_gid(g_self_client, getgid()); |
---|
1722 | #endif |
---|
1723 | clients_get(g_self_client, &self); |
---|
1724 | |
---|
1725 | if ( self == NULL ) { |
---|
1726 | ROAR_ERR("Can not get self client!"); |
---|
1727 | return 1; |
---|
1728 | } |
---|
1729 | |
---|
1730 | strcpy(self->name, "RoarAudio daemon internal"); |
---|
1731 | |
---|
1732 | if ( roar_nnode_free(&(self->nnode)) == -1 ) |
---|
1733 | return 1; |
---|
1734 | |
---|
1735 | // not fully correct but ok as workaorund |
---|
1736 | // so tools assume that roard runs on the same machine as |
---|
1737 | // they in case they use AF_UNIX: |
---|
1738 | if ( roar_nnode_new(&(self->nnode), ROAR_SOCKET_TYPE_UNIX) == -1 ) |
---|
1739 | return 1; |
---|
1740 | |
---|
1741 | #ifdef ROAR_HAVE_FORK |
---|
1742 | if ( daemon ) { |
---|
1743 | #ifdef ROAR_HAVE_SYSLOG |
---|
1744 | roar_debug_set_stderr_mode(ROAR_DEBUG_MODE_SYSLOG); |
---|
1745 | #else |
---|
1746 | roar_debug_set_stderr_fh(-1); |
---|
1747 | #endif |
---|
1748 | |
---|
1749 | close(ROAR_STDIN ); |
---|
1750 | close(ROAR_STDOUT); |
---|
1751 | close(ROAR_STDERR); |
---|
1752 | |
---|
1753 | if ( fork() ) |
---|
1754 | ROAR_U_EXIT(0); |
---|
1755 | |
---|
1756 | #ifdef ROAR_HAVE_SETSID |
---|
1757 | setsid(); |
---|
1758 | #endif |
---|
1759 | clients_set_pid(g_self_client, getpid()); // reset pid as it changed |
---|
1760 | } |
---|
1761 | #endif |
---|
1762 | |
---|
1763 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
1764 | // early test for UID as we need this for the pidfile and the setuid() |
---|
1765 | if ( sock_user != NULL ) { |
---|
1766 | if ( (pwd = getpwnam(sock_user)) == NULL ) { |
---|
1767 | ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno)); |
---|
1768 | return 1; |
---|
1769 | } |
---|
1770 | } |
---|
1771 | #endif |
---|
1772 | |
---|
1773 | #ifdef SUPPORT_PIDFILE |
---|
1774 | if ( pidfile != NULL ) { |
---|
1775 | if ( roar_vio_open_file(&pidfile_vio, pidfile, O_WRONLY|O_CREAT, 0644) == -1 ) { |
---|
1776 | ROAR_ERR("Can not write pidfile: %s", pidfile); |
---|
1777 | } else { |
---|
1778 | roar_vio_printf(&pidfile_vio, "%i\n", getpid()); |
---|
1779 | roar_vio_close(&pidfile_vio); |
---|
1780 | } |
---|
1781 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
1782 | if ( pwd || grp ) { |
---|
1783 | if ( chown(pidfile, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 ) { |
---|
1784 | ROAR_WARN("Can not change ownership of pidfile: %s: %s", pidfile, strerror(errno)); |
---|
1785 | } |
---|
1786 | } |
---|
1787 | if ( chmod(pidfile, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1 ) { |
---|
1788 | ROAR_WARN("Can not change permissions of pidfile: %s: %s", pidfile, strerror(errno)); |
---|
1789 | } |
---|
1790 | #endif |
---|
1791 | } |
---|
1792 | #endif |
---|
1793 | |
---|
1794 | #ifdef ROAR_HAVE_CHROOT |
---|
1795 | if (chrootdir) { |
---|
1796 | if ( chroot(chrootdir) == -1 ) { |
---|
1797 | ROAR_ERR("Can not chroot to %s: %s", chrootdir, strerror(errno)); |
---|
1798 | return 2; |
---|
1799 | } |
---|
1800 | if ( chdir("/") == -1 ) { |
---|
1801 | ROAR_ERR("Can not chdir to /: %s", strerror(errno)); |
---|
1802 | return 2; |
---|
1803 | } |
---|
1804 | } |
---|
1805 | #endif |
---|
1806 | |
---|
1807 | #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) |
---|
1808 | if ( setids & R_SETUID ) { |
---|
1809 | if ( sock_user == NULL ) { |
---|
1810 | ROAR_ERR("Can not set UID if no username is supplied"); |
---|
1811 | return 1; |
---|
1812 | } |
---|
1813 | if ( !pwd || setuid(pwd->pw_uid) == -1 ) { |
---|
1814 | ROAR_ERR("Can not set UserID: %s", strerror(errno)); |
---|
1815 | return 3; |
---|
1816 | } |
---|
1817 | #ifdef ROAR_HAVE_GETUID |
---|
1818 | clients_set_uid(g_self_client, getuid()); |
---|
1819 | #endif |
---|
1820 | } |
---|
1821 | #endif |
---|
1822 | |
---|
1823 | // Register with OpenSLP: |
---|
1824 | #ifdef ROAR_HAVE_LIBSLP |
---|
1825 | if ( reg_slp ) { |
---|
1826 | register_slp(0, sock_addr); |
---|
1827 | } |
---|
1828 | #endif |
---|
1829 | |
---|
1830 | #ifdef ROAR_HAVE_LIBX11 |
---|
1831 | if ( reg_x11 ) { |
---|
1832 | register_x11(0, sock_addr); |
---|
1833 | } |
---|
1834 | #endif |
---|
1835 | |
---|
1836 | // start main loop... |
---|
1837 | main_loop(drvid, drvinst, &sa, sysclocksync); |
---|
1838 | |
---|
1839 | // clean up. |
---|
1840 | clean_quit_prep(); |
---|
1841 | driver_close(drvinst, drvid); |
---|
1842 | output_buffer_free(); |
---|
1843 | |
---|
1844 | return 0; |
---|
1845 | } |
---|
1846 | |
---|
1847 | void cleanup_listen_socket (int terminate) { |
---|
1848 | int i; |
---|
1849 | |
---|
1850 | // Deregister from SLP: |
---|
1851 | #ifdef ROAR_HAVE_LIBSLP |
---|
1852 | register_slp(1, NULL); |
---|
1853 | #endif |
---|
1854 | |
---|
1855 | #ifdef ROAR_HAVE_LIBX11 |
---|
1856 | register_x11(1, NULL); |
---|
1857 | #endif |
---|
1858 | |
---|
1859 | #ifdef ROAR_SUPPORT_LISTEN |
---|
1860 | for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) { |
---|
1861 | if ( g_listen[i].socket != -1 ) { |
---|
1862 | #ifdef ROAR_HAVE_IO_POSIX |
---|
1863 | close(g_listen[i].socket); |
---|
1864 | #endif // #else is useless because we are in void context. |
---|
1865 | |
---|
1866 | g_listen[i].socket = -1; |
---|
1867 | |
---|
1868 | #ifdef ROAR_HAVE_UNIX |
---|
1869 | if ( server[i] != NULL ) |
---|
1870 | if ( *(server[i]) == '/' ) |
---|
1871 | unlink(server[i]); |
---|
1872 | #endif |
---|
1873 | } |
---|
1874 | } |
---|
1875 | |
---|
1876 | #endif |
---|
1877 | |
---|
1878 | if ( terminate ) |
---|
1879 | g_terminate = 1; |
---|
1880 | } |
---|
1881 | |
---|
1882 | void clean_quit_prep (void) { |
---|
1883 | cleanup_listen_socket(0); |
---|
1884 | |
---|
1885 | plugins_free(); |
---|
1886 | |
---|
1887 | #ifndef ROAR_WITHOUT_DCOMP_SOURCES |
---|
1888 | sources_free(); |
---|
1889 | #endif |
---|
1890 | streams_free(); |
---|
1891 | clients_free(); |
---|
1892 | #ifndef ROAR_WITHOUT_DCOMP_SSYNTH |
---|
1893 | ssynth_free(); |
---|
1894 | #endif |
---|
1895 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
1896 | midi_cb_stop(); // stop console beep |
---|
1897 | #endif |
---|
1898 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
1899 | midi_free(); |
---|
1900 | #endif |
---|
1901 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
1902 | light_free(); |
---|
1903 | #endif |
---|
1904 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
1905 | rdtcs_free(); |
---|
1906 | #endif |
---|
1907 | |
---|
1908 | waveform_free(); |
---|
1909 | |
---|
1910 | #ifdef SUPPORT_PIDFILE |
---|
1911 | if ( pidfile != NULL ) |
---|
1912 | unlink(pidfile); |
---|
1913 | #endif |
---|
1914 | } |
---|
1915 | |
---|
1916 | void clean_quit (void) { |
---|
1917 | clean_quit_prep(); |
---|
1918 | // driver_close(drvinst, drvid); |
---|
1919 | // output_buffer_free(); |
---|
1920 | exit(0); |
---|
1921 | } |
---|
1922 | |
---|
1923 | //ll |
---|