summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-11-09 18:47:57 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-11-09 19:51:08 +0000
commitb460d9f32eb527bc7aad4894a5f85c4e69366104 (patch)
treeaeacce4c04338d8327f2df1a7154e2e4677eb71d
parenta3b6751863b4e7e620dd1b75b4a8d8187d2069a5 (diff)
downloadlibguestfs-b460d9f32eb527bc7aad4894a5f85c4e69366104.tar.gz
libguestfs-b460d9f32eb527bc7aad4894a5f85c4e69366104.tar.xz
libguestfs-b460d9f32eb527bc7aad4894a5f85c4e69366104.zip
lib: Modify library code to use guestfs_{push,pop}_error_handler.
This is less efficient than directly manipulating g->error_cb, but easier to maintain.
-rw-r--r--src/inspect-fs-unix.c23
-rw-r--r--src/inspect-fs-windows.c10
-rw-r--r--src/inspect-fs.c13
-rw-r--r--src/inspect.c13
-rw-r--r--src/listfs.c8
5 files changed, 33 insertions, 34 deletions
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 33c5ee97..a48d1768 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -718,14 +718,14 @@ check_architecture (guestfs_h *g, struct inspect_fs *fs)
const char *binaries[] =
{ "/bin/bash", "/bin/ls", "/bin/echo", "/bin/rm", "/bin/sh" };
size_t i;
+ char *arch;
for (i = 0; i < sizeof binaries / sizeof binaries[0]; ++i) {
if (guestfs_is_file (g, binaries[i]) > 0) {
/* Ignore errors from file_architecture call. */
- guestfs_error_handler_cb old_error_cb = g->error_cb;
- g->error_cb = NULL;
- char *arch = guestfs_file_architecture (g, binaries[i]);
- g->error_cb = old_error_cb;
+ guestfs_push_error_handler (g, NULL, NULL);
+ arch = guestfs_file_architecture (g, binaries[i]);
+ guestfs_pop_error_handler (g);
if (arch) {
/* String will be owned by handle, freed by
@@ -814,10 +814,9 @@ check_hostname_redhat (guestfs_h *g, struct inspect_fs *fs)
/* Errors here are not fatal (RHBZ#726739), since it could be
* just missing HOSTNAME field in the file.
*/
- guestfs_error_handler_cb old_error_cb = g->error_cb;
- g->error_cb = NULL;
+ guestfs_push_error_handler (g, NULL, NULL);
hostname = guestfs_aug_get (g, "/files/etc/sysconfig/network/HOSTNAME");
- g->error_cb = old_error_cb;
+ guestfs_pop_error_handler (g);
/* This is freed by guestfs___free_inspect_info. Note that hostname
* could be NULL because we ignored errors above.
@@ -1593,23 +1592,21 @@ static int
is_partition (guestfs_h *g, const char *partition)
{
char *device;
- guestfs_error_handler_cb old_error_cb;
- old_error_cb = g->error_cb;
- g->error_cb = NULL;
+ guestfs_push_error_handler (g, NULL, NULL);
if ((device = guestfs_part_to_dev (g, partition)) == NULL) {
- g->error_cb = old_error_cb;
+ guestfs_pop_error_handler (g);
return 0;
}
if (guestfs_device_index (g, device) == -1) {
- g->error_cb = old_error_cb;
+ guestfs_pop_error_handler (g);
free (device);
return 0;
}
- g->error_cb = old_error_cb;
+ guestfs_pop_error_handler (g);
free (device);
return 1;
diff --git a/src/inspect-fs-windows.c b/src/inspect-fs-windows.c
index af75871d..af4dcfdf 100644
--- a/src/inspect-fs-windows.c
+++ b/src/inspect-fs-windows.c
@@ -564,10 +564,12 @@ map_registry_disk_blob (guestfs_h *g, const char *blob)
char *
guestfs___case_sensitive_path_silently (guestfs_h *g, const char *path)
{
- guestfs_error_handler_cb old_error_cb = g->error_cb;
- g->error_cb = NULL;
- char *ret = guestfs_case_sensitive_path (g, path);
- g->error_cb = old_error_cb;
+ char *ret;
+
+ guestfs_push_error_handler (g, NULL, NULL);
+ ret = guestfs_case_sensitive_path (g, path);
+ guestfs_pop_error_handler (g);
+
return ret;
}
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index 2dbafb5d..ffcd0d68 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -91,14 +91,15 @@ int
guestfs___check_for_filesystem_on (guestfs_h *g, const char *device,
int is_block, int is_partnum)
{
+ char *vfs_type;
+
/* Get vfs-type in order to check if it's a Linux(?) swap device.
* If there's an error we should ignore it, so to do that we have to
* temporarily replace the error handler with a null one.
*/
- guestfs_error_handler_cb old_error_cb = g->error_cb;
- g->error_cb = NULL;
- char *vfs_type = guestfs_vfs_type (g, device);
- g->error_cb = old_error_cb;
+ guestfs_push_error_handler (g, NULL, NULL);
+ vfs_type = guestfs_vfs_type (g, device);
+ guestfs_pop_error_handler (g);
int is_swap = vfs_type && STREQ (vfs_type, "swap");
@@ -115,8 +116,8 @@ guestfs___check_for_filesystem_on (guestfs_h *g, const char *device,
}
/* Try mounting the device. As above, ignore errors. */
- g->error_cb = NULL;
int r;
+ guestfs_push_error_handler (g, NULL, NULL);
if (vfs_type && STREQ (vfs_type, "ufs")) { /* Hack for the *BSDs. */
/* FreeBSD fs is a variant of ufs called ufs2 ... */
r = guestfs_mount_vfs (g, "ro,ufstype=ufs2", "ufs", device, "/");
@@ -127,7 +128,7 @@ guestfs___check_for_filesystem_on (guestfs_h *g, const char *device,
r = guestfs_mount_ro (g, device, "/");
}
free (vfs_type);
- g->error_cb = old_error_cb;
+ guestfs_pop_error_handler (g);
if (r == -1)
return 0;
diff --git a/src/inspect.c b/src/inspect.c
index f16aea10..59773c72 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -564,16 +564,15 @@ guestfs___free_inspect_info (guestfs_h *g)
int
guestfs___feature_available (guestfs_h *g, const char *feature)
{
+ const char *groups[] = { feature, NULL };
+ int r;
+
/* If there's an error we should ignore it, so to do that we have to
* temporarily replace the error handler with a null one.
*/
- guestfs_error_handler_cb old_error_cb = g->error_cb;
- g->error_cb = NULL;
-
- const char *groups[] = { feature, NULL };
- int r = guestfs_available (g, (char * const *) groups);
-
- g->error_cb = old_error_cb;
+ guestfs_push_error_handler (g, NULL, NULL);
+ r = guestfs_available (g, (char * const *) groups);
+ guestfs_pop_error_handler (g);
return r == 0 ? 1 : 0;
}
diff --git a/src/listfs.c b/src/listfs.c
index 5ddd1de5..697fb2e0 100644
--- a/src/listfs.c
+++ b/src/listfs.c
@@ -134,11 +134,11 @@ check_with_vfs_type (guestfs_h *g, const char *device,
char ***ret, size_t *ret_size)
{
char *v;
+ char *vfs_type;
- guestfs_error_handler_cb old_error_cb = g->error_cb;
- g->error_cb = NULL;
- char *vfs_type = guestfs_vfs_type (g, device);
- g->error_cb = old_error_cb;
+ guestfs_push_error_handler (g, NULL, NULL);
+ vfs_type = guestfs_vfs_type (g, device);
+ guestfs_pop_error_handler (g);
if (!vfs_type)
v = safe_strdup (g, "unknown");