summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.com>2016-12-06 13:11:06 -0500
committerSteve Dickson <steved@redhat.com>2016-12-20 13:29:04 -0500
commit08c6be49aa7261c2beff099687a6186a6596b1f5 (patch)
tree99441874636be69cb73e69bc403d71a7831babc4
parent8a051f2eefa9eeb034ffbff567b645c367d4a4e4 (diff)
downloadnfs-utils-08c6be49aa7261c2beff099687a6186a6596b1f5.tar.gz
nfs-utils-08c6be49aa7261c2beff099687a6186a6596b1f5.tar.xz
nfs-utils-08c6be49aa7261c2beff099687a6186a6596b1f5.zip
conffile: split loading of file into a separate function.
This will make support of include files easier. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Steve Dickson <steved@redhat.com>
-rw-r--r--support/nfs/conffile.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
index e459750..965726c 100644
--- a/support/nfs/conffile.c
+++ b/support/nfs/conffile.c
@@ -366,23 +366,18 @@ conf_init (void)
conf_reinit();
}
-/* Open the config file and map it into our address space, then parse it. */
-void
-conf_reinit(void)
+static int
+conf_load(int trans, char *path)
{
- struct conf_binding *cb = 0;
- int fd, trans;
- unsigned int i;
- size_t sz;
- char *new_conf_addr = 0;
struct stat sb;
+ if ((stat (path, &sb) == 0) || (errno != ENOENT)) {
+ char *new_conf_addr;
+ size_t sz = sb.st_size;
+ int fd = open (path, O_RDONLY, 0);
- if ((stat (conf_path, &sb) == 0) || (errno != ENOENT)) {
- sz = sb.st_size;
- fd = open (conf_path, O_RDONLY, 0);
if (fd == -1) {
- xlog_warn("conf_reinit: open (\"%s\", O_RDONLY) failed", conf_path);
- return;
+ xlog_warn("conf_reinit: open (\"%s\", O_RDONLY) failed", path);
+ return -1;
}
new_conf_addr = malloc(sz);
@@ -399,13 +394,28 @@ conf_reinit(void)
}
close(fd);
- trans = conf_begin();
/* XXX Should we not care about errors and rollback? */
conf_parse(trans, new_conf_addr, sz);
free(new_conf_addr);
+ return 0;
+ fail:
+ close(fd);
+ free(new_conf_addr);
}
- else
- trans = conf_begin();
+ return -1;
+}
+
+/* Open the config file and map it into our address space, then parse it. */
+void
+conf_reinit(void)
+{
+ struct conf_binding *cb = 0;
+ int trans;
+ unsigned int i;
+
+ trans = conf_begin();
+ if (conf_load(trans, conf_path) < 0)
+ return;
/* Load default configuration values. */
conf_load_defaults();
@@ -419,11 +429,6 @@ conf_reinit(void)
conf_end(trans, 1);
return;
-
-fail:
- if (new_conf_addr)
- free(new_conf_addr);
- close (fd);
}
/*