2017-02-02 11:34:37 +00:00
|
|
|
/**
|
|
|
|
* @file main.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Core library */
|
|
|
|
#define TRACE_MODULE _main_
|
|
|
|
#include "core_debug.h"
|
|
|
|
#include "core_signal.h"
|
|
|
|
|
|
|
|
#include "symtbl.h"
|
|
|
|
|
|
|
|
/* Server */
|
|
|
|
#include "cellwire.h"
|
|
|
|
|
|
|
|
extern char g_compile_time[];
|
|
|
|
|
|
|
|
static void show_version()
|
|
|
|
{
|
|
|
|
printf("CellWire daemon v%s - %s\n",
|
|
|
|
PACKAGE_VERSION, g_compile_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_help()
|
|
|
|
{
|
|
|
|
show_version();
|
|
|
|
|
|
|
|
printf("\n"
|
|
|
|
"Usage: cellwired [arguments]\n"
|
|
|
|
"\n"
|
|
|
|
"Arguments:\n"
|
|
|
|
" -v Show version\n"
|
|
|
|
" -h Show help\n"
|
|
|
|
" -d Start as daemon\n"
|
|
|
|
" -f Set configuration file name\n"
|
|
|
|
" -l log_path Fork log daemon with file path to be logged to\n"
|
|
|
|
"\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int check_signal(int signum)
|
|
|
|
{
|
|
|
|
switch (signum)
|
|
|
|
{
|
|
|
|
case SIGTERM:
|
|
|
|
case SIGINT:
|
|
|
|
{
|
|
|
|
d_info("%s received",
|
|
|
|
signum == SIGTERM ? "SIGTERM" : "SIGINT");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2017-02-27 05:55:35 +00:00
|
|
|
d_error("Unknown signal number = %d\n", signum);
|
2017-02-02 11:34:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
/**************************************************************************
|
|
|
|
* Starting up process.
|
|
|
|
*
|
|
|
|
* Keep the order of starting-up
|
|
|
|
*/
|
2017-02-27 05:55:35 +00:00
|
|
|
char *config_path = NULL;
|
|
|
|
char *log_path = NULL;
|
2017-02-02 11:34:37 +00:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2017-02-27 05:55:35 +00:00
|
|
|
int opt = getopt (argc, argv, "vhdf:l:");
|
2017-02-02 11:34:37 +00:00
|
|
|
if (opt == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (opt)
|
|
|
|
{
|
|
|
|
case 'v':
|
|
|
|
show_version();
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
case 'h':
|
|
|
|
show_help();
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
case 'd':
|
2017-02-27 05:55:35 +00:00
|
|
|
{
|
|
|
|
pid_t pid;
|
|
|
|
pid = fork();
|
|
|
|
|
|
|
|
d_assert(pid >= 0, return EXIT_FAILURE, "fork() failed");
|
|
|
|
|
|
|
|
if (pid != 0)
|
|
|
|
{
|
|
|
|
/* Parent */
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
/* Child */
|
|
|
|
|
|
|
|
setsid();
|
|
|
|
umask(027);
|
2017-02-02 11:34:37 +00:00
|
|
|
break;
|
2017-02-27 05:55:35 +00:00
|
|
|
}
|
2017-02-02 11:34:37 +00:00
|
|
|
case 'f':
|
|
|
|
config_path = optarg;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
log_path = optarg;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
show_help();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-26 14:11:50 +00:00
|
|
|
{
|
2017-03-07 06:52:07 +00:00
|
|
|
#if 0
|
2017-02-26 14:11:50 +00:00
|
|
|
extern int _mme_sm;
|
2017-03-07 07:19:18 +00:00
|
|
|
d_trace_level(&_mme_sm, 100);
|
2017-02-26 14:11:50 +00:00
|
|
|
extern int _enb_s1_sm;
|
2017-03-07 07:19:18 +00:00
|
|
|
d_trace_level(&_enb_s1_sm, 100);
|
2017-03-07 06:52:07 +00:00
|
|
|
extern int _ue_emm_sm;
|
2017-03-07 07:19:18 +00:00
|
|
|
d_trace_level(&_ue_emm_sm, 100);
|
2017-02-26 14:11:50 +00:00
|
|
|
|
2017-03-07 07:19:18 +00:00
|
|
|
extern int _s1ap_recv;
|
2017-03-07 06:52:07 +00:00
|
|
|
d_trace_level(&_ue_emm_sm, 100);
|
2017-03-07 07:19:18 +00:00
|
|
|
extern int _s1ap_send;
|
|
|
|
d_trace_level(&_s1ap_recv, 100);
|
|
|
|
extern int _s6a;
|
|
|
|
d_trace_level(&_s1ap_send, 100);
|
|
|
|
#endif
|
2017-02-26 14:11:50 +00:00
|
|
|
}
|
|
|
|
|
2017-02-27 06:09:41 +00:00
|
|
|
if (cellwire_initialize(config_path, log_path) != CORE_OK)
|
2017-02-02 11:34:37 +00:00
|
|
|
{
|
|
|
|
d_fatal("CellWire initialization failed. Aborted");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2017-02-27 06:09:41 +00:00
|
|
|
|
2017-02-10 13:16:22 +00:00
|
|
|
show_version();
|
2017-02-02 11:34:37 +00:00
|
|
|
d_info("CellWire daemon start");
|
|
|
|
signal_thread(check_signal);
|
|
|
|
|
|
|
|
d_info("CellWire daemon terminating...");
|
|
|
|
|
|
|
|
cellwire_terminate();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|