conf: optimize badconfig log

This commit is contained in:
Nick Peng
2022-07-07 22:49:30 +08:00
parent 7d62226995
commit 4e2161c6fc
5 changed files with 17 additions and 12 deletions

View File

@@ -1917,14 +1917,16 @@ static struct config_item _config_item[] = {
static int _conf_printf(const char *file, int lineno, int ret) static int _conf_printf(const char *file, int lineno, int ret)
{ {
if (ret == CONF_RET_ERR) { switch (ret) {
tlog(TLOG_ERROR, "process config file '%s' failed at line %d.", file, lineno); case CONF_RET_ERR:
syslog(LOG_NOTICE, "process config file '%s' failed at line %d.", file, lineno); case CONF_RET_WARN:
return -1; case CONF_RET_BADCONF:
} else if (ret == CONF_RET_WARN) {
tlog(TLOG_WARN, "process config file '%s' failed at line %d.", file, lineno); tlog(TLOG_WARN, "process config file '%s' failed at line %d.", file, lineno);
syslog(LOG_NOTICE, "process config file '%s' failed at line %d.", file, lineno); syslog(LOG_NOTICE, "process config file '%s' failed at line %d.", file, lineno);
return -1; return -1;
break;
default:
break;
} }
return 0; return 0;

View File

@@ -30,6 +30,7 @@
#define CONF_RET_ERR -1 #define CONF_RET_ERR -1
#define CONF_RET_WARN -2 #define CONF_RET_WARN -2
#define CONF_RET_NOENT -3 #define CONF_RET_NOENT -3
#define CONF_RET_BADCONF -4
struct config_item { struct config_item {
const char *item; const char *item;

View File

@@ -262,6 +262,7 @@ int load_conf_file(const char *file, struct config_item *items, conf_error_handl
/* if field format is not key = value, error */ /* if field format is not key = value, error */
if (filed_num != 2) { if (filed_num != 2) {
handler(file, line_no, CONF_RET_BADCONF);
goto errout; goto errout;
} }

View File

@@ -506,6 +506,11 @@ int main(int argc, char *argv[])
} }
} }
if (dns_server_load_conf(config_file) != 0) {
fprintf(stderr, "load config failed.\n");
goto errout;
}
if (is_forground == 0) { if (is_forground == 0) {
if (daemon(0, 0) < 0) { if (daemon(0, 0) < 0) {
fprintf(stderr, "run daemon process failed, %s\n", strerror(errno)); fprintf(stderr, "run daemon process failed, %s\n", strerror(errno));
@@ -522,10 +527,8 @@ int main(int argc, char *argv[])
} }
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
if (dns_server_load_conf(config_file) != 0) { signal(SIGINT, _sig_exit);
fprintf(stderr, "load config failed.\n"); signal(SIGTERM, _sig_exit);
goto errout;
}
drop_root_privilege(); drop_root_privilege();
@@ -535,8 +538,6 @@ int main(int argc, char *argv[])
goto errout; goto errout;
} }
signal(SIGINT, _sig_exit);
signal(SIGTERM, _sig_exit);
atexit(_smartdns_exit); atexit(_smartdns_exit);
return _smartdns_run(); return _smartdns_run();

View File

@@ -77,7 +77,7 @@
#define NETLINK_ALIGN(len) (((len) + 3) & ~(3)) #define NETLINK_ALIGN(len) (((len) + 3) & ~(3))
#define BUFF_SZ 256 #define BUFF_SZ 1024
struct ipset_netlink_attr { struct ipset_netlink_attr {
unsigned short len; unsigned short len;