diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-11-09 18:03:49 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-11-09 19:51:09 +0000 |
commit | 2d220f5da2cd25e0fda0c98b98ecb384c1fe5c47 (patch) | |
tree | a718347b5c6141743397b90fe6cf90116a7c8738 | |
parent | b460d9f32eb527bc7aad4894a5f85c4e69366104 (diff) | |
download | libguestfs-2d220f5da2cd25e0fda0c98b98ecb384c1fe5c47.tar.gz libguestfs-2d220f5da2cd25e0fda0c98b98ecb384c1fe5c47.tar.xz libguestfs-2d220f5da2cd25e0fda0c98b98ecb384c1fe5c47.zip |
tools: Modify existing tools to use guestfs_{push,pop}_error_handler.
This is a shorter and more convenient way to disable errors
temporarily across calls.
-rw-r--r-- | cat/virt-filesystems.c | 40 | ||||
-rw-r--r-- | df/df.c | 14 | ||||
-rw-r--r-- | edit/virt-edit.c | 14 | ||||
-rw-r--r-- | examples/mount_local.c | 7 | ||||
-rw-r--r-- | fish/destpaths.c | 17 | ||||
-rw-r--r-- | fish/edit.c | 7 | ||||
-rw-r--r-- | fish/fish.c | 7 | ||||
-rw-r--r-- | fish/supported.c | 7 | ||||
-rw-r--r-- | format/format.c | 14 | ||||
-rw-r--r-- | inspector/virt-inspector.c | 95 | ||||
-rw-r--r-- | tests/charsets/test-charset-fidelity.c | 7 | ||||
-rw-r--r-- | tests/mount-local/test-parallel-mount-local.c | 7 | ||||
-rw-r--r-- | tests/regressions/rhbz790721.c | 7 |
13 files changed, 83 insertions, 160 deletions
diff --git a/cat/virt-filesystems.c b/cat/virt-filesystems.c index c28c4b1c..9c370186 100644 --- a/cat/virt-filesystems.c +++ b/cat/virt-filesystems.c @@ -36,15 +36,6 @@ #include "guestfs.h" #include "options.h" -#define DISABLE_GUESTFS_ERRORS_FOR(stmt) do { \ - guestfs_error_handler_cb old_error_cb; \ - void *old_error_data; \ - old_error_cb = guestfs_get_error_handler (g, &old_error_data); \ - guestfs_set_error_handler (g, NULL, NULL); \ - stmt; \ - guestfs_set_error_handler (g, old_error_cb, old_error_data); \ - } while (0) - /* These globals are shared with options.c. */ guestfs_h *g; @@ -472,9 +463,9 @@ do_output_filesystems (void) * otherwise pass them as NULL. */ if ((columns & COLUMN_VFS_LABEL)) { - DISABLE_GUESTFS_ERRORS_FOR ( - vfs_label = guestfs_vfs_label (g, fses[i]); - ); + guestfs_push_error_handler (g, NULL, NULL); + vfs_label = guestfs_vfs_label (g, fses[i]); + guestfs_pop_error_handler (g); if (vfs_label == NULL) { vfs_label = strdup (""); if (!vfs_label) { @@ -484,9 +475,9 @@ do_output_filesystems (void) } } if ((columns & COLUMN_UUID)) { - DISABLE_GUESTFS_ERRORS_FOR ( - vfs_uuid = guestfs_vfs_uuid (g, fses[i]); - ); + guestfs_push_error_handler (g, NULL, NULL); + vfs_uuid = guestfs_vfs_uuid (g, fses[i]); + guestfs_pop_error_handler (g); if (vfs_uuid == NULL) { vfs_uuid = strdup (""); if (!vfs_uuid) { @@ -662,23 +653,20 @@ get_mbr_id (const char *dev, const char *parent_name) char *parttype = NULL; int mbr_id = -1, partnum; - DISABLE_GUESTFS_ERRORS_FOR ( - parttype = guestfs_part_get_parttype (g, parent_name); - ); + guestfs_push_error_handler (g, NULL, NULL); + + parttype = guestfs_part_get_parttype (g, parent_name); if (parttype && STREQ (parttype, "msdos")) { - DISABLE_GUESTFS_ERRORS_FOR ( - partnum = guestfs_part_to_partnum (g, dev); - ); - if (partnum >= 0) { - DISABLE_GUESTFS_ERRORS_FOR ( - mbr_id = guestfs_part_get_mbr_id (g, parent_name, partnum); - ); - } + partnum = guestfs_part_to_partnum (g, dev); + if (partnum >= 0) + mbr_id = guestfs_part_get_mbr_id (g, parent_name, partnum); } free (parttype); + guestfs_pop_error_handler (g); + return mbr_id; } @@ -122,8 +122,6 @@ df_on_handle (const char *name, const char *uuid, char **devices, int offset) static int find_dev_in_devices (const char *dev, char **devices) { - guestfs_error_handler_cb old_error_cb; - void *old_error_data; size_t i, len; char *whole_disk; int free_whole_disk; @@ -132,12 +130,11 @@ find_dev_in_devices (const char *dev, char **devices) /* Convert 'dev' to a whole disk name. */ len = strlen (dev); if (len > 0 && c_isdigit (dev[len-1])) { - old_error_cb = guestfs_get_error_handler (g, &old_error_data); - guestfs_set_error_handler (g, NULL, NULL); + guestfs_push_error_handler (g, NULL, NULL); whole_disk = guestfs_part_to_dev (g, dev); - guestfs_set_error_handler (g, old_error_cb, old_error_data); + guestfs_pop_error_handler (g); if (!whole_disk) /* probably an MD device or similar */ return 0; @@ -167,8 +164,6 @@ try_df (const char *name, const char *uuid, const char *dev, int offset) { struct guestfs_statvfs *stat = NULL; - guestfs_error_handler_cb old_error_cb; - void *old_error_data; if (verbose) fprintf (stderr, "try_df %s %s %d\n", name, dev, offset); @@ -176,15 +171,14 @@ try_df (const char *name, const char *uuid, /* Try mounting and stating the device. This might reasonably fail, * so don't show errors. */ - old_error_cb = guestfs_get_error_handler (g, &old_error_data); - guestfs_set_error_handler (g, NULL, NULL); + guestfs_push_error_handler (g, NULL, NULL); if (guestfs_mount_ro (g, dev, "/") == 0) { stat = guestfs_statvfs (g, "/"); guestfs_umount_all (g); } - guestfs_set_error_handler (g, old_error_cb, old_error_data); + guestfs_pop_error_handler (g); if (stat) { print_stat (name, uuid, dev, offset, stat); diff --git a/edit/virt-edit.c b/edit/virt-edit.c index db480255..c34f044d 100644 --- a/edit/virt-edit.c +++ b/edit/virt-edit.c @@ -536,16 +536,13 @@ copy_attributes (const char *src, const char *dest) * attributes too? */ if (has_linuxxattrs) { - guestfs_error_handler_cb old_error_cb; - void *old_error_data; - old_error_cb = guestfs_get_error_handler (g, &old_error_data); - guestfs_set_error_handler (g, NULL, NULL); + guestfs_push_error_handler (g, NULL, NULL); selinux_context = guestfs_getxattr (g, src, "security.selinux", &selinux_context_size); /* selinux_context could be NULL. This isn't an error. */ - guestfs_set_error_handler (g, old_error_cb, old_error_data); + guestfs_pop_error_handler (g); } /* Set the permissions (inc. sticky and set*id bits), UID, GID. */ @@ -578,15 +575,12 @@ feature_available (guestfs_h *g, const char *feature) /* 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; - void *old_error_data; - old_error_cb = guestfs_get_error_handler (g, &old_error_data); - guestfs_set_error_handler (g, NULL, NULL); + guestfs_push_error_handler (g, NULL, NULL); const char *groups[] = { feature, NULL }; int r = guestfs_available (g, (char * const *) groups); - guestfs_set_error_handler (g, old_error_cb, old_error_data); + guestfs_pop_error_handler (g); return r == 0 ? 1 : 0; } diff --git a/examples/mount_local.c b/examples/mount_local.c index 2fe1a8f3..fb09bb3b 100644 --- a/examples/mount_local.c +++ b/examples/mount_local.c @@ -45,8 +45,6 @@ main (int argc, char *argv[]) char tempdir[] = "/tmp/mlXXXXXX"; pid_t pid; char *shell, *p; - guestfs_error_handler_cb old_error_cb; - void *old_error_data; if (argc != 2) { usage (); @@ -175,14 +173,13 @@ main (int argc, char *argv[]) /* We're going to hide libguestfs errors here, but in a real program * you would probably want to log them somewhere. */ - old_error_cb = guestfs_get_error_handler (g, &old_error_data); - guestfs_set_error_handler (g, NULL, NULL); + guestfs_push_error_handler (g, NULL, NULL); /* Now run the FUSE thread. */ if (guestfs_mount_local_run (g) == -1) exit (EXIT_FAILURE); - guestfs_set_error_handler (g, old_error_cb, old_error_data); + guestfs_pop_error_handler (g); waitpid (pid, NULL, 0); diff --git a/fish/destpaths.c b/fish/destpaths.c index f3cf0f2e..bc355ccc 100644 --- a/fish/destpaths.c +++ b/fish/destpaths.c @@ -89,19 +89,6 @@ complete_dest_paths_generator (const char *text, int state) static size_t len, index; static struct word *words = NULL; static size_t nr_words = 0; - guestfs_error_handler_cb old_error_cb; - void *old_error_cb_data; - - /* Temporarily replace the error handler so that messages don't - * get printed to stderr while we are issuing commands. - */ -#define SAVE_ERROR_CB \ - old_error_cb = guestfs_get_error_handler (g, &old_error_cb_data); \ - guestfs_set_error_handler (g, NULL, NULL); - - /* Restore error handler. */ -#define RESTORE_ERROR_CB \ - guestfs_set_error_handler (g, old_error_cb, old_error_cb_data); if (!state) { char **strs; @@ -114,7 +101,7 @@ complete_dest_paths_generator (const char *text, int state) words = NULL; nr_words = 0; - SAVE_ERROR_CB + guestfs_push_error_handler (g, NULL, NULL); /* Silently do nothing if an allocation fails */ #define APPEND_STRS_AND_FREE \ @@ -220,7 +207,7 @@ complete_dest_paths_generator (const char *text, int state) * names. At the moment we don't do that. */ - RESTORE_ERROR_CB + guestfs_pop_error_handler (g); } /* This inhibits ordinary (local filename) completion. */ diff --git a/fish/edit.c b/fish/edit.c index b26a2dda..be3fb9ad 100644 --- a/fish/edit.c +++ b/fish/edit.c @@ -206,16 +206,13 @@ copy_attributes (const char *src, const char *dest) * attributes too? */ if (has_linuxxattrs) { - guestfs_error_handler_cb old_error_cb; - void *old_error_data; - old_error_cb = guestfs_get_error_handler (g, &old_error_data); - guestfs_set_error_handler (g, NULL, NULL); + guestfs_push_error_handler (g, NULL, NULL); selinux_context = guestfs_getxattr (g, src, "security.selinux", &selinux_context_size); /* selinux_context could be NULL. This isn't an error. */ - guestfs_set_error_handler (g, old_error_cb, old_error_data); + guestfs_pop_error_handler (g); } /* Set the permissions (inc. sticky and set*id bits), UID, GID. */ diff --git a/fish/fish.c b/fish/fish.c index 332ef1ac..25e49c7e 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -1932,15 +1932,12 @@ feature_available (guestfs_h *g, const char *feature) /* 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; - void *old_error_data; - old_error_cb = guestfs_get_error_handler (g, &old_error_data); - guestfs_set_error_handler (g, NULL, NULL); + guestfs_push_error_handler (g, NULL, NULL); const char *groups[] = { feature, NULL }; int r = guestfs_available (g, (char * const *) groups); - guestfs_set_error_handler (g, old_error_cb, old_error_data); + guestfs_pop_error_handler (g); return r == 0 ? 1 : 0; } diff --git a/fish/supported.c b/fish/supported.c index 1b558bf9..c3a15c8f 100644 --- a/fish/supported.c +++ b/fish/supported.c @@ -39,10 +39,7 @@ run_supported (const char *cmd, size_t argc, char *argv[]) /* Temporarily replace the error handler so that messages don't get * printed to stderr while we are issuing commands. */ - guestfs_error_handler_cb old_error_cb; - void *old_error_cb_data; - old_error_cb = guestfs_get_error_handler (g, &old_error_cb_data); - guestfs_set_error_handler (g, NULL, NULL); + guestfs_push_error_handler (g, NULL, NULL); /* Work out the max string length of any group name. */ size_t i; @@ -76,7 +73,7 @@ run_supported (const char *cmd, size_t argc, char *argv[]) free (groups); /* Restore error handler. */ - guestfs_set_error_handler (g, old_error_cb, old_error_cb_data); + guestfs_pop_error_handler (g); return 0; } diff --git a/format/format.c b/format/format.c index 05b84347..32b4bdb5 100644 --- a/format/format.c +++ b/format/format.c @@ -430,11 +430,8 @@ do_rescan (char **devices) { size_t i; size_t errors = 0; - guestfs_error_handler_cb old_error_cb; - void *old_error_data; - old_error_cb = guestfs_get_error_handler (g, &old_error_data); - guestfs_set_error_handler (g, NULL, NULL); + guestfs_push_error_handler (g, NULL, NULL); for (i = 0; devices[i] != NULL; ++i) { if (guestfs_blockdev_rereadpt (g, devices[i]) == -1) @@ -444,7 +441,7 @@ do_rescan (char **devices) if (guestfs_vgscan (g) == -1) errors++; - guestfs_set_error_handler (g, old_error_cb, old_error_data); + guestfs_pop_error_handler (g); return errors ? 1 : 0; } @@ -455,15 +452,12 @@ feature_available (guestfs_h *g, const char *feature) /* 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; - void *old_error_data; - old_error_cb = guestfs_get_error_handler (g, &old_error_data); - guestfs_set_error_handler (g, NULL, NULL); + guestfs_push_error_handler (g, NULL, NULL); const char *groups[] = { feature, NULL }; int r = guestfs_available (g, (char * const *) groups); - guestfs_set_error_handler (g, old_error_cb, old_error_data); + guestfs_pop_error_handler (g); return r == 0 ? 1 : 0; } diff --git a/inspector/virt-inspector.c b/inspector/virt-inspector.c index a86d30de..7c43b54f 100644 --- a/inspector/virt-inspector.c +++ b/inspector/virt-inspector.c @@ -293,15 +293,6 @@ main (int argc, char *argv[]) exit (EXIT_SUCCESS); } -#define DISABLE_GUESTFS_ERRORS_FOR(stmt) do { \ - guestfs_error_handler_cb old_error_cb; \ - void *old_error_data; \ - old_error_cb = guestfs_get_error_handler (g, &old_error_data); \ - guestfs_set_error_handler (g, NULL, NULL); \ - stmt; \ - guestfs_set_error_handler (g, old_error_cb, old_error_data); \ - } while (0) - #define XMLERROR(code,e) do { \ if ((e) == (code)) { \ fprintf (stderr, _("%s: XML write error at \"%s\": %m\n"), \ @@ -433,22 +424,20 @@ output_root (xmlTextWriterPtr xo, char *root) * or if the systemroot could not be determined for a windows guest. * Disable error output around this call. */ - DISABLE_GUESTFS_ERRORS_FOR ( - str = guestfs_inspect_get_windows_systemroot (g, root); - if (str) - XMLERROR (-1, - xmlTextWriterWriteElement (xo, BAD_CAST "windows_systemroot", - BAD_CAST str)); - free (str); - ); - DISABLE_GUESTFS_ERRORS_FOR ( - str = guestfs_inspect_get_windows_current_control_set (g, root); - if (str) - XMLERROR (-1, - xmlTextWriterWriteElement (xo, BAD_CAST "windows_current_control_set", - BAD_CAST str)); - free (str); - ); + guestfs_push_error_handler (g, NULL, NULL); + str = guestfs_inspect_get_windows_systemroot (g, root); + if (str) + XMLERROR (-1, + xmlTextWriterWriteElement (xo, BAD_CAST "windows_systemroot", + BAD_CAST str)); + free (str); + str = guestfs_inspect_get_windows_current_control_set (g, root); + if (str) + XMLERROR (-1, + xmlTextWriterWriteElement (xo, BAD_CAST "windows_current_control_set", + BAD_CAST str)); + free (str); + guestfs_pop_error_handler (g); str = guestfs_inspect_get_hostname (g, root); if (!str) exit (EXIT_FAILURE); @@ -620,32 +609,30 @@ output_filesystems (xmlTextWriterPtr xo, char *root) xmlTextWriterWriteAttribute (xo, BAD_CAST "dev", BAD_CAST str)); free (str); - DISABLE_GUESTFS_ERRORS_FOR ( - str = guestfs_vfs_type (g, filesystems[i]); - if (str && str[0]) - XMLERROR (-1, - xmlTextWriterWriteElement (xo, BAD_CAST "type", - BAD_CAST str)); - free (str); - ); - - DISABLE_GUESTFS_ERRORS_FOR ( - str = guestfs_vfs_label (g, filesystems[i]); - if (str && str[0]) - XMLERROR (-1, - xmlTextWriterWriteElement (xo, BAD_CAST "label", - BAD_CAST str)); - free (str); - ); - - DISABLE_GUESTFS_ERRORS_FOR ( - str = guestfs_vfs_uuid (g, filesystems[i]); - if (str && str[0]) - XMLERROR (-1, - xmlTextWriterWriteElement (xo, BAD_CAST "uuid", - BAD_CAST str)); - free (str); - ); + guestfs_push_error_handler (g, NULL, NULL); + + str = guestfs_vfs_type (g, filesystems[i]); + if (str && str[0]) + XMLERROR (-1, + xmlTextWriterWriteElement (xo, BAD_CAST "type", + BAD_CAST str)); + free (str); + + str = guestfs_vfs_label (g, filesystems[i]); + if (str && str[0]) + XMLERROR (-1, + xmlTextWriterWriteElement (xo, BAD_CAST "label", + BAD_CAST str)); + free (str); + + str = guestfs_vfs_uuid (g, filesystems[i]); + if (str && str[0]) + XMLERROR (-1, + xmlTextWriterWriteElement (xo, BAD_CAST "uuid", + BAD_CAST str)); + free (str); + + guestfs_pop_error_handler (g); XMLERROR (-1, xmlTextWriterEndElement (xo)); } @@ -662,9 +649,9 @@ output_drive_mappings (xmlTextWriterPtr xo, char *root) char *str; size_t i; - DISABLE_GUESTFS_ERRORS_FOR ( - drive_mappings = guestfs_inspect_get_drive_mappings (g, root); - ); + guestfs_push_error_handler (g, NULL, NULL); + drive_mappings = guestfs_inspect_get_drive_mappings (g, root); + guestfs_pop_error_handler (g); if (drive_mappings == NULL) return; diff --git a/tests/charsets/test-charset-fidelity.c b/tests/charsets/test-charset-fidelity.c index b358f2cd..d67787fe 100644 --- a/tests/charsets/test-charset-fidelity.c +++ b/tests/charsets/test-charset-fidelity.c @@ -448,15 +448,12 @@ feature_available (guestfs_h *g, const char *feature) /* 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; - void *old_error_data; - old_error_cb = guestfs_get_error_handler (g, &old_error_data); - guestfs_set_error_handler (g, NULL, NULL); + guestfs_push_error_handler (g, NULL, NULL); const char *groups[] = { feature, NULL }; int r = guestfs_available (g, (char * const *) groups); - guestfs_set_error_handler (g, old_error_cb, old_error_data); + guestfs_pop_error_handler (g); return r == 0 ? 1 : 0; } diff --git a/tests/mount-local/test-parallel-mount-local.c b/tests/mount-local/test-parallel-mount-local.c index 791a7488..989a9baf 100644 --- a/tests/mount-local/test-parallel-mount-local.c +++ b/tests/mount-local/test-parallel-mount-local.c @@ -204,8 +204,6 @@ start_thread (void *statevp) time_t start_t, t; pid_t pid; int status, r; - guestfs_error_handler_cb old_error_cb; - void *old_error_cb_data; g = guestfs_create (); if (g == NULL) { @@ -264,10 +262,9 @@ start_thread (void *statevp) /* Run the FUSE main loop. We don't really want to see libguestfs * errors here since these are harmless. */ - old_error_cb = guestfs_get_error_handler (g, &old_error_cb_data); - guestfs_set_error_handler (g, NULL, NULL); + guestfs_push_error_handler (g, NULL, NULL); r = guestfs_mount_local_run (g); - guestfs_set_error_handler (g, old_error_cb, old_error_cb_data); + guestfs_pop_error_handler (g); /* Wait for child process to exit and catch any errors from it. */ again: diff --git a/tests/regressions/rhbz790721.c b/tests/regressions/rhbz790721.c index 7d5c266c..72746779 100644 --- a/tests/regressions/rhbz790721.c +++ b/tests/regressions/rhbz790721.c @@ -121,8 +121,6 @@ start_thread (void *vi) { guestfs_h *g; int r, thread_id = *(int *)vi; - guestfs_error_handler_cb old_error_cb; - void *old_error_data; const char *error; g = guestfs_create (); @@ -159,8 +157,7 @@ start_thread (void *vi) * will fail with "child process died unexpectedly". We are * interested in other failures. */ - old_error_cb = guestfs_get_error_handler (g, &old_error_data); - guestfs_set_error_handler (g, NULL, NULL); + guestfs_push_error_handler (g, NULL, NULL); r = guestfs_launch (g); error = guestfs_last_error (g); @@ -190,7 +187,7 @@ start_thread (void *vi) pthread_exit (vi); } - guestfs_set_error_handler (g, old_error_cb, old_error_data); + guestfs_pop_error_handler (g); /* Close the handle. */ guestfs_close (g); |