fix: daemonize before zlog initialization

This commit is contained in:
eeff
2022-08-23 15:51:37 +08:00
parent 00a55af7da
commit 6beffed3e6
3 changed files with 8 additions and 7 deletions
+1 -7
View File
@@ -101,7 +101,6 @@ static inline size_t parse_restart_policy(const char *s, size_t *out)
void neu_cli_args_init(neu_cli_args_t *args, int argc, char *argv[])
{
char * opts = "c:dh";
bool dev_log = false;
struct option long_options[] = {
{ "help", no_argument, NULL, 1 },
{ "daemon", no_argument, NULL, 'd' },
@@ -129,8 +128,7 @@ void neu_cli_args_init(neu_cli_args_t *args, int argc, char *argv[])
usage();
goto quit;
case 'l':
zlog_init("./config/dev.conf");
dev_log = true;
args->dev_log = true;
break;
case 'r':
if (0 != parse_restart_policy(optarg, &args->restart)) {
@@ -155,10 +153,6 @@ void neu_cli_args_init(neu_cli_args_t *args, int argc, char *argv[])
}
}
if (!dev_log) {
zlog_init("./config/zlog.conf");
}
if (!args->daemonized && args->restart != NEU_RESTART_NEVER) {
fprintf(stderr,
"%s: option '--restart' has no effects without '--daemon'\n",
+1
View File
@@ -37,6 +37,7 @@ extern "C" {
*/
typedef struct {
bool daemonized; // flag indicating whether to run as daemon process
bool dev_log; // logging for development
size_t restart; // restart policy
bool disable_auth;
} neu_cli_args_t;
+6
View File
@@ -85,6 +85,12 @@ int main(int argc, char *argv[])
// become a daemon, this should be before calling `init`
daemonize();
}
if (args.dev_log) {
zlog_init("./config/dev.conf");
} else {
zlog_init("./config/zlog.conf");
}
neuron = zlog_get_category("neuron");
if (neuron_already_running()) {