source: roaraudio/roard/roard.c @ 1145:a5edc8a12b46

Last change on this file since 1145:a5edc8a12b46 was 1145:a5edc8a12b46, checked in by phi, 15 years ago

use the new driver interface by default

File size: 19.0 KB
Line 
1//roard.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27char * server = ROAR_DEFAULT_SOCK_GLOBAL; // global server address
28
29void usage (void) {
30 printf("Usage: roard [OPTIONS]...\n\n");
31
32 printf("Misc Options:\n\n");
33 printf(
34        " --daemon              - Bring the server into background after init\n"
35        " --terminate           - Terminate after last client quited\n"
36        " --restart             - Trys to stop an old instance and start a new with new settings\n"
37        " --realtime            - Trys to get realtime priority,\n"
38        "                         give multible times for being more realtime\n"
39        " --chroot DIR          - chroots to the given dir\n"
40        " --setgid              - GroupID to the audio group as specified via -G\n"
41        " --setuid              - UserID to the audio user as specified via -U\n"
42        " --sysclocksync        - calculate exact sample rate using the system clock\n"
43       );
44
45 printf("\nAudio Options:\n\n");
46 printf(
47        " -R  --rate   RATE     - Set server rate\n"
48        " -B  --bits   BITS     - Set server bits\n"
49        " -C  --chans  CHANNELS - Set server channels\n"
50       );
51
52 printf("\nDriver Options:\n\n");
53 printf(" -d  --driver DRV      - Set the driver (default: %s)\n", ROAR_DRIVER_DEFAULT);
54 printf(" -D  --device DEV      - Set the device\n");
55 printf(" -dO OPTS              - Set output options\n");
56 printf(" --list-driver         - List all drivers\n");
57
58 printf("\nOutput Options:\n\n");
59 printf(" -o  --odriver DRV     - Set the driver, use '--list-driver' to get a list\n");
60 printf(" -O  --odevice DEV     - Set the device\n");
61 printf(" -oO OPTS              - Set output options\n");
62 printf(" -oN                   - Adds another output\n");
63 printf(" -oP                   - Mark output as primary\n");
64
65 printf("\nSource Options:\n\n");
66 printf(" -s  --source DRV      - Use DRV as input driver\n"
67        " -S           DEV      - Use DEV as input device\n"
68        " -sO          OPTS     - Use OPTS as input options\n"
69        " -sP                   - Make souce as primary\n"
70       );
71
72 printf("\nCodec Filter Options:\n\n");
73 printf(" --list-cf             - List all codec filter\n"
74       );
75
76 printf("\nServer Options:\n\n");
77 printf(" -t  --tcp             - Use TCP listen socket\n"
78        " -u  --unix            - Use UNIX Domain listen socket (default)\n"
79#ifdef ROAR_HAVE_LIBDNET
80        " -n  --decnet          - use DECnet listen socket\n"
81#endif
82        " -4                    - Use IPv4 connections (implies -t)\n"
83#ifdef PF_INET6
84        " -6                    - Use IPv6 connections (implies -t)\n"
85#endif
86#ifdef IPV6_ADDRFORM
87        " -64                   - Try to downgrade sockets from IPv6 into IPv4,\n"
88        "                         this is normaly not usefull.\n"
89#endif
90        " -p  --port            - TCP Port to bind to\n"
91        " -b  --bind            - IP/Hostname to bind to\n"
92        "     --sock            - Filename for UNIX Domain Socket\n"
93        " -G  GROUP             - Sets the group for the UNIX Domain Socket, (default: %s)\n"
94        "                         You need the permittions to change the GID\n"
95        " -U  USER              - Sets the user for the UNIX Domain Socket, (default: do not set)\n"
96        "                         You need the permittions to change the UID (normaly only root has)\n"
97        " --no-listen           - Do not listen for new clients\n"
98        "                         (only usefull for relaing, impleys --terminate)\n"
99        " --client-fh           - Comunicate with a client over this handle\n"
100        "                         (only usefull for relaing)\n"
101        " --close-fh            - Closes the given fh\n"
102        " --standby             - Start in standby state\n"
103        " --auto-standby        - Automatical goes into standby if there are no streams\n",
104        ROAR_DEFAULT_SOCKGRP
105       );
106// printf("\n Options:\n\n");
107 printf("\n");
108}
109
110int restart_server (char * server) {
111 struct roar_connection con;
112 if ( roar_connect(&con, server) == -1 ) {
113  return -1;
114 }
115
116 if ( roar_terminate(&con, 1) == -1 ) {
117  return -1;
118 }
119
120 return roar_disconnect(&con);
121}
122
123#define R_SETUID 1
124#define R_SETGID 2
125
126int add_output (char * drv, char * dev, char * opts, int prim, int count) {
127 int stream;
128 struct roar_stream * s;
129 struct roar_stream_server * ss;
130 char * k, * v;
131 int codec;
132 int sync = 0;
133
134 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
135
136 if ( drv == NULL && count == 0 ) {
137  drv  = ROAR_DRIVER_DEFAULT;
138  prim = 1;
139  sync = 1;
140 }
141
142 if ( (stream = streams_new()) == -1 ) {
143  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
144  if ( prim ) alive = 0;
145  return -1;
146 }
147
148 streams_get(stream, &ss);
149 s = ROAR_STREAM(ss);
150
151 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
152
153 s->dir        = ROAR_DIR_OUTPUT;
154 s->pos_rel_id = -1;
155// s->info.codec = codec;
156
157 codec = s->info.codec;
158
159 k = strtok(opts, ",");
160 while (k != NULL) {
161//  ROAR_WARN("add_output(*): opts: %s", k);
162
163  if ( (v = strstr(k, "=")) != NULL ) {
164   *v++ = 0;
165  }
166
167  ROAR_DBG("add_output(*): opts: k='%s', v='%s'", k, v);
168  if ( strcmp(k, "rate") == 0 ) {
169   s->info.rate = atoi(v);
170  } else if ( strcmp(k, "channels") == 0 ) {
171   s->info.channels = atoi(v);
172  } else if ( strcmp(k, "bits") == 0 ) {
173   s->info.bits = atoi(v);
174  } else if ( strcmp(k, "codec") == 0 ) {
175   if ( (codec = roar_str2codec(v)) == -1 ) {
176    ROAR_ERR("add_output(*): unknown codec '%s'", v);
177    streams_delete(stream);
178    if ( prim ) alive = 0;
179    return -1;
180   }
181  } else if ( strcmp(k, "meta") == 0 ) {
182   streams_set_flag(stream, ROAR_FLAG_META);
183  } else if ( strcmp(k, "sync") == 0 ) {
184   sync = 1;
185  } else {
186   ROAR_ERR("add_output(*): unknown option '%s'", k);
187   streams_delete(stream);
188   if ( prim ) alive = 0;
189   return -1;
190  }
191
192  k = strtok(NULL, ",");
193 }
194
195 if ( codec == ROAR_CODEC_ALAW || codec == ROAR_CODEC_MULAW )
196  s->info.bits = 8; // needed to open OSS driver, will be overriden by codecfilter
197
198 s->info.codec = codec;
199 ROAR_STREAM_SERVER(s)->codec_orgi = codec;
200
201 if ( driver_openvio(&(ss->vio), &(ss->driver_id), drv, dev, &(s->info), -1) == -1 ) {
202  streams_delete(stream);
203  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
204  if ( prim ) alive = 0;
205  return -1;
206 }
207
208 streams_set_fh(stream, -1); // update some internal structures
209
210 client_stream_add(g_source_client, stream);
211
212 if ( prim )
213  streams_mark_primary(stream);
214
215 if ( sync ) {
216  streams_set_flag(stream, ROAR_FLAG_SYNC);
217 } else {
218  streams_reset_flag(stream, ROAR_FLAG_SYNC);
219 }
220
221 return 0;
222}
223
224int main (int argc, char * argv[]) {
225 int i;
226 char * k;
227 char user_sock[80]  = {0};
228 struct roar_audio_info sa;
229 int    daemon       = 0;
230 int    realtime     = 0;
231 int    sysclocksync = 0;
232 char * driver = getenv("ROAR_DRIVER");
233 char * device = getenv("ROAR_DEVICE");
234 char * opts   = NULL;
235// char * server = ROAR_DEFAULT_SOCK_GLOBAL;
236 int      port = ROAR_DEFAULT_PORT;
237 int               drvid;
238 char * s_drv     = "cf";
239 char * s_dev     = NULL;
240 char * s_con     = NULL;
241 char * s_opt     = NULL;
242 int    s_prim    = 0;
243 char * o_drv     = NULL;
244 char * o_dev     = NULL;
245 char * o_opts    = NULL;
246 int    o_prim    = 0;
247 int    o_count   = 0;
248 char * sock_grp  = ROAR_DEFAULT_SOCKGRP;
249 char * sock_user = NULL;
250 int    sock_type = ROAR_SOCKET_TYPE_UNKNOWN;
251 char * chrootdir = NULL;
252 int    setids    = 0;
253 char * env_roar_proxy_backup;
254 struct group   * grp  = NULL;
255 struct passwd  * pwd  = NULL;
256 struct servent * serv = NULL;
257 DRIVER_USERDATA_T drvinst;
258 struct roar_client * self = NULL;
259#ifdef ROAR_HAVE_LIBDNET
260 char decnethost[80];
261#endif
262
263 g_listen_socket = -1;
264 g_standby       =  0;
265 g_autostandby   =  0;
266 alive           =  1;
267
268 sa.bits     = ROAR_BITS_DEFAULT;
269 sa.channels = ROAR_CHANNELS_DEFAULT;
270 sa.rate     = ROAR_RATE_DEFAULT;
271 sa.codec    = ROAR_CODEC_DEFAULT;
272
273 g_sa = &sa;
274
275
276 if ( getuid() != 0 && getenv("HOME") ) {
277  snprintf(user_sock, 79, "%s/%s", getenv("HOME"), ROAR_DEFAULT_SOCK_USER);
278  server = user_sock;
279 }
280
281 if ( getenv("ROAR_SERVER") != NULL )
282  server = getenv("ROAR_SERVER");
283
284 if ( clients_init() == -1 ) {
285  ROAR_ERR("Can not init clients!");
286  return 1;
287 }
288
289 if ( streams_init() == -1 ) {
290  ROAR_ERR("Can not init streams!");
291  return 1;
292 }
293
294 if ( (g_self_client = clients_new()) == -1 ) {
295  ROAR_ERR("Can not create self client!");
296  return 1;
297 }
298
299 if ( sources_init() == -1 ) {
300  ROAR_ERR("Can not init sources!");
301  return 1;
302 }
303
304 if ( (sources_set_client(g_self_client)) == -1 ) {
305  ROAR_ERR("Can not init set source client!");
306  return 1;
307 }
308
309 for (i = 1; i < argc; i++) {
310  k = argv[i];
311
312  if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) {
313   usage();
314   return 0;
315
316  } else if ( strcmp(k, "--restart") == 0 ) {
317   if ( restart_server(server) == -1 ) {
318    ROAR_WARN("Can not terminate old server (not running at %s?), tring to continue anyway", server);
319   }
320
321  } else if ( strcmp(k, "--demon") == 0 || strcmp(k, "--daemon") == 0 ) {
322   daemon = 1;
323  } else if ( strcmp(k, "--terminate") == 0 ) {
324   g_terminate = 1;
325  } else if ( strcmp(k, "--sysclocksync") == 0 ) {
326   sysclocksync = 1000;
327  } else if ( strcmp(k, "--realtime") == 0 ) {
328   realtime++;
329  } else if ( strcmp(k, "--chroot") == 0 ) {
330   chrootdir = argv[++i];
331  } else if ( strcmp(k, "--setgid") == 0 ) {
332   setids |= R_SETGID;
333  } else if ( strcmp(k, "--setuid") == 0 ) {
334   setids |= R_SETUID;
335
336  } else if ( strcmp(k, "--list-cf") == 0 ) {
337   print_codecfilterlist();
338   return 0;
339
340  } else if ( strcmp(k, "-R") == 0 || strcmp(k, "--rate") == 0 ) {
341   sa.rate = atoi(argv[++i]);
342  } else if ( strcmp(k, "-B") == 0 || strcmp(k, "--bits") == 0 ) {
343   sa.bits = atoi(argv[++i]);
344  } else if ( strcmp(k, "-C") == 0 || strcmp(k, "--chans") == 0 ) {
345   sa.channels = atoi(argv[++i]);
346
347  } else if ( strcmp(k, "-d") == 0 || strcmp(k, "--driver") == 0 ) {
348   driver = argv[++i];
349   if ( strcmp(driver, "list") == 0 ) {
350    ROAR_WARN("The option is obsolete, use --list-driver!");
351    print_driverlist();
352    return 0;
353   }
354  } else if ( strcmp(k, "-D") == 0 || strcmp(k, "--device") == 0 ) {
355   device = argv[++i];
356  } else if ( strcmp(k, "-dO") == 0 ) {
357   opts = argv[++i];
358  } else if ( strcmp(k, "--list-driver") == 0 ) {
359   print_driverlist();
360   return 0;
361
362  } else if ( strcmp(k, "-o") == 0 || strcmp(k, "--odriver") == 0 ) {
363   o_drv  = argv[++i];
364  } else if ( strcmp(k, "-O") == 0 || strcmp(k, "--odevice") == 0 ) {
365   o_dev  = argv[++i];
366  } else if ( strcmp(k, "-oO") == 0 ) {
367   o_opts = argv[++i];
368  } else if ( strcmp(k, "-oP") == 0 ) {
369   o_prim = 1;
370  } else if ( strcmp(k, "-oN") == 0 ) {
371   if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 )
372    o_count++;
373
374   o_drv  = o_dev = o_opts = NULL;
375   o_prim = 0;
376
377  } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) {
378   s_drv = argv[++i];
379  } else if ( strcmp(k, "-S") == 0 ) {
380   s_dev = argv[++i];
381  } else if ( strcmp(k, "-sO") == 0 ) {
382   s_opt = argv[++i];
383  } else if ( strcmp(k, "-sC") == 0 ) {
384   s_con = argv[++i];
385  } else if ( strcmp(k, "-sP") == 0 ) {
386   s_prim = 1;
387  } else if ( strcmp(k, "-sN") == 0 ) {
388   if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
389    ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
390   }
391   s_opt = s_dev = s_con = NULL;
392   s_drv = "cf";
393   s_prim = 0;
394
395  } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--port") == 0 ) {
396   // This is only usefull in INET not UNIX mode.
397   if ( *server == '/' )
398    server = ROAR_DEFAULT_HOST;
399
400   errno = 0;
401   if ( (port = atoi(argv[++i])) < 1 ) {
402    if ( (serv = getservbyname(argv[i], "tcp")) == NULL ) {
403     ROAR_ERR("Unknown service: %s: %s", argv[i], strerror(errno));
404     return 1;
405    }
406    // NOTE: we need to use ROAR_NET2HOST16() here even if s_port is of type int!
407    ROAR_DBG("main(*): serv = {s_name='%s', s_aliases={...}, s_port=%i, s_proto='%s'}",
408            serv->s_name, ROAR_NET2HOST16(serv->s_port), serv->s_proto);
409    port = ROAR_NET2HOST16(serv->s_port);
410   }
411  } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) {
412   server = argv[++i];
413
414  } else if ( strcmp(k, "-t") == 0 || strcmp(k, "--tcp") == 0 ) {
415   if ( sock_type != ROAR_SOCKET_TYPE_TCP && sock_type != ROAR_SOCKET_TYPE_TCP6 )
416    sock_type = ROAR_SOCKET_TYPE_TCP;
417
418   if ( *server == '/' )
419    server = ROAR_DEFAULT_HOST;
420
421  } else if ( strcmp(k, "-4") == 0 ) {
422   sock_type = ROAR_SOCKET_TYPE_TCP;
423   if ( *server == '/' )
424    server = ROAR_DEFAULT_HOST;
425  } else if ( strcmp(k, "-6") == 0 ) {
426#ifdef PF_INET6
427   sock_type = ROAR_SOCKET_TYPE_TCP6;
428   if ( *server == '/' )
429    server = ROAR_DEFAULT_HOST;
430#else
431    ROAR_ERR("No IPv6 support compiled in!");
432    return 1;
433#endif
434
435  } else if ( strcmp(k, "-u") == 0 || strcmp(k, "--unix") == 0 ) {
436   // ignore this case as it is the default behavor.
437   sock_type = ROAR_SOCKET_TYPE_UNIX;
438
439  } else if ( strcmp(k, "-n") == 0 || strcmp(k, "--decnet") == 0 ) {
440#ifdef ROAR_HAVE_LIBDNET
441    port   = ROAR_DEFAULT_NUM;
442    strcpy(decnethost, ROAR_DEFAULT_LISTEN_OBJECT);
443    server = decnethost;
444    sock_type = ROAR_SOCKET_TYPE_DECNET;
445#else
446    ROAR_ERR("No DECnet support compiled in!");
447    return 1;
448#endif
449
450  } else if ( strcmp(k, "-G") == 0 ) {
451   sock_grp  = argv[++i];
452  } else if ( strcmp(k, "-U") == 0 ) {
453   sock_user = argv[++i];
454
455  } else if ( strcmp(k, "--no-listen") == 0 ) {
456   *server     = 0;
457   g_terminate = 1;
458  } else if ( strcmp(k, "--client-fh") == 0 ) {
459   if ( clients_set_fh(clients_new(), atoi(argv[++i])) == -1 ) {
460    ROAR_ERR("main(*): Can not set client's fh");
461    return 1;
462   }
463  } else if ( strcmp(k, "--close-fh") == 0 ) {
464   close(atoi(argv[++i]));
465
466  } else if ( strcmp(k, "--standby") == 0 ) {
467   g_standby = 1;
468  } else if ( strcmp(k, "--auto-standby") == 0 ) {
469   g_autostandby = 1;
470  } else {
471   usage();
472   return 1;
473  }
474
475 }
476
477 if ( s_dev != NULL ) {
478  if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
479   ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
480  }
481 }
482
483 add_output(o_drv, o_dev, o_opts, o_prim, o_count);
484
485 ROAR_DBG("Server config: rate=%i, bits=%i, chans=%i", sa.rate, sa.bits, sa.channels);
486
487 if ( midi_init() == -1 )
488  ROAR_ERR("Can not initialize MIDI subsystem");
489
490 if ( *server != 0 ) {
491  if ( (g_listen_socket = roar_socket_listen(sock_type, server, port)) == -1 ) {
492   if ( *server == '/' ) {
493    if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) {
494     env_roar_proxy_backup = strdup(env_roar_proxy_backup);
495     unsetenv("ROAR_PROXY");
496    }
497    if ( (i = roar_socket_connect(server, port)) != -1 ) {
498     close(i);
499     ROAR_ERR("Can not open listen socket!");
500     return 1;
501    } else {
502     unlink(server);
503     if ( (g_listen_socket = roar_socket_listen(sock_type, server, port)) == -1 ) {
504      ROAR_ERR("Can not open listen socket!");
505      return 1;
506     }
507    }
508    if ( env_roar_proxy_backup != NULL ) {
509     setenv("ROAR_PROXY", env_roar_proxy_backup, 0);
510     free(env_roar_proxy_backup);
511    }
512   } else {
513    ROAR_ERR("Can not open listen socket!");
514    return 1;
515   }
516  }
517
518  if ( (grp = getgrnam(sock_grp)) == NULL ) {
519   ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno));
520  }
521  if ( sock_user || (setids & R_SETUID) ) {
522   if ( (pwd = getpwnam(sock_user)) == NULL ) {
523    ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno));
524   }
525  }
526
527  if ( *server == '/' ) {
528   if ( grp ) {
529    if ( pwd ) {
530     chown(server, pwd->pw_uid, grp->gr_gid);
531    } else {
532     chown(server, -1, grp->gr_gid);
533    }
534    if ( getuid() == 0 )
535     chmod(server, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
536   }
537  }
538 }
539
540 if ( output_buffer_init(&sa) == -1 ) {
541  ROAR_ERR("Can not init output buffer!");
542  return 1;
543 }
544
545 if ( driver == NULL ) {
546  driver = "null";
547 } else {
548  ROAR_WARN("Usage of old driver interface. use -o not -d!");
549 }
550
551 if ( driver_open(&drvinst, &drvid, driver, device, &sa) == -1 ) {
552  ROAR_ERR("Can not open output driver!");
553  return 1;
554 }
555
556 if ( samples_init() == -1 ) {
557  ROAR_ERR("Can not init samples!");
558  return 1;
559 }
560
561
562 signal(SIGINT,  on_sig_int);
563 signal(SIGCHLD, on_sig_chld);
564 signal(SIGPIPE, SIG_IGN);  // ignore broken pipes
565
566 if ( realtime ) {
567#ifdef DEBUG
568  ROAR_WARN("compiled with -DDEBUG but realtime is enabled: for real realtime support compiel without -DDEBUG");
569#endif
570
571  errno = 0;
572  nice(-5*realtime); // -5 for each --realtime
573  if ( errno )
574   ROAR_WARN("Can not decrease nice value by 5: %s", strerror(errno));
575/*
576#ifdef __linux__
577  if ( ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0)) == -1 )
578   ROAR_WARN("Can not set io priority: %s", strerror(errno));
579#endif
580*/
581 }
582
583 if ( setids & R_SETGID ) {
584  if ( setgroups(0, (const gid_t *) NULL) == -1 ) {
585   ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno));
586  }
587  if ( !grp || setgid(grp->gr_gid) == -1 ) {
588   ROAR_ERR("Can not set GroupID: %s", strerror(errno));
589  }
590 }
591
592
593 clients_set_pid(g_self_client, getpid());
594 clients_set_uid(g_self_client, getuid());
595 clients_set_gid(g_self_client, getgid());
596 clients_get(g_self_client, &self);
597
598 if ( self == NULL ) {
599  ROAR_ERR("Can not get self client!");
600  return 1;
601 }
602
603 strcpy(self->name, "RoarAudio daemon internal");
604
605 if ( daemon ) {
606  close(ROAR_STDIN );
607  close(ROAR_STDOUT);
608  close(ROAR_STDERR);
609  setsid();
610  if ( fork() )
611   _exit(0);
612  clients_set_pid(g_self_client, getpid()); // reset pid as it changed
613 }
614
615 if (chrootdir) {
616  if ( chroot(chrootdir) == -1 ) {
617   ROAR_ERR("Can not chroot to %s: %s", chrootdir, strerror(errno));
618   return 2;
619  }
620  if ( chdir("/") == -1 ) {
621   ROAR_ERR("Can not chdir to /: %s", strerror(errno));
622   return 2;
623  }
624 }
625
626 if ( setids & R_SETUID ) {
627  if ( !pwd || setuid(pwd->pw_uid) == -1 ) {
628   ROAR_ERR("Can not set UserID: %s", strerror(errno));
629   return 3;
630  }
631  clients_set_uid(g_self_client, getuid());
632 }
633
634 // start main loop...
635 main_loop(drvid, drvinst, &sa, sysclocksync);
636
637 // clean up.
638 clean_quit_prep();
639 driver_close(drvinst, drvid);
640 output_buffer_free();
641
642 return 0;
643}
644
645void cleanup_listen_socket (int terminate) {
646
647 if ( g_listen_socket != -1 ) {
648  close(g_listen_socket);
649
650  g_listen_socket = -1;
651
652  if ( *server == '/' )
653   unlink(server);
654 }
655
656 if ( terminate )
657  g_terminate = 1;
658}
659
660void clean_quit_prep (void) {
661 cleanup_listen_socket(0);
662
663 sources_free();
664 streams_free();
665 clients_free();
666 midi_cb_stop(); // stop console beep
667 midi_free();
668}
669
670void clean_quit (void) {
671 clean_quit_prep();
672// driver_close(drvinst, drvid);
673// output_buffer_free();
674 exit(0);
675}
676
677//ll
Note: See TracBrowser for help on using the repository browser.