From f8873153be5480ca6b79741e7cbdf667080e562d Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sat, 27 Jun 2015 10:04:47 +0200 Subject: added -m option to pre-load modules before config is parsed --- src/main.c | 54 +++++++++++++++++++++++++++++++++++------------------- src/module.c | 14 ++++++++++++++ 2 files changed, 49 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 51dc3d0..029eacc 100644 --- a/src/main.c +++ b/src/main.c @@ -34,6 +34,26 @@ static void signal_handler(int sig) } +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 module\n" + "\t-p Audio files\n" + "\t-h -? Help\n" + "\t-t Test and exit\n" + "\t-v Verbose debug\n" + ); +} + + int main(int argc, char *argv[]) { bool prefer_ipv6 = false, run_daemon = false, test = false; @@ -47,9 +67,13 @@ int main(int argc, char *argv[]) (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:hvt"); + const int c = getopt(argc, argv, "6de:f:p:hvtm:"); if (0 > c) break; @@ -57,20 +81,7 @@ int main(int argc, char *argv[]) case '?': case 'h': - (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-p Audio files\n" - "\t-h -? Help\n" - "\t-t Test and exit\n" - "\t-v Verbose debug\n" - ); + usage(); return -2; #if HAVE_INET6 @@ -91,6 +102,15 @@ int main(int argc, char *argv[]) conf_path_set(optarg); break; + case 'm': + err = module_preload(optarg); + if (err) { + re_fprintf(stderr, + "could not pre-load module" + " '%s' (%m)\n", optarg, err); + } + break; + case 'p': play_set_path(optarg); break; @@ -112,10 +132,6 @@ int main(int argc, char *argv[]) (void)argv; #endif - err = libre_init(); - if (err) - goto out; - err = conf_configure(); if (err) { warning("main: configure failed: %m\n", err); diff --git a/src/module.c b/src/module.c index 12b3d13..d9c7584 100644 --- a/src/module.c +++ b/src/module.c @@ -154,3 +154,17 @@ void module_app_unload(void) { list_flush(&modappl); } + + +int module_preload(const char *module) +{ + struct pl path, name; + + if (!module) + return EINVAL; + + pl_set_str(&path, "."); + pl_set_str(&name, module); + + return load_module(NULL, &path, &name); +} -- cgit v1.2.3