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

Re: [Libguestfs] [PATCH 1/5] daemon error handling: Clear errno before calling stub functions.



On 30/11/09 14:42, Richard W.M. Jones wrote:

From bad45d57b816c3734bcbf5f92a707fc1ff112c1c Mon Sep 17 00:00:00 2001
From: Richard Jones<rjones redhat com>
Date: Mon, 30 Nov 2009 13:55:04 +0000
Subject: [PATCH 1/5] daemon error handling: Clear errno before calling stub functions.

This just ensures that we accurately report errors, even if our
error path code doesn't set errno.  We won't end up with a bogus
errno left over from a previous call.
---
  daemon/proto.c |   17 ++++++++++++++++-
  1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/daemon/proto.c b/daemon/proto.c
index 2231037..e3ff9e9 100644
--- a/daemon/proto.c
+++ b/daemon/proto.c
@@ -29,6 +29,10 @@
  #include<rpc/types.h>
  #include<rpc/xdr.h>

+#ifdef HAVE_WINDOWS_H
+#include<windows.h>
+#endif
+
  #include "c-ctype.h"
  #include "ignore-value.h"

@@ -137,9 +141,20 @@ main_loop (int _sock)
        goto cont;
      }

-    /* Now start to process this message. */
      proc_nr = hdr.proc;
      serial = hdr.serial;
+
+    /* Clear errors before we call the stub functions.  This is just
+     * to ensure that we can accurately report errors in cases where
+     * error handling paths don't set errno correctly.
+     */
+    errno = 0;
+#ifdef WIN32
+    SetLastError (0);
+    WSASetLastError (0);
+#endif
+
+    /* Now start to process this message. */
      dispatch_incoming_message (&xdr);
      /* Note that dispatch_incoming_message will also send a reply. */

-- 1.6.5.2

Looks safe. ACK.

Incidentally, what's returning success but still setting an error code which requires this?

Matt
--
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team

M:       +44 (0)7977 267231
GPG ID:  D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490


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