Support relative conf-path
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#define DEFAULT_DNS_CACHE_SIZE 512
|
||||
|
||||
@@ -999,10 +1000,21 @@ static int _conf_printf(const char *file, int lineno, int ret)
|
||||
|
||||
int config_addtional_file(void *data, int argc, char *argv[])
|
||||
{
|
||||
char *file_path = argv[1];
|
||||
char *conf_file = argv[1];
|
||||
char file_path[DNS_MAX_PATH];
|
||||
char file_path_dir[DNS_MAX_PATH];
|
||||
|
||||
if (conf_file[0] != '/') {
|
||||
strncpy(file_path_dir, conf_get_conf_file(), DNS_MAX_PATH);
|
||||
dirname(file_path_dir);
|
||||
snprintf(file_path, DNS_MAX_PATH, "%s/%s", file_path_dir, conf_file);
|
||||
} else {
|
||||
strncpy(file_path, conf_file, DNS_MAX_PATH);
|
||||
}
|
||||
|
||||
if (access(file_path, R_OK) != 0) {
|
||||
tlog(TLOG_WARN, "conf file %s is not readable.", file_path);
|
||||
syslog(LOG_NOTICE, "conf file %s is not readable.", file_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,4 +118,6 @@ int load_conf(const char *file, struct config_item items[], conf_error_handler h
|
||||
|
||||
void load_exit(void);
|
||||
|
||||
const char *conf_get_conf_file(void);
|
||||
|
||||
#endif // !_GENERIC_CONF_H
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char *currrent_conf_file = NULL;
|
||||
|
||||
const char *conf_get_conf_file(void)
|
||||
{
|
||||
return currrent_conf_file;
|
||||
}
|
||||
|
||||
int conf_custom(const char *item, void *data, int argc, char *argv[])
|
||||
{
|
||||
struct config_item_custom *item_custom = data;
|
||||
@@ -255,6 +262,7 @@ int load_conf_file(const char *file, struct config_item *items, conf_error_handl
|
||||
|
||||
conf_getopt_reset();
|
||||
/* call item function */
|
||||
currrent_conf_file = file;
|
||||
call_ret = items[i].item_func(items[i].item, items[i].data, argc, argv);
|
||||
ret = handler(file, line_no, call_ret);
|
||||
if (ret != 0) {
|
||||
|
||||
Reference in New Issue
Block a user