summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-02-01 12:18:35 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-02-01 15:09:09 +0000
commit330fbea5b2d6bd7db84f7ea7afe87cf1bcd438e0 (patch)
tree5a1c1de5498303ace3de64f771ccba949f202df0 /generator
parent90d6386c13edcb479113889bbd3cedf83c2e6277 (diff)
Clarify the error message when unavailable functions are called (RHBZ#679737).
Callers are supposed to use the availability API to check for functions that may not be available in particular builds of libguestfs. If they don't do this, currently they tend to get obscure error messages, eg: libguestfs: error: zerofree: /dev/vda1: zerofree: No such file or directory This commit changes the error message to explain what callers ought to be doing instead: libguestfs: error: zerofree: feature 'zerofree' is not available in this build of libguestfs. Read 'AVAILABILITY' in the guestfs(3) man page for how to check for the availability of features. This patch makes the stubs check for availability. The stub code changes to: static void zerofree_stub (XDR *xdr_in) { [...] /* The caller should have checked before calling this. */ if (! optgroup_zerofree_available ()) { reply_with_error ("feature '%s' is not available in this\n" "build of libguestfs. Read 'AVAILABILITY' in the guestfs(3) man page for\n" "how to check for the availability of features.", "zerofree"); goto done; } [...]
Diffstat (limited to 'generator')
-rw-r--r--generator/generator_daemon.ml24
1 files changed, 22 insertions, 2 deletions
diff --git a/generator/generator_daemon.ml b/generator/generator_daemon.ml
index 88cc8bf2..0eb2446a 100644
--- a/generator/generator_daemon.ml
+++ b/generator/generator_daemon.ml
@@ -75,12 +75,14 @@ and generate_daemon_actions () =
pr "#include \"c-ctype.h\"\n";
pr "#include \"guestfs_protocol.h\"\n";
pr "#include \"actions.h\"\n";
+ pr "#include \"optgroups.h\"\n";
pr "\n";
List.iter (
- fun (name, (ret, args, optargs), _, _, _, _, _) ->
+ fun (name, (ret, args, optargs), _, flags, _, _, _) ->
(* Generate server-side stubs. *)
- pr "static void %s_stub (XDR *xdr_in)\n" name;
+ pr "static void\n";
+ pr "%s_stub (XDR *xdr_in)\n" name;
pr "{\n";
(match ret with
| RErr | RInt _ -> pr " int r;\n"
@@ -122,6 +124,24 @@ and generate_daemon_actions () =
let is_filein =
List.exists (function FileIn _ -> true | _ -> false) args in
+ (* Reject Optional functions that are not available (RHBZ#679737). *)
+ List.iter (
+ function
+ | Optional group ->
+ pr " /* The caller should have checked before calling this. */\n";
+ pr " if (! optgroup_%s_available ()) {\n" group;
+ if is_filein then
+ pr " cancel_receive ();\n";
+ pr " reply_with_error (\"feature '%%s' is not available in this\\n\"\n";
+ pr " \"build of libguestfs. Read 'AVAILABILITY' in the guestfs(3) man page for\\n\"\n";
+ pr " \"how to check for the availability of features.\",\n";
+ pr " \"%s\");\n" group;
+ pr " goto done;\n";
+ pr " }\n";
+ pr "\n"
+ | _ -> ()
+ ) flags;
+
(* Reject unknown optional arguments.
* Note this code is included even for calls with no optional
* args because the caller must not pass optargs_bitmask != 0