[Pkg-libvirt-commits] [libguestfs] 44/63: daemon: add a way to check for the version of augeas
Hilko Bengen
bengen at moszumanska.debian.org
Fri Oct 3 14:43:30 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag debian/1%1.27.39-1
in repository libguestfs.
commit d01fbe86662860b3e7fef8b76a8ba9579669c8af
Author: Pino Toscano <ptoscano at redhat.com>
Date: Fri Sep 5 14:47:22 2014 +0200
daemon: add a way to check for the version of augeas
Query augeas for its version when required, i.e. only once when using
the new augeas_is_version function.
---
daemon/augeas.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
daemon/daemon.h | 16 ++++++++++++++-
2 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/daemon/augeas.c b/daemon/augeas.c
index 74f3ba7..9c8bbcc 100644
--- a/daemon/augeas.c
+++ b/daemon/augeas.c
@@ -29,12 +29,73 @@
#include "actions.h"
#include "optgroups.h"
+#define FPRINTF_AUGEAS_ERROR(aug,fs,...) \
+ do { \
+ int code = aug_error (aug); \
+ if (code == AUG_ENOMEM) \
+ reply_with_error (fs ": augeas out of memory", ##__VA_ARGS__); \
+ else { \
+ const char *message = aug_error_message (aug); \
+ const char *minor = aug_error_minor_message (aug); \
+ const char *details = aug_error_details (aug); \
+ fprintf (stderr, fs ": %s%s%s%s%s", ##__VA_ARGS__, \
+ message, \
+ minor ? ": " : "", minor ? minor : "", \
+ details ? ": " : "", details ? details : ""); \
+ } \
+ } while (0)
+
+int augeas_version;
+
/* The Augeas handle. We maintain a single handle per daemon, which
* is all that is necessary and reduces the complexity of the API
* considerably.
*/
static augeas *aug = NULL;
+void
+aug_read_version (void)
+{
+ CLEANUP_AUG_CLOSE augeas *ah = NULL;
+ int r;
+ const char *str;
+ int major = 0, minor = 0, patch = 0;
+
+ if (augeas_version != 0)
+ return;
+
+ /* Optimization: do not load the files nor the lenses, since we are
+ * only interested in the version.
+ */
+ ah = aug_init ("/", NULL, AUG_NO_ERR_CLOSE | AUG_NO_LOAD | AUG_NO_STDINC);
+ if (!ah) {
+ FPRINTF_AUGEAS_ERROR (ah, "augeas initialization failed");
+ return;
+ }
+
+ if (aug_error (ah) != AUG_NOERROR) {
+ FPRINTF_AUGEAS_ERROR (ah, "aug_init");
+ return;
+ }
+
+ r = aug_get (ah, "/augeas/version", &str);
+ if (r != 1) {
+ FPRINTF_AUGEAS_ERROR (ah, "aug_get");
+ return;
+ }
+
+ r = sscanf (str, "%d.%d.%d", &major, &minor, &patch);
+ if (r != 2 && r != 3) {
+ fprintf (stderr, "cannot match the version string in '%s'\n", str);
+ return;
+ }
+
+ if (verbose)
+ fprintf (stderr, "augeas version: %d.%d.%d\n", major, minor, patch);
+
+ augeas_version = (major << 16) | (minor << 8) | patch;
+}
+
/* Clean up the augeas handle on daemon exit. */
void aug_finalize (void) __attribute__((destructor));
void
diff --git a/daemon/daemon.h b/daemon/daemon.h
index b9e7402..0ccbc9e 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -228,8 +228,22 @@ extern void copy_lvm (void);
/*-- in zero.c --*/
extern void wipe_device_before_mkfs (const char *device);
-/*-- in augeas.c, hivex.c, journal.c --*/
+/*-- in augeas.c --*/
+extern void aug_read_version (void);
extern void aug_finalize (void);
+
+/* The version of augeas, saved as:
+ * (MAJOR << 16) | (MINOR << 8) | PATCH
+ */
+extern int augeas_version;
+static inline int
+augeas_is_version (int major, int minor, int patch)
+{
+ aug_read_version (); /* Lazy version reading. */
+ return augeas_version >= ((major << 16) | (minor << 8) | patch);
+}
+
+/*-- hivex.c, journal.c --*/
extern void hivex_finalize (void);
extern void journal_finalize (void);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list