smartdns: support multiline config option and fix timer issue.

This commit is contained in:
Nick Peng
2023-02-02 20:23:53 +08:00
parent 108f514b83
commit 03ba24480b
6 changed files with 28 additions and 12 deletions

View File

@@ -3862,10 +3862,12 @@ static void *_dns_client_work(void *arg)
sleep_time = 0;
}
}
last = now;
if (now >= expect_time) {
_dns_client_period_run();
if (last != now) {
_dns_client_period_run();
}
sleep_time = sleep - (now - expect_time);
if (sleep_time < 0) {
sleep_time = 0;
@@ -3873,6 +3875,7 @@ static void *_dns_client_work(void *arg)
}
expect_time += sleep;
}
last = now;
pthread_mutex_lock(&client.domain_map_lock);
if (list_empty(&client.dns_request_list) && atomic_read(&client.run_period) == 0) {

View File

@@ -5137,7 +5137,7 @@ static void _dns_server_period_run(unsigned int msec)
struct dns_request *tmp = NULL;
LIST_HEAD(check_list);
if (msec % 10 == 0) {
if ((msec % 10) == 0) {
_dns_server_period_run_second();
}
@@ -5227,11 +5227,12 @@ int dns_server_run(void)
expect_time -= cnt * sleep;
sleep_time -= cnt * sleep;
}
last = now;
if (now >= expect_time) {
msec++;
_dns_server_period_run(msec);
if (last != now) {
_dns_server_period_run(msec);
}
sleep_time = sleep - (now - expect_time);
if (sleep_time < 0) {
sleep_time = 0;
@@ -5250,6 +5251,7 @@ int dns_server_run(void)
pthread_mutex_unlock(&server.request_list_lock);
expect_time += sleep;
}
last = now;
num = epoll_wait(server.epoll_fd, events, DNS_MAX_EVENTS, sleep_time);
if (num < 0) {

View File

@@ -1780,10 +1780,11 @@ static void *_fast_ping_work(void *arg)
sleep_time = 0;
}
}
last = now;
if (now >= expect_time) {
_fast_ping_period_run();
if (last != now) {
_fast_ping_period_run();
}
sleep_time = sleep - (now - expect_time);
if (sleep_time < 0) {
sleep_time = 0;
@@ -1791,6 +1792,7 @@ static void *_fast_ping_work(void *arg)
}
expect_time += sleep;
}
last = now;
pthread_mutex_lock(&ping.map_lock);
if (hash_empty(ping.addrmap)) {

View File

@@ -21,7 +21,7 @@
#include <unistd.h>
#define MAX_LINE_LEN 1024
#define MAX_LINE_LEN 8192
#define MAX_KEY_LEN 64
#define CONF_INT_MAX (~(1 << 31))
#define CONF_INT_MIN (1 << 31)

View File

@@ -299,7 +299,7 @@ static int load_conf_printf(const char *file, int lineno, int ret)
static int load_conf_file(const char *file, struct config_item *items, conf_error_handler handler)
{
FILE *fp = NULL;
char line[MAX_LINE_LEN];
char line[MAX_LINE_LEN + MAX_KEY_LEN];
char key[MAX_KEY_LEN];
char value[MAX_LINE_LEN];
int filed_num = 0;
@@ -309,6 +309,8 @@ static int load_conf_file(const char *file, struct config_item *items, conf_erro
int ret = 0;
int call_ret = 0;
int line_no = 0;
int line_len = 0;
int read_len = 0;
if (handler == NULL) {
handler = load_conf_printf;
@@ -320,9 +322,17 @@ static int load_conf_file(const char *file, struct config_item *items, conf_erro
}
line_no = 0;
while (fgets(line, MAX_LINE_LEN, fp)) {
while (fgets(line + line_len, MAX_LINE_LEN - line_len, fp)) {
line_no++;
filed_num = sscanf(line, "%63s %1023[^\r\n]s", key, value);
read_len = strnlen(line + line_len, sizeof(line));
if (read_len >= 2 && *(line + line_len + read_len - 2) == '\\') {
line_len += read_len - 2;
line[line_len] = '\0';
continue;
}
line_len = 0;
filed_num = sscanf(line, "%63s %8192[^\r\n]s", key, value);
if (filed_num <= 0) {
continue;
}

View File

@@ -45,7 +45,6 @@
#include <sys/types.h>
#include <ucontext.h>
#define MAX_LINE_LEN 1024
#define MAX_KEY_LEN 64
#define SMARTDNS_PID_FILE "/var/run/smartdns.pid"
#define TMP_BUFF_LEN_32 32