forked from acouzens/open5gs
PID command line option(-p) is added
This commit is contained in:
parent
8c289c6d6e
commit
a0eb08a2fa
|
@ -13,7 +13,7 @@ extern "C" {
|
|||
#define MAX_NUM_OF_CONFIG_TOKEN 256
|
||||
|
||||
typedef struct _config_t {
|
||||
char *path;
|
||||
const char *path;
|
||||
char json[MAX_CONFIG_FILE_SIZE+1];
|
||||
jsmntok_t token[MAX_NUM_OF_CONFIG_TOKEN];
|
||||
void *bson;
|
||||
|
@ -30,6 +30,7 @@ typedef struct _context_t {
|
|||
void *database;
|
||||
|
||||
struct {
|
||||
const char *path;
|
||||
int console;
|
||||
const char *syslog;
|
||||
struct {
|
||||
|
|
11
main.c
11
main.c
|
@ -30,7 +30,8 @@ static void show_help(const char *name)
|
|||
" -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"
|
||||
" -l log_file Log file path to be logged to\n"
|
||||
" -p pid_file PID file path\n"
|
||||
"\n", name);
|
||||
}
|
||||
|
||||
|
@ -81,10 +82,11 @@ int main(int argc, char *argv[])
|
|||
*/
|
||||
char *config_path = NULL;
|
||||
char *log_path = NULL;
|
||||
char *pid_path = NULL;
|
||||
|
||||
while (1)
|
||||
{
|
||||
int opt = getopt (argc, argv, "vhdf:l:");
|
||||
int opt = getopt (argc, argv, "vhdf:l:p:");
|
||||
if (opt == -1)
|
||||
break;
|
||||
|
||||
|
@ -120,6 +122,9 @@ int main(int argc, char *argv[])
|
|||
case 'l':
|
||||
log_path = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
pid_path = optarg;
|
||||
break;
|
||||
default:
|
||||
show_help(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -132,7 +137,7 @@ int main(int argc, char *argv[])
|
|||
atexit(terminate);
|
||||
|
||||
core_initialize();
|
||||
app_log_pid(app_name);
|
||||
app_log_pid(pid_path);
|
||||
if (app_initialize(config_path, log_path) != CORE_OK)
|
||||
{
|
||||
d_fatal("NextEPC initialization failed. Aborted");
|
||||
|
|
12
src/app.h
12
src/app.h
|
@ -10,19 +10,21 @@ extern "C" {
|
|||
|
||||
extern const char *app_name;
|
||||
|
||||
CORE_DECLARE(status_t) app_initialize(char *config_path, char *log_path);
|
||||
CORE_DECLARE(status_t) app_initialize(
|
||||
const char *config_path, const char *log_path);
|
||||
CORE_DECLARE(void) app_terminate(void);
|
||||
|
||||
CORE_DECLARE(status_t) app_will_initialize(char *config_path, char *log_path);
|
||||
CORE_DECLARE(status_t) app_did_initialize(char *config_path, char *log_path);
|
||||
CORE_DECLARE(status_t) app_will_initialize(
|
||||
const char *config_path, const char *log_path);
|
||||
CORE_DECLARE(status_t) app_did_initialize(void);
|
||||
CORE_DECLARE(void) app_will_terminate(void);
|
||||
CORE_DECLARE(void) app_did_terminate(void);
|
||||
|
||||
CORE_DECLARE(status_t) config_initialize(char *config_path);
|
||||
CORE_DECLARE(status_t) config_initialize(const char *config_path);
|
||||
CORE_DECLARE(void) config_terminate(void);
|
||||
|
||||
CORE_DECLARE(status_t) app_logger_restart(void);
|
||||
CORE_DECLARE(status_t) app_log_pid(const char *file);
|
||||
CORE_DECLARE(status_t) app_log_pid(const char *pid_path);
|
||||
|
||||
CORE_DECLARE(status_t) mme_initialize();
|
||||
CORE_DECLARE(void) mme_terminate(void);
|
||||
|
|
|
@ -21,7 +21,7 @@ static semaphore_id hss_sem2 = 0;
|
|||
|
||||
const char *app_name = "epc";
|
||||
|
||||
status_t app_initialize(char *config_path, char *log_path)
|
||||
status_t app_initialize(const char *config_path, const char *log_path)
|
||||
{
|
||||
pid_t pid;
|
||||
status_t rv;
|
||||
|
@ -228,7 +228,7 @@ status_t app_initialize(char *config_path, char *log_path)
|
|||
if (hss_sem1) semaphore_wait(hss_sem1);
|
||||
}
|
||||
|
||||
rv = app_did_initialize(config_path, log_path);
|
||||
rv = app_did_initialize();
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
d_trace(1, "MME try to initialize\n");
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
const char *app_name = "hss";
|
||||
|
||||
status_t app_initialize(char *config_path, char *log_path)
|
||||
status_t app_initialize(const char *config_path, const char *log_path)
|
||||
{
|
||||
status_t rv;
|
||||
int others = 0;
|
||||
|
@ -28,7 +28,7 @@ status_t app_initialize(char *config_path, char *log_path)
|
|||
d_assert(rv == CORE_OK, return rv, "Failed to intialize HSS");
|
||||
d_trace(1, "HSS initialize...done\n");
|
||||
|
||||
rv = app_did_initialize(config_path, log_path);
|
||||
rv = app_did_initialize();
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
return CORE_OK;
|
||||
|
|
44
src/init.c
44
src/init.c
|
@ -8,15 +8,15 @@
|
|||
|
||||
#include "app.h"
|
||||
|
||||
#define DEFAULT_RUNTIME_DIR_PATH LOCALSTATE_DIR "run/"
|
||||
#define DEFAULT_CONFIG_FILE_PATH SYSCONF_DIR PACKAGE "/nextepc.conf"
|
||||
#define DEFAULT_RUNTIME_DIR_PATH LOCALSTATE_DIR "run/"
|
||||
|
||||
static status_t app_logger_init();
|
||||
static status_t app_logger_final();
|
||||
static status_t app_logger_start();
|
||||
static status_t app_logger_stop();
|
||||
|
||||
status_t app_will_initialize(char *config_path, char *log_path)
|
||||
status_t app_will_initialize(const char *config_path, const char *log_path)
|
||||
{
|
||||
status_t rv;
|
||||
int others = 0;
|
||||
|
@ -39,6 +39,7 @@ status_t app_will_initialize(char *config_path, char *log_path)
|
|||
d_trace_level(&_app_init, others);
|
||||
}
|
||||
|
||||
context_self()->log.path = log_path;
|
||||
rv = app_logger_init();
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
|
@ -51,7 +52,7 @@ status_t app_will_initialize(char *config_path, char *log_path)
|
|||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t app_did_initialize(char *config_path, char *log_path)
|
||||
status_t app_did_initialize(void)
|
||||
{
|
||||
status_t rv = app_logger_start();
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
@ -76,33 +77,36 @@ void app_did_terminate(void)
|
|||
context_final();
|
||||
}
|
||||
|
||||
status_t app_log_pid(const char *name)
|
||||
status_t app_log_pid(const char *pid_path)
|
||||
{
|
||||
file_t *pid_file = NULL;
|
||||
file_info_t finfo;
|
||||
static pid_t saved_pid = -1;
|
||||
pid_t mypid;
|
||||
status_t rv;
|
||||
char fname[MAX_FILEPATH_LEN];
|
||||
char default_pid_path[MAX_FILEPATH_LEN];
|
||||
char buf[128];
|
||||
|
||||
d_assert(name, return CORE_ERROR, );
|
||||
|
||||
snprintf(fname, sizeof(fname), "%snextepc-%sd/pid",
|
||||
DEFAULT_RUNTIME_DIR_PATH, name);
|
||||
mypid = getpid();
|
||||
if (mypid != saved_pid
|
||||
&& file_stat(&finfo, fname, FILE_INFO_MTIME) == CORE_OK)
|
||||
if (pid_path == NULL)
|
||||
{
|
||||
d_warn("pid file %s overwritten -- Unclean "
|
||||
"shutdown of previous NextEPC run?", fname);
|
||||
snprintf(default_pid_path, sizeof(default_pid_path),
|
||||
"%snextepc-%sd/pid", DEFAULT_RUNTIME_DIR_PATH, app_name);
|
||||
pid_path = default_pid_path;
|
||||
}
|
||||
|
||||
if ((rv = file_open(&pid_file, fname,
|
||||
mypid = getpid();
|
||||
if (mypid != saved_pid
|
||||
&& file_stat(&finfo, pid_path, FILE_INFO_MTIME) == CORE_OK)
|
||||
{
|
||||
d_warn("pid file %s overwritten -- Unclean "
|
||||
"shutdown of previous NextEPC run?", pid_path);
|
||||
}
|
||||
|
||||
if ((rv = file_open(&pid_file, pid_path,
|
||||
FILE_WRITE | FILE_CREATE | FILE_TRUNCATE,
|
||||
FILE_UREAD | FILE_UWRITE | FILE_GREAD | FILE_WREAD)) != CORE_OK)
|
||||
{
|
||||
d_error("could not create %s", fname);
|
||||
d_error("could not create %s", pid_path);
|
||||
return CORE_ERROR;
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "%" C_PID_T_FMT "\r\n", mypid);
|
||||
|
@ -110,6 +114,8 @@ status_t app_log_pid(const char *name)
|
|||
file_close(pid_file);
|
||||
saved_pid = mypid;
|
||||
|
||||
d_print(" PID[%" C_PID_T_FMT "] : '%s'\n", saved_pid, pid_path);
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
|
@ -147,6 +153,9 @@ static status_t app_logger_init()
|
|||
if (context_self()->log.socket.file &&
|
||||
context_self()->log.socket.unix_domain)
|
||||
{
|
||||
if (context_self()->log.path)
|
||||
context_self()->log.socket.file = context_self()->log.path;
|
||||
|
||||
rv = d_msg_socket_init(context_self()->log.socket.unix_domain);
|
||||
if (rv != CORE_OK)
|
||||
{
|
||||
|
@ -161,6 +170,9 @@ static status_t app_logger_init()
|
|||
}
|
||||
if (context_self()->log.file)
|
||||
{
|
||||
if (context_self()->log.path)
|
||||
context_self()->log.file = context_self()->log.path;
|
||||
|
||||
rv = d_msg_file_init(context_self()->log.file);
|
||||
if (rv != CORE_OK)
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
const char *app_name = "mme";
|
||||
|
||||
status_t app_initialize(char *config_path, char *log_path)
|
||||
status_t app_initialize(const char *config_path, const char *log_path)
|
||||
{
|
||||
status_t rv;
|
||||
int others = 0;
|
||||
|
@ -28,7 +28,7 @@ status_t app_initialize(char *config_path, char *log_path)
|
|||
d_assert(rv == CORE_OK, return rv, "Failed to intialize MME");
|
||||
d_trace(1, "MME initialize...done\n");
|
||||
|
||||
rv = app_did_initialize(config_path, log_path);
|
||||
rv = app_did_initialize();
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
return CORE_OK;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
const char *app_name = "pcrf";
|
||||
|
||||
status_t app_initialize(char *config_path, char *log_path)
|
||||
status_t app_initialize(const char *config_path, const char *log_path)
|
||||
{
|
||||
status_t rv;
|
||||
int others = 0;
|
||||
|
@ -28,7 +28,7 @@ status_t app_initialize(char *config_path, char *log_path)
|
|||
d_assert(rv == CORE_OK, return rv, "Failed to intialize PCRF");
|
||||
d_trace(1, "PCRF initialize...done\n");
|
||||
|
||||
rv = app_did_initialize(config_path, log_path);
|
||||
rv = app_did_initialize();
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
return CORE_OK;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
const char *app_name = "pgw";
|
||||
|
||||
status_t app_initialize(char *config_path, char *log_path)
|
||||
status_t app_initialize(const char *config_path, const char *log_path)
|
||||
{
|
||||
status_t rv;
|
||||
int others = 0;
|
||||
|
@ -28,7 +28,7 @@ status_t app_initialize(char *config_path, char *log_path)
|
|||
d_assert(rv == CORE_OK, return rv, "Failed to intialize PGW");
|
||||
d_trace(1, "PGW initialize...done\n");
|
||||
|
||||
rv = app_did_initialize(config_path, log_path);
|
||||
rv = app_did_initialize();
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
return CORE_OK;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
const char *app_name = "sgw";
|
||||
|
||||
status_t app_initialize(char *config_path, char *log_path)
|
||||
status_t app_initialize(const char *config_path, const char *log_path)
|
||||
{
|
||||
status_t rv;
|
||||
int others = 0;
|
||||
|
@ -28,7 +28,7 @@ status_t app_initialize(char *config_path, char *log_path)
|
|||
d_assert(rv == CORE_OK, return rv, "Failed to intialize SGW");
|
||||
d_trace(1, "SGW initialize...done\n");
|
||||
|
||||
rv = app_did_initialize(config_path, log_path);
|
||||
rv = app_did_initialize();
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
return CORE_OK;
|
||||
|
|
Loading…
Reference in New Issue