/** * @file src/main.c Main application code * * Copyright (C) 2010 - 2015 Creytiv.com */ #ifdef SOLARIS #define __EXTENSIONS__ 1 #endif #include #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_GETOPT #include #endif #include #include static void signal_handler(int sig) { static bool term = false; if (term) { mod_close(); exit(0); } term = true; info("terminated by signal %d\n", sig); ua_stop_all(false); } static void ua_exit_handler(void *arg) { (void)arg; debug("ua exited -- stopping main runloop\n"); /* The main run-loop can be stopped now */ re_cancel(); } static void usage(void) { (void)re_fprintf(stderr, "Usage: baresip [options]\n" "options:\n" #if HAVE_INET6 "\t-6 Prefer IPv6\n" #endif "\t-d Daemon\n" "\t-e Exec commands\n" "\t-f Config path\n" "\t-m Pre-load modules (repeat)\n" "\t-p Audio files\n" "\t-h -? Help\n" "\t-t Test and exit\n" "\t-u Extra UA parameters\n" "\t-v Verbose debug\n" ); } int main(int argc, char *argv[]) { bool prefer_ipv6 = false, run_daemon = false, test = false; const char *ua_eprm = NULL; const char *exec = NULL; const char *audio_path = NULL; const char *modv[16]; size_t modc = 0; int err; (void)re_fprintf(stderr, "baresip v%s" " Copyright (C) 2010 - 2016" " Alfred E. Heggestad et al.\n", BARESIP_VERSION); (void)sys_coredump_set(true); err = libre_init(); if (err) goto out; #ifdef HAVE_GETOPT for (;;) { const int c = getopt(argc, argv, "6de:f:p:hu:vtm:"); if (0 > c) break; switch (c) { case '?': case 'h': usage(); return -2; #if HAVE_INET6 case '6': prefer_ipv6 = true; break; #endif case 'd': run_daemon = true; break; case 'e': exec = optarg; break; case 'f': conf_path_set(optarg); break; case 'm': if (modc >= ARRAY_SIZE(modv)) { warning("max %zu modules\n", ARRAY_SIZE(modv)); err = EINVAL; goto out; } modv[modc++] = optarg; break; case 'p': audio_path = optarg; break; case 't': test = true; break; case 'u': ua_eprm = optarg; break; case 'v': log_enable_debug(true); break; default: break; } } #else (void)argc; (void)argv; #endif err = conf_configure(); if (err) { warning("main: configure failed: %m\n", err); goto out; } /* Set audio path preferring the one given in -p argument (if any) */ if (audio_path) play_set_path(audio_path); else if (str_isset(conf_config()->audio.audio_path)) play_set_path(conf_config()->audio.audio_path); /* * Initialise the top-level baresip struct, must be * done AFTER configuration is complete. */ err = baresip_init(conf_config(), prefer_ipv6); if (err) { warning("main: baresip init failed (%m)\n", err); goto out; } /* NOTE: must be done after all arguments are processed */ if (modc) { size_t i; info("pre-loading modules: %zu\n", modc); for (i=0; i