Note that additional memory may be required to typecheck Augeas lenses (RHBZ#729887).
[libguestfs.git] / generator / generator_daemon.ml
index 21a5888..7e18e35 100644 (file)
@@ -122,18 +122,29 @@ and generate_daemon_actions () =
       let is_filein =
         List.exists (function FileIn _ -> true | _ -> false) args in
 
-      (* Reject unknown optional arguments. *)
+      (* 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
+       * in that case.
+       *)
       if optargs <> [] then (
         let len = List.length optargs in
         let mask = Int64.lognot (Int64.pred (Int64.shift_left 1L len)) in
         pr "  if (optargs_bitmask & UINT64_C(0x%Lx)) {\n" mask;
         if is_filein then
-          pr "    if (cancel_receive () != -2)\n";
+          pr "    cancel_receive ();\n";
         pr "    reply_with_error (\"unknown option in optional arguments bitmask (this can happen if a program is compiled against a newer version of libguestfs, then run against an older version of the daemon)\");\n";
         pr "    goto done;\n";
         pr "  }\n";
-        pr "\n"
+      ) else (
+        pr "  if (optargs_bitmask != 0) {\n";
+        if is_filein then
+          pr "    cancel_receive ();\n";
+        pr "    reply_with_error (\"header optargs_bitmask field must be passed as 0 for calls that don't take optional arguments\");\n";
+        pr "    goto done;\n";
+        pr "  }\n";
       );
+      pr "\n";
 
       (* Decode arguments. *)
       if args <> [] || optargs <> [] then (
@@ -141,8 +152,8 @@ and generate_daemon_actions () =
         pr "\n";
         pr "  if (!xdr_guestfs_%s_args (xdr_in, &args)) {\n" name;
         if is_filein then
-          pr "    if (cancel_receive () != -2)\n";
-        pr "      reply_with_error (\"daemon failed to decode procedure arguments\");\n";
+          pr "    cancel_receive ();\n";
+        pr "    reply_with_error (\"daemon failed to decode procedure arguments\");\n";
         pr "    goto done;\n";
         pr "  }\n";
         let pr_args n =
@@ -153,8 +164,8 @@ and generate_daemon_actions () =
           pr "                sizeof (char *) * (args.%s.%s_len+1));\n" n n;
           pr "  if (%s == NULL) {\n" n;
           if is_filein then
-            pr "    if (cancel_receive () != -2)\n";
-          pr "      reply_with_perror (\"realloc\");\n";
+            pr "    cancel_receive ();\n";
+          pr "    reply_with_perror (\"realloc\");\n";
           pr "    goto done;\n";
           pr "  }\n";
           pr "  %s[args.%s.%s_len] = NULL;\n" n n n;
@@ -165,15 +176,15 @@ and generate_daemon_actions () =
           | Pathname n ->
               pr_args n;
               pr "  ABS_PATH (%s, %s, goto done);\n"
-                n (if is_filein then "cancel_receive ()" else "0");
+                n (if is_filein then "cancel_receive ()" else "");
           | Device n ->
               pr_args n;
               pr "  RESOLVE_DEVICE (%s, %s, goto done);\n"
-                n (if is_filein then "cancel_receive ()" else "0");
+                n (if is_filein then "cancel_receive ()" else "");
           | Dev_or_Path n ->
               pr_args n;
               pr "  REQUIRE_ROOT_OR_RESOLVE_DEVICE (%s, %s, goto done);\n"
-                n (if is_filein then "cancel_receive ()" else "0");
+                n (if is_filein then "cancel_receive ()" else "");
           | String n | Key n -> pr_args n
           | OptString n -> pr "  %s = args.%s ? *args.%s : NULL;\n" n n n
           | StringList n ->
@@ -187,7 +198,7 @@ and generate_daemon_actions () =
               pr "    size_t i;\n";
               pr "    for (i = 0; %s[i] != NULL; ++i)\n" n;
               pr "      RESOLVE_DEVICE (%s[i], %s, goto done);\n" n
-                (if is_filein then "cancel_receive ()" else "0");
+                (if is_filein then "cancel_receive ()" else "");
               pr "  }\n";
           | Bool n -> pr "  %s = args.%s;\n" n n
           | Int n -> pr "  %s = args.%s;\n" n n
@@ -206,7 +217,7 @@ and generate_daemon_actions () =
         (* Emit NEED_ROOT just once, even when there are two or
            more Pathname args *)
         pr "  NEED_ROOT (%s, goto done);\n"
-          (if is_filein then "cancel_receive ()" else "0");
+          (if is_filein then "cancel_receive ()" else "");
       );
 
       (* Don't want to call the impl with any FileIn or FileOut