X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fproto.c;h=1ad9d11192f592c6820b7d0adce53ce95c3d5380;hp=2231037b61981a8cce00144dd1220594593e14c1;hb=088d0c53cfe0dcb20b87707a9055175b2fd6b72f;hpb=55355491c5ad2535b99a31ec81241f7f9f92177e diff --git a/daemon/proto.c b/daemon/proto.c index 2231037..1ad9d11 100644 --- a/daemon/proto.c +++ b/daemon/proto.c @@ -29,6 +29,10 @@ #include #include +#ifdef HAVE_WINDOWS_H +#include +#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. */ @@ -180,12 +195,11 @@ reply_with_error (const char *fs, ...) } void -reply_with_perror (const char *fs, ...) +reply_with_perror_errno (int err, const char *fs, ...) { char buf1[GUESTFS_ERROR_LEN]; char buf2[GUESTFS_ERROR_LEN]; va_list args; - int err = errno; va_start (args, fs); vsnprintf (buf1, sizeof buf1, fs, args);