dns_conf: support relative path for dnsmasq-lease-file
This commit is contained in:
@@ -1750,8 +1750,8 @@ static int _conf_dhcp_lease_dnsmasq_file(void *data, int argc, char *argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_strncpy(dns_conf_dnsmasq_lease_file, argv[1], DNS_MAX_PATH);
|
conf_get_conf_fullpath(argv[1], dns_conf_dnsmasq_lease_file, sizeof(dns_conf_dnsmasq_lease_file));
|
||||||
if (_conf_dhcp_lease_dnsmasq_add(argv[1]) != 0) {
|
if (_conf_dhcp_lease_dnsmasq_add(dns_conf_dnsmasq_lease_file) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,4 +160,6 @@ void load_exit(void);
|
|||||||
|
|
||||||
const char *conf_get_conf_file(void);
|
const char *conf_get_conf_file(void);
|
||||||
|
|
||||||
|
const char *conf_get_conf_fullpath(const char *path, char *fullpath, size_t path_len);
|
||||||
|
|
||||||
#endif // !_GENERIC_CONF_H
|
#endif // !_GENERIC_CONF_H
|
||||||
|
|||||||
@@ -18,16 +18,46 @@
|
|||||||
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static const char *currrent_conf_file = NULL;
|
static const char *current_conf_file = NULL;
|
||||||
|
|
||||||
const char *conf_get_conf_file(void)
|
const char *conf_get_conf_file(void)
|
||||||
{
|
{
|
||||||
return currrent_conf_file;
|
return current_conf_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *conf_get_conf_fullpath(const char *path, char *fullpath, size_t path_len)
|
||||||
|
{
|
||||||
|
char file_path_dir[PATH_MAX];
|
||||||
|
|
||||||
|
if (path_len < 1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path[0] == '/') {
|
||||||
|
strncpy(fullpath, path, path_len);
|
||||||
|
return fullpath;
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(file_path_dir, conf_get_conf_file(), PATH_MAX - 1);
|
||||||
|
file_path_dir[PATH_MAX - 1] = 0;
|
||||||
|
dirname(file_path_dir);
|
||||||
|
if (file_path_dir[0] == '\0') {
|
||||||
|
strncpy(fullpath, path, path_len);
|
||||||
|
return fullpath;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (snprintf(fullpath, PATH_MAX, "%s/%s", file_path_dir, path) < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fullpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
int conf_custom(const char *item, void *data, int argc, char *argv[])
|
int conf_custom(const char *item, void *data, int argc, char *argv[])
|
||||||
@@ -303,7 +333,7 @@ static int load_conf_file(const char *file, struct config_item *items, conf_erro
|
|||||||
|
|
||||||
conf_getopt_reset();
|
conf_getopt_reset();
|
||||||
/* call item function */
|
/* call item function */
|
||||||
currrent_conf_file = file;
|
current_conf_file = file;
|
||||||
call_ret = items[i].item_func(items[i].item, items[i].data, argc, argv);
|
call_ret = items[i].item_func(items[i].item, items[i].data, argc, argv);
|
||||||
ret = handler(file, line_no, call_ret);
|
ret = handler(file, line_no, call_ret);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user