summaryrefslogtreecommitdiffstats
path: root/sysdep
diff options
context:
space:
mode:
authorOndrej Filip <feela@network.cz>2011-09-11 21:21:47 +0200
committerOndrej Filip <feela@network.cz>2011-09-11 21:21:47 +0200
commit48ec367aabaaa5328f4072d237001e245a7363df (patch)
tree9a65d5e1b051ff6aa24cd036ff1930bcb370fb8b /sysdep
parenta98995273bd8788cf525f44479026d5ce6b7dd52 (diff)
downloadbird-48ec367aabaaa5328f4072d237001e245a7363df.tar
bird-48ec367aabaaa5328f4072d237001e245a7363df.zip
Configuration can include other files.
Diffstat (limited to 'sysdep')
-rw-r--r--sysdep/unix/main.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c
index 5547791..72f7e85 100644
--- a/sysdep/unix/main.c
+++ b/sysdep/unix/main.c
@@ -18,6 +18,7 @@
#include <pwd.h>
#include <grp.h>
#include <sys/stat.h>
+#include <libgen.h>
#include "nest/bird.h"
#include "lib/lists.h"
@@ -150,18 +151,34 @@ read_iproute_table(char *file, char *prefix, int max)
#endif // PATH_IPROUTE_DIR
-static int conf_fd;
static char *config_name = PATH_CONFIG;
static int
-cf_read(byte *dest, unsigned int len)
+cf_read(byte *dest, unsigned int len, int fd)
{
- int l = read(conf_fd, dest, len);
+ int l = read(fd, dest, len);
if (l < 0)
cf_error("Read error");
return l;
}
+static int
+cf_open(char *filename)
+{
+ char full_name[BIRD_FNAME_MAX];
+ char *cur = filename;
+ int ret;
+
+ if (*filename != '/') {
+ snprintf(full_name, sizeof(full_name), "%s/%s", dirname(config_name), filename);
+ cur = full_name;
+ }
+
+ if ((ret = open(cur, O_RDONLY)) == -1)
+ cf_error("Unable to open included configuration file: %s", cur);
+}
+
+
void
sysdep_preconfig(struct config *c)
{
@@ -189,12 +206,13 @@ unix_read_config(struct config **cp, char *name)
int ret;
*cp = conf;
- conf_fd = open(name, O_RDONLY);
- if (conf_fd < 0)
+ conf->file_fd = open(name, O_RDONLY);
+ if (conf->file_fd < 0)
return 0;
cf_read_hook = cf_read;
+ cf_open_hook = cf_open;
ret = config_parse(conf);
- close(conf_fd);
+ close(conf->file_fd);
return ret;
}
@@ -206,7 +224,7 @@ read_config(void)
if (!unix_read_config(&conf, config_name))
{
if (conf->err_msg)
- die("%s, line %d: %s", config_name, conf->err_lino, conf->err_msg);
+ die("%s, line %d: %s", conf->err_file_name, conf->err_lino, conf->err_msg);
else
die("Unable to open configuration file %s: %m", config_name);
}
@@ -222,7 +240,7 @@ async_config(void)
if (!unix_read_config(&conf, config_name))
{
if (conf->err_msg)
- log(L_ERR "%s, line %d: %s", config_name, conf->err_lino, conf->err_msg);
+ log(L_ERR "%s, line %d: %s", conf->err_file_name, conf->err_lino, conf->err_msg);
else
log(L_ERR "Unable to open configuration file %s: %m", config_name);
config_free(conf);