[augeas-devel] [PATCH 1/8] Keep a dummy struct info in struct error for convenience

lutter at redhat.com lutter at redhat.com
Sat May 7 01:12:49 UTC 2011


From: David Lutterkort <lutter at redhat.com>

  * src/errcode.h (struct error): at a info member
  * src/augeas.c (aug_init): set up the struct info in struct error;
    (aug_close): free the struct info in struct error
---
 src/augeas.c  |    7 +++++++
 src/errcode.h |    4 ++++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/src/augeas.c b/src/augeas.c
index 8d6de28..9f51759 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -352,6 +352,12 @@ struct augeas *aug_init(const char *root, const char *loadpath,
         goto error;
     if (ALLOC(result->error) < 0)
         goto error;
+    if (make_ref(result->error->info) < 0)
+        goto error;
+    result->error->info->error = result->error;
+    result->error->info->filename = dup_string("(unknown file)");
+    if (result->error->info->filename == NULL)
+        goto error;
     result->error->aug = result;
 
     result->origin = make_tree_origin(tree_root);
@@ -1446,6 +1452,7 @@ void aug_close(struct augeas *aug) {
     free((void *) aug->root);
     free(aug->modpathz);
     free_symtab(aug->symtab);
+    unref(aug->error->info, info);
     free(aug->error->details);
     free(aug->error);
     free(aug);
diff --git a/src/errcode.h b/src/errcode.h
index cef33e4..d700ce5 100644
--- a/src/errcode.h
+++ b/src/errcode.h
@@ -35,6 +35,10 @@ struct error {
     int            minor;
     char          *details;       /* Human readable explanation */
     const char    *minor_details; /* Human readable version of MINOR */
+    /* A dummy info of last resort; this can be used in places where
+     * a struct info is needed but none available
+     */
+    struct info   *info;
     /* Bit of a kludge to get at struct augeas, but since struct error
      * is now available in a lot of places (through struct info), this
      * gives a convenient way to get at the overall state
-- 
1.7.4.4




More information about the augeas-devel mailing list