1
0
Fork 0
mbuni/mbuni/mmsc/mmsc.c

99 lines
2.2 KiB
C

/*
* Mbuni - Open Source MMS Gateway
*
* MMSC: Full MMSC startup
*
* Copyright (C) 2003 - 2008, Digital Solutions Ltd. - http://www.dsmagic.com
*
* Paul Bagyenda <bagyenda@dsmagic.com>
*
* This program is free software, distributed under the terms of
* the GNU General Public License, with a few exceptions granted (see LICENSE)
*/
#include "mmsc.h"
#include "mms_uaprof.h"
static mCfg *cfg;
MmscSettings *settings;
List *proxyrelays;
static void quit_now(int notused)
{
stop_mmsrelay();
stop_mmsproxy();
}
/* manage the SIGHUP signal */
static void relog_now(int notused)
{
warning(0, "SIGHUP received, catching and re-opening logs");
log_reopen();
alog_reopen();
}
int main(int argc, char *argv[])
{
int cfidx;
Octstr *fname;
long r_thread = 0;
mms_lib_init();
srandom(time(NULL));
cfidx = get_and_set_debugs(argc, argv, NULL);
if (argv[cfidx] == NULL)
fname = octstr_imm("mbuni.conf");
else
fname = octstr_create(argv[cfidx]);
cfg = mms_cfg_read(fname);
if (cfg == NULL)
panic(0, "Couldn't read configuration from '%s'.", octstr_get_cstr(fname));
octstr_destroy(fname);
info(0, "----------------------------------------");
info(0, " " MM_NAME " MMSC version %s starting", MMSC_VERSION);
settings = mms_load_mmsc_settings(cfg,&proxyrelays);
mms_cfg_destroy(cfg);
if (!settings)
panic(0, "No global MMSC configuration!");
signal(SIGHUP, relog_now);
signal(SIGTERM, quit_now);
signal(SIGPIPE,SIG_IGN); /* Ignore pipe errors. They kill us sometimes for nothing*/
if ((r_thread = gwthread_create((gwthread_func_t *)mmsrelay, NULL)) < 0)
panic(0, "Failed to start MMSC Relay component!");
if (mmsproxy() < 0)
panic(0, "Failed to start MMSC Relay component!");
/* We are done. Cleanup. */
info(0, "MMSC shutdown commenced.");
gwthread_join(r_thread);
sleep(2); /* Wait for them to die. */
info(0, "Final cleanup...");
mms_cleanup_mmsc_settings(settings); /* Stop settings stuff and so on. */
info(0, "Shutdown complete...");
mms_lib_shutdown();
return 0;
}