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"
|
|
|
|
|
|
|
|
/* Server */
|
2017-07-11 14:38:52 +00:00
|
|
|
#include "app.h"
|
2017-02-02 11:34:37 +00:00
|
|
|
|
2017-03-22 07:59:34 +00:00
|
|
|
static char *compile_time = __DATE__ " " __TIME__;
|
2017-02-02 11:34:37 +00:00
|
|
|
|
|
|
|
static void show_version()
|
|
|
|
{
|
2017-07-10 05:33:46 +00:00
|
|
|
printf("NextEPC daemon v%s - %s\n", PACKAGE_VERSION, compile_time);
|
2017-02-02 11:34:37 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 05:16:15 +00:00
|
|
|
static void show_help(const char *name)
|
2017-02-02 11:34:37 +00:00
|
|
|
{
|
|
|
|
show_version();
|
|
|
|
|
|
|
|
printf("\n"
|
2017-07-11 05:16:15 +00:00
|
|
|
"Usage: %s [arguments]\n"
|
2017-02-02 11:34:37 +00:00
|
|
|
"\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"
|
2017-07-11 05:16:15 +00:00
|
|
|
"\n", name);
|
2017-02-02 11:34:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int check_signal(int signum)
|
|
|
|
{
|
|
|
|
switch (signum)
|
|
|
|
{
|
|
|
|
case SIGTERM:
|
|
|
|
case SIGINT:
|
|
|
|
{
|
|
|
|
d_info("%s received",
|
|
|
|
signum == SIGTERM ? "SIGTERM" : "SIGINT");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2017-03-26 06:57:46 +00:00
|
|
|
case SIGUSR1:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2017-02-02 11:34:37 +00:00
|
|
|
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':
|
2017-07-11 05:16:15 +00:00
|
|
|
show_help(argv[0]);
|
2017-02-02 11:34:37 +00:00
|
|
|
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:
|
2017-07-11 05:16:15 +00:00
|
|
|
show_help(argv[0]);
|
2017-02-02 11:34:37 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-26 14:11:50 +00:00
|
|
|
{
|
2017-04-11 06:13:30 +00:00
|
|
|
#if 0
|
2017-04-18 11:21:53 +00:00
|
|
|
extern int _s1ap_path;
|
|
|
|
d_trace_level(&_s1ap_path, 100);
|
2017-04-18 09:24:37 +00:00
|
|
|
extern int _sgw_path;
|
|
|
|
d_trace_level(&_sgw_path, 100);
|
|
|
|
extern int _pgw_path;
|
|
|
|
d_trace_level(&_pgw_path, 100);
|
|
|
|
extern int _pgw_context;
|
|
|
|
d_trace_level(&_pgw_context, 100);
|
2017-03-30 14:27:26 +00:00
|
|
|
extern int _gtp_xact;
|
|
|
|
d_trace_level(&_gtp_xact, 100);
|
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-04-10 14:59:59 +00:00
|
|
|
extern int _s1ap_sm;
|
|
|
|
d_trace_level(&_s1ap_sm, 100);
|
|
|
|
extern int _emm_sm;
|
|
|
|
d_trace_level(&_emm_sm, 100);
|
2017-04-14 04:41:33 +00:00
|
|
|
extern int _bearer_sm;
|
|
|
|
d_trace_level(&_bearer_sm, 100);
|
2017-02-26 14:11:50 +00:00
|
|
|
|
2017-03-07 07:19:18 +00:00
|
|
|
extern int _s1ap_recv;
|
|
|
|
d_trace_level(&_s1ap_recv, 100);
|
2017-04-04 02:00:25 +00:00
|
|
|
extern int _s1ap_send;
|
2017-03-07 07:19:18 +00:00
|
|
|
d_trace_level(&_s1ap_send, 100);
|
2017-04-04 02:00:25 +00:00
|
|
|
extern int _s6a;
|
|
|
|
d_trace_level(&_s6a, 100);
|
2017-03-15 14:07:31 +00:00
|
|
|
extern int _tlv_msg;
|
|
|
|
d_trace_level(&_tlv_msg, 1);
|
2017-03-07 07:19:18 +00:00
|
|
|
#endif
|
2017-02-26 14:11:50 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 05:09:31 +00:00
|
|
|
show_version();
|
|
|
|
d_print("\n");
|
|
|
|
|
2017-07-11 14:38:52 +00:00
|
|
|
if (app_initialize(config_path, log_path) != CORE_OK)
|
2017-02-02 11:34:37 +00:00
|
|
|
{
|
2017-07-10 05:33:46 +00:00
|
|
|
d_fatal("NextEPC initialization failed. Aborted");
|
2017-02-02 11:34:37 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2017-02-27 06:09:41 +00:00
|
|
|
|
2017-07-14 05:09:31 +00:00
|
|
|
d_print("\n\n");
|
2017-07-10 05:33:46 +00:00
|
|
|
d_info("NextEPC daemon start");
|
2017-02-02 11:34:37 +00:00
|
|
|
signal_thread(check_signal);
|
|
|
|
|
2017-07-10 05:33:46 +00:00
|
|
|
d_info("NextEPC daemon terminating...");
|
2017-02-02 11:34:37 +00:00
|
|
|
|
2017-07-11 14:38:52 +00:00
|
|
|
app_terminate();
|
2017-02-02 11:34:37 +00:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|