update it

This commit is contained in:
Sukchan Lee 2017-02-27 14:55:35 +09:00
parent ad44d2ab58
commit 95857bc9bc
6 changed files with 80 additions and 74 deletions

View File

@ -13,6 +13,7 @@
#include "core_net.h"
#include "core_file.h"
#include "core_pkbuf.h"
#include "core_signal.h"
status_t core_app_initialize(int *argc,
const char * const * *argv,
@ -49,6 +50,7 @@ status_t core_initialize(void)
tm_init();
msgq_init();
d_msg_init();
signal_init();
return CORE_OK;
}

View File

@ -4,6 +4,7 @@
#include "core_debug.h"
#include "core_param.h"
#include "core_file.h"
#include "core_signal.h"
#include <stdio.h>
#include <sys/socket.h>
@ -21,6 +22,27 @@ static file_t *g_file = NULL;
static int request_stop = 0;
void check_signal(int signum)
{
switch (signum)
{
case SIGTERM:
case SIGINT:
{
d_info("%s received",
signum == SIGTERM ? "SIGTERM" : "SIGINT");
logger_stop();
break;
}
default:
{
d_error("Unknown signal number = %d\n", signum);
break;
}
}
}
status_t log_file_backup()
{
status_t rv;
@ -88,7 +110,7 @@ status_t log_file_backup()
return CORE_OK;
}
int logger_start(const char *path)
int logger_start_internal(const char *path)
{
status_t rv;
int ret, count = 0;
@ -217,6 +239,33 @@ int logger_start(const char *path)
return 0;
}
void logger_start(const char *path)
{
pid_t pid;
pid = fork();
d_assert(pid >= 0, _exit(EXIT_FAILURE), "fork() failed");
if (pid == 0)
{
int ret;
/* Child */
umask(027);
signal_unblock(SIGINT);
signal_unblock(SIGTERM);
core_signal(SIGINT, check_signal);
core_signal(SIGTERM, check_signal);
ret = logger_start_internal(path);
d_assert(ret == 0, _exit(EXIT_FAILURE), "logger_start() failed");
_exit(EXIT_SUCCESS);
}
/* Parent */
}
void logger_stop()
{
request_stop = 1;

View File

@ -7,7 +7,7 @@
extern "C" {
#endif /* __cplusplus */
CORE_DECLARE(int) logger_start(const char *path);
CORE_DECLARE(void) logger_start(const char *path);
CORE_DECLARE(void) logger_stop();
#ifdef __cplusplus

View File

@ -167,7 +167,7 @@ static int check_signal(int signum)
}
default:
{
d_error("Unknown Signal Number = %d\n", signum);
d_error("Unknown signal number = %d\n", signum);
break;
}

91
main.c
View File

@ -19,7 +19,6 @@
/* Server */
#include "cellwire.h"
char *config_path = NULL;
extern char g_compile_time[];
static void show_version()
@ -59,7 +58,7 @@ static int check_signal(int signum)
}
default:
{
d_error("Unknown Signal Number = %d\n", signum);
d_error("Unknown signal number = %d\n", signum);
break;
}
@ -67,36 +66,20 @@ static int check_signal(int signum)
return 0;
}
void logger_signal(int signum)
{
switch (signum)
{
case SIGTERM:
case SIGINT:
logger_stop();
break;
default:
break;
}
}
int main(int argc, char *argv[])
{
int opt;
int opt_daemon = 0;
int opt_logger = 0;
char *log_path = NULL;
/**************************************************************************
* Starting up process.
*
* Keep the order of starting-up
*/
char *config_path = NULL;
char *log_path = NULL;
while (1)
{
opt = getopt (argc, argv, "vhdf:l:");
int opt = getopt (argc, argv, "vhdf:l:");
if (opt == -1)
break;
@ -109,13 +92,27 @@ int main(int argc, char *argv[])
show_help();
return EXIT_SUCCESS;
case 'd':
opt_daemon = 1;
{
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);
break;
}
case 'f':
config_path = optarg;
break;
case 'l':
opt_logger = 1;
log_path = optarg;
break;
default:
@ -124,49 +121,6 @@ int main(int argc, char *argv[])
}
}
core_initialize();
if (opt_daemon)
{
pid_t pid;
pid = fork();
d_assert(pid != -1, return EXIT_FAILURE, "fork() failed");
if (pid != 0)
{
/* Parent */
return EXIT_SUCCESS;
}
/* Child */
setsid();
umask(027);
}
if (opt_logger)
{
pid_t pid;
pid = fork();
d_assert(pid != -1, return EXIT_FAILURE, "fork() failed");
if (pid == 0)
{
/* Child */
setsid();
umask(027);
core_signal(SIGINT, logger_signal);
core_signal(SIGTERM, logger_signal);
logger_start(log_path);
return EXIT_SUCCESS;
}
/* Parent */
}
{
extern int _mme_sm;
extern int _enb_s1_sm;
@ -177,7 +131,10 @@ int main(int argc, char *argv[])
d_trace_level(&_s1ap_path, 100);
}
signal_init();
core_initialize();
if (log_path)
logger_start(optarg);
if (cellwire_initialize(config_path) != CORE_OK)
{

View File

@ -16,7 +16,6 @@
#include "core.h"
#include "core_debug.h"
#include "core_signal.h"
#include "cellwire.h"
#include "context.h"
@ -41,9 +40,9 @@ void core_assert_ok(abts_case* tc, const char* context, status_t rv,
void test_terminate(void)
{
threads_stop();
d_msg_to(D_MSG_TO_STDOUT, 1);
d_msg_to(D_MSG_TO_STDOUT, 1);
core_terminate();
cellwire_terminate();
}
@ -51,7 +50,6 @@ void test_terminate(void)
void test_initialize(void)
{
core_initialize();
signal_init();
cellwire_initialize(NULL);
threads_start();