[netcf-devel] [PATCH 4/5] initscripts driver: reload augeas on every public API call

David Lutterkort lutter at redhat.com
Thu Jul 9 22:58:14 UTC 2009


We need to reload Augeas every time a public API call is made to ensure we
are operating on the latest data from the file system.
---
 src/drv_initscripts.c |   24 +++++++++++++++++++++++-
 src/internal.h        |    2 ++
 src/netcf.c           |    2 ++
 3 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/src/drv_initscripts.c b/src/drv_initscripts.c
index 0ad9eb5..d606e03 100644
--- a/src/drv_initscripts.c
+++ b/src/drv_initscripts.c
@@ -92,6 +92,7 @@ struct driver {
     xsltStylesheetPtr  get;
     xmlRelaxNGPtr      rng;
     int                ioctl_fd;
+    unsigned int       load_augeas : 1;
 };
 
 /* Entries in a ifcfg file that tell us that the interface
@@ -114,11 +115,15 @@ static int xasprintf(char **strp, const char *format, ...) {
   return result;
 }
 
+/* Get the Augeas instance; if we already initialized it, just return
+ * it. Otherwise, create a new one and return that.
+ */
 static struct augeas *get_augeas(struct netcf *ncf) {
+    int r;
+
     if (ncf->driver->augeas == NULL) {
         struct augeas *aug;
         char *path;
-        int r;
 
         r = xasprintf(&path, "%s/lenses", ncf->data_dir);
         ERR_COND_BAIL(r < 0, ncf, ENOMEM);
@@ -151,6 +156,19 @@ static struct augeas *get_augeas(struct netcf *ncf) {
             fprintf(stderr, "please file a bug with the following lines in the bug report:\n");
             aug_print(aug, stderr, "/augeas//error");
         }
+    } else {
+        if (ncf->driver->load_augeas) {
+            struct augeas *aug = ncf->driver->augeas;
+            /* Undefine all our variables to work around bug 79 in Augeas */
+            aug_defvar(aug, "iptables", NULL);
+            aug_defvar(aug, "fw", NULL);
+            aug_defvar(aug, "fw_custom", NULL);
+            aug_defvar(aug, "ipt_filter", NULL);
+
+            r = aug_load(ncf->driver->augeas);
+            ERR_THROW(r < 0, ncf, EOTHER, "failed to reload config files");
+            ncf->driver->load_augeas = 0;
+        }
     }
     return ncf->driver->augeas;
  error:
@@ -502,6 +520,10 @@ void drv_close(struct netcf *ncf) {
     FREE(ncf->driver);
 }
 
+void drv_entry(struct netcf *ncf) {
+    ncf->driver->load_augeas = 1;
+}
+
 static int list_interface_ids(struct netcf *ncf,
                               int maxnames, char **names,
                               unsigned int flags,
diff --git a/src/internal.h b/src/internal.h
index 56c6038..d6acd55 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -152,6 +152,8 @@ void vreport_error(struct netcf *ncf, netcf_errcode_t errcode,
  */
 int drv_init(struct netcf *netcf);
 void drv_close(struct netcf *netcf);
+/* Called on every entry through the public API */
+void drv_entry(struct netcf *netcf);
 int drv_num_of_interfaces(struct netcf *ncf, unsigned int flags);
 int drv_list_interfaces(struct netcf *ncf, int maxnames, char **names, unsigned int flags);
 struct netcf_if *drv_lookup_by_name(struct netcf *ncf, const char *name);
diff --git a/src/netcf.c b/src/netcf.c
index aef8b4d..6f1214d 100644
--- a/src/netcf.c
+++ b/src/netcf.c
@@ -37,6 +37,8 @@
     do {                                        \
         (ncf)->errcode = NETCF_NOERROR;         \
         FREE((ncf)->errdetails);                \
+        if (ncf->driver != NULL)                \
+            drv_entry(ncf);                     \
     } while(0);
 
 /* Human-readable error messages. This array is indexed by NETCF_ERRCODE_T */
-- 
1.6.0.6



More information about the netcf-devel mailing list