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