+}
+
+int main(int argc, char **argv) {
+ int n;
+
+ set_progname(argv);
+ if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
+ while((n = getopt_long(argc, argv, "hVc:dD", options, 0)) >= 0) {
+ switch(n) {
+ case 'h': help();
+ case 'V': version();
+ case 'c': configfile = optarg; break;
+ case 'd': debugging = 1; break;
+ case 'D': debugging = 0; break;
+ default: fatal(0, "invalid option");
+ }
+ }
+ if(getenv("DISORDER_DEBUG_SPEAKER")) debugging = 1;
+ /* If stderr is a TTY then log there, otherwise to syslog. */
+ if(!isatty(2)) {
+ openlog(progname, LOG_PID, LOG_DAEMON);
+ log_default = &log_syslog;
+ }
+ if(config_read()) fatal(0, "cannot read configuration");
+ /* ignore SIGPIPE */
+ signal(SIGPIPE, SIG_IGN);
+ /* reap kids */
+ signal(SIGCHLD, reap);
+ /* set nice value */
+ xnice(config->nice_speaker);
+ /* change user */
+ become_mortal();
+ /* make sure we're not root, whatever the config says */
+ if(getuid() == 0 || geteuid() == 0) fatal(0, "do not run as root");
+ /* identify the backend used to play */
+ for(n = 0; backends[n].backend != -1; ++n)
+ if(backends[n].backend == config->speaker_backend)
+ break;
+ if(backends[n].backend == -1)
+ fatal(0, "unsupported backend %d", config->speaker_backend);
+ backend = &backends[n];
+ /* backend-specific initialization */
+ backend->init();
+ mainloop();