log: enable output log to console when run as daemon.

This commit is contained in:
Nick Peng
2023-06-16 21:57:39 +08:00
parent a6e5ceb675
commit 8a9a11d6d9
3 changed files with 16 additions and 14 deletions

View File

@@ -855,7 +855,7 @@ int main(int argc, char *argv[])
} }
if (daemon_ret > 0) { if (daemon_ret > 0) {
ret = daemon_kickoff(daemon_ret, 0); ret = daemon_kickoff(daemon_ret, 0, dns_conf_log_console | verbose_screen);
if (ret != 0) { if (ret != 0) {
goto errout; goto errout;
} }
@@ -867,7 +867,7 @@ int main(int argc, char *argv[])
return ret; return ret;
errout: errout:
if (daemon_ret > 0) { if (daemon_ret > 0) {
daemon_kickoff(daemon_ret, ret); daemon_kickoff(daemon_ret, ret, dns_conf_log_console | verbose_screen);
} }
smartdns_test_notify(2); smartdns_test_notify(2);
return 1; return 1;

View File

@@ -1560,7 +1560,7 @@ errout:
return; return;
} }
int daemon_kickoff(int fd, int status) int daemon_kickoff(int fd, int status, int no_close)
{ {
if (fd <= 0) { if (fd <= 0) {
return -1; return -1;
@@ -1571,6 +1571,7 @@ int daemon_kickoff(int fd, int status)
return -1; return -1;
} }
if (no_close == 0) {
int fd_null = open("/dev/null", O_RDWR); int fd_null = open("/dev/null", O_RDWR);
if (fd_null < 0) { if (fd_null < 0) {
fprintf(stderr, "open /dev/null failed, %s\n", strerror(errno)); fprintf(stderr, "open /dev/null failed, %s\n", strerror(errno));
@@ -1584,6 +1585,7 @@ int daemon_kickoff(int fd, int status)
if (fd_null > 2) { if (fd_null > 2) {
close(fd_null); close(fd_null);
} }
}
close(fd); close(fd);

View File

@@ -144,7 +144,7 @@ void close_all_fd(int keepfd);
int run_daemon(void); int run_daemon(void);
int daemon_kickoff(int fd, int status); int daemon_kickoff(int fd, int status, int no_close);
int write_file(const char *filename, void *data, int data_len); int write_file(const char *filename, void *data, int data_len);