open5gs/src/epc.c

93 lines
2.0 KiB
C
Raw Normal View History

2017-07-11 09:44:59 +00:00
#define TRACE_MODULE _epc_main
#include "core_debug.h"
#include "core_signal.h"
#include "core_semaphore.h"
2017-07-11 14:38:52 +00:00
#include "app.h"
2017-07-11 09:44:59 +00:00
static pid_t hss_pid = 0;
2017-07-11 09:44:59 +00:00
static int check_signal(int signum);
2017-07-11 14:38:52 +00:00
status_t app_initialize(char *config_path, char *log_path)
2017-07-11 09:44:59 +00:00
{
status_t rv;
semaphore_id semaphore;
2017-07-12 12:25:10 +00:00
rv = app_will_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
2017-07-11 09:44:59 +00:00
d_assert(semaphore_create(&semaphore, 0) == CORE_OK,
return rv, "semaphore_create() failed");
2017-07-11 09:44:59 +00:00
hss_pid = fork();
d_assert(hss_pid >= 0, _exit(EXIT_FAILURE), "fork() failed");
if (hss_pid == 0)
{
/* Child */
d_assert(semaphore_wait(semaphore) == CORE_OK,
_exit(EXIT_FAILURE), "semaphore_wait() failed");
d_assert(semaphore_delete(semaphore) == CORE_OK,
_exit(EXIT_FAILURE), "semaphore_delete() failed");
2017-07-11 09:44:59 +00:00
rv = hss_initialize();
if (rv != CORE_OK) _exit(EXIT_FAILURE);
signal_thread(check_signal);
hss_terminate();
_exit(EXIT_SUCCESS);
}
/* Parent */
rv = CORE_OK;
if (pgw_initialize() != CORE_OK) rv = CORE_ERROR;
if (sgw_initialize() != CORE_OK) rv = CORE_ERROR;
if (mme_initialize() != CORE_OK) rv = CORE_ERROR;
2017-07-11 09:44:59 +00:00
d_assert(semaphore_post(semaphore) == CORE_OK,,
"semaphore_post() failed");
2017-07-11 09:44:59 +00:00
if (app_did_initialize(config_path, log_path) != CORE_OK) rv = CORE_ERROR;
2017-07-11 09:44:59 +00:00
return rv;;
2017-07-11 09:44:59 +00:00
}
2017-07-11 14:38:52 +00:00
void app_terminate(void)
2017-07-11 09:44:59 +00:00
{
2017-07-11 14:38:52 +00:00
app_will_terminate();
2017-07-11 09:44:59 +00:00
if (hss_pid)
core_kill(hss_pid, SIGTERM);
2017-07-11 09:44:59 +00:00
mme_terminate();
sgw_terminate();
pgw_terminate();
2017-07-11 14:38:52 +00:00
app_did_terminate();
2017-07-11 09:44:59 +00:00
}
static int check_signal(int signum)
{
switch (signum)
{
case SIGTERM:
case SIGINT:
{
d_info("%s received",
signum == SIGTERM ? "SIGTERM" : "SIGINT");
return 1;
}
default:
{
d_error("Unknown signal number = %d\n", signum);
break;
}
}
return 0;
}