summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2010-11-03 18:29:58 +0000
committerRichard W.M. Jones <rjones@redhat.com>2010-11-03 18:49:00 +0000
commit01d613ae957431d65c700a34e369ef4c06dd6d8f (patch)
tree710e51ac4652ec4e0541a91fce1ae7b17556f472
parent6a218092812783eaea43919674eb8d1c74a80b33 (diff)
downloadlibguestfs-01d613ae957431d65c700a34e369ef4c06dd6d8f.tar.gz
libguestfs-01d613ae957431d65c700a34e369ef4c06dd6d8f.tar.xz
libguestfs-01d613ae957431d65c700a34e369ef4c06dd6d8f.zip
docs: Clarify default error handler.
-rw-r--r--src/guestfs.pod27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/guestfs.pod b/src/guestfs.pod
index ae0c4dfd..b21a25dd 100644
--- a/src/guestfs.pod
+++ b/src/guestfs.pod
@@ -889,7 +889,32 @@ handle by calling L</guestfs_last_error>, L</guestfs_last_errno>,
and/or by setting up an error handler with
L</guestfs_set_error_handler>.
-The default error handler prints the information string to C<stderr>.
+When the handle is created, a default error handler is installed which
+prints the error message string to C<stderr>. For small short-running
+command line programs it is sufficient to do:
+
+ if (guestfs_launch (g) == -1)
+ exit (EXIT_FAILURE);
+
+since the default error handler will ensure that an error message has
+been printed to C<stderr> before the program exits.
+
+For other programs the caller will almost certainly want to install an
+alternate error handler or do error handling in-line like this:
+
+ g = guestfs_create ();
+
+ /* This disables the default behaviour of printing errors
+ on stderr. */
+ guestfs_set_error_handler (g, NULL, NULL);
+
+ if (guestfs_launch (g) == -1) {
+ /* Examine the error message and print it etc. */
+ char *msg = guestfs_last_error (g);
+ int errnum = guestfs_last_errno (g);
+ fprintf (stderr, "%s\n", msg);
+ /* ... */
+ }
Out of memory errors are handled differently. The default action is
to call L<abort(3)>. If this is undesirable, then you can set a