Skip to content

Commit

Permalink
fix log file redirect
Browse files Browse the repository at this point in the history
When running as a daemon it will close stdout/stderr,
so the log file fd should be dup after the daemon succeeds
  • Loading branch information
findstr committed Jul 26, 2024
1 parent 990e850 commit 1c1b318
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 4 additions & 0 deletions silly-src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <lauxlib.h>
#include <string.h>
#include "silly.h"
#include "silly_daemon.h"
#include "silly_trace.h"
#include "silly_log.h"
#include "silly_timer.h"
Expand Down Expand Up @@ -145,6 +146,7 @@ int main(int argc, char *argv[])
{
int status;
struct silly_config config;
memset(&config, 0, sizeof(config));
config.argc = argc;
config.argv = argv;
config.selfpath = argv[0];
Expand All @@ -156,9 +158,11 @@ int main(int argc, char *argv[])
strncpy(config.bootstrap, argv[1], ARRAY_SIZE(config.bootstrap) - 1);
parse_args(&config, argc, argv);
silly_trace_init();
silly_daemon_start(&config);
silly_log_init(&config);
silly_timer_init();
status = silly_run(&config);
silly_daemon_stop(&config);
silly_log_info("%s exit, leak memory size:%zu\n",
argv[0], silly_memused());
silly_log_flush();
Expand Down
6 changes: 1 addition & 5 deletions silly-src/silly_run.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "silly_worker.h"
#include "silly_monitor.h"
#include "silly_signal.h"
#include "silly_daemon.h"

#include "silly_run.h"

Expand Down Expand Up @@ -147,13 +146,11 @@ silly_run(const struct silly_config *config)
R.exitstatus = 0;
pthread_mutex_init(&R.mutex, NULL);
pthread_cond_init(&R.cond, NULL);
silly_daemon_start(config);
silly_signal_init();
err = silly_socket_init();
if (unlikely(err < 0)) {
silly_log_error("%s socket init fail:%d\n", config->selfname, err);
silly_daemon_stop(config);
exit(-1);
return -err;
}
silly_worker_init();
silly_monitor_init();
Expand All @@ -168,7 +165,6 @@ silly_run(const struct silly_config *config)
for (i = 0; i < 3; i++)
pthread_join(pid[i], NULL);
silly_log_flush();
silly_daemon_stop(config);
pthread_mutex_destroy(&R.mutex);
pthread_cond_destroy(&R.cond);
silly_worker_exit();
Expand Down

0 comments on commit 1c1b318

Please sign in to comment.