[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH] Fix trace segfault for non-daemon functions (RHBZ#682756).



-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
>From 819975af019d4213721e40a2dc49ef5d2f9e9bc4 Mon Sep 17 00:00:00 2001
From: Richard W.M. Jones <rjones redhat com>
Date: Mon, 7 Mar 2011 15:55:56 +0000
Subject: [PATCH] Fix trace segfault for non-daemon functions (RHBZ#682756).

---
 generator/generator_c.ml |   40 +++++++++++++++++++++++-----------------
 1 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/generator/generator_c.ml b/generator/generator_c.ml
index c4915ea..c4ceebf 100644
--- a/generator/generator_c.ml
+++ b/generator/generator_c.ml
@@ -887,22 +887,22 @@ check_state (guestfs_h *g, const char *caller)
           shortname style;
       pr "{\n";
       pr "  int trace_flag = g->trace;\n";
-      (match ret with
-       | RErr | RInt _ | RBool _ ->
-           pr "  int r;\n"
-       | RInt64 _ ->
-           pr "  int64_t r;\n"
-       | RConstString _ | RConstOptString _ ->
-           pr "  const char *r;\n"
-       | RString _ | RBufferOut _ ->
-           pr "  char *r;\n"
-       | RStringList _ | RHashtable _ ->
-           pr "  char **r;\n"
-       | RStruct (_, typ) ->
-           pr "  struct guestfs_%s *r;\n" typ
-       | RStructList (_, typ) ->
-           pr "  struct guestfs_%s_list *r;\n" typ
-      );
+      let errcode =
+        match ret with
+        | RErr | RInt _ | RBool _ ->
+            pr "  int r;\n"; "-1"
+        | RInt64 _ ->
+            pr "  int64_t r;\n"; "-1"
+        | RConstString _ | RConstOptString _ ->
+            pr "  const char *r;\n"; "NULL"
+        | RString _ | RBufferOut _ ->
+            pr "  char *r;\n"; "NULL"
+        | RStringList _ | RHashtable _ ->
+            pr "  char **r;\n"; "NULL"
+        | RStruct (_, typ) ->
+            pr "  struct guestfs_%s *r;\n" typ; "NULL"
+        | RStructList (_, typ) ->
+            pr "  struct guestfs_%s_list *r;\n" typ; "NULL" in
       pr "\n";
       check_null_strings shortname style;
       reject_unknown_optargs shortname style;
@@ -910,7 +910,13 @@ check_state (guestfs_h *g, const char *caller)
       pr "  r = guestfs__%s " shortname;
       generate_c_call_args ~handle:"g" style;
       pr ";\n";
-      trace_return shortname style "r";
+      pr "\n";
+      pr "  if (r != %s) {\n" errcode;
+      trace_return ~indent:4 shortname style "r";
+      pr "  } else {\n";
+      trace_return_error ~indent:4 shortname style;
+      pr "  }\n";
+      pr "\n";
       pr "  return r;\n";
       pr "}\n";
       pr "\n"
-- 
1.7.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]