X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=generator%2Fgenerator_daemon.ml;h=f5c1fa3e79ba0c02b96a0f50fe10e648b0c2033a;hb=1acb82e9f70a81982c7c2ad8b7966bffc4fcfa8a;hp=f15ae6126b8e3552f18e79998671d987146b5f97;hpb=65f44b459070a1dbfba66c31e0be69588e49f4a8;p=libguestfs.git diff --git a/generator/generator_daemon.ml b/generator/generator_daemon.ml index f15ae61..f5c1fa3 100644 --- a/generator/generator_daemon.ml +++ b/generator/generator_daemon.ml @@ -82,21 +82,20 @@ and generate_daemon_actions () = (* Generate server-side stubs. *) pr "static void %s_stub (XDR *xdr_in)\n" name; pr "{\n"; - let error_code = - match ret with - | RErr | RInt _ -> pr " int r;\n"; "-1" - | RInt64 _ -> pr " int64_t r;\n"; "-1" - | RBool _ -> pr " int r;\n"; "-1" - | RConstString _ | RConstOptString _ -> - failwithf "RConstString|RConstOptString cannot be used by daemon functions" - | RString _ -> pr " char *r;\n"; "NULL" - | RStringList _ | RHashtable _ -> pr " char **r;\n"; "NULL" - | RStruct (_, typ) -> pr " guestfs_int_%s *r;\n" typ; "NULL" - | RStructList (_, typ) -> pr " guestfs_int_%s_list *r;\n" typ; "NULL" - | RBufferOut _ -> - pr " size_t size = 1;\n"; - pr " char *r;\n"; - "NULL" in + (match ret with + | RErr | RInt _ -> pr " int r;\n" + | RInt64 _ -> pr " int64_t r;\n" + | RBool _ -> pr " int r;\n" + | RConstString _ | RConstOptString _ -> + failwithf "RConstString|RConstOptString cannot be used by daemon functions" + | RString _ -> pr " char *r;\n" + | RStringList _ | RHashtable _ -> pr " char **r;\n" + | RStruct (_, typ) -> pr " guestfs_int_%s *r;\n" typ + | RStructList (_, typ) -> pr " guestfs_int_%s_list *r;\n" typ + | RBufferOut _ -> + pr " size_t size = 1;\n"; + pr " char *r;\n" + ); if args <> [] || optargs <> [] then ( pr " struct guestfs_%s_args args;\n" name; @@ -129,7 +128,7 @@ and generate_daemon_actions () = 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"; @@ -142,8 +141,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 = @@ -154,8 +153,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; @@ -166,15 +165,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 -> @@ -188,7 +187,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 @@ -207,7 +206,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 @@ -223,11 +222,16 @@ and generate_daemon_actions () = pr ";\n" in (match ret with + | RConstOptString _ -> assert false | RErr | RInt _ | RInt64 _ | RBool _ - | RConstString _ | RConstOptString _ + | RConstString _ | RString _ | RStringList _ | RHashtable _ | RStruct (_, _) | RStructList (_, _) -> - pr " if (r == %s)\n" error_code; + let errcode = + match errcode_of_ret ret with + | `CannotReturnError -> assert false + | (`ErrorIsMinusOne | `ErrorIsNULL) as e -> e in + pr " if (r == %s)\n" (string_of_errcode errcode); pr " /* do_%s has already called reply_with_error */\n" name; pr " goto done;\n"; pr "\n" @@ -235,7 +239,7 @@ and generate_daemon_actions () = pr " /* size == 0 && r == NULL could be a non-error case (just\n"; pr " * an ordinary zero-length buffer), so be careful ...\n"; pr " */\n"; - pr " if (size == 1 && r == %s)\n" error_code; + pr " if (size == 1 && r == NULL)\n"; pr " /* do_%s has already called reply_with_error */\n" name; pr " goto done;\n"; pr "\n"