>From 0cef389dee418992db186836c8c5f2e3a296f378 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Mon, 23 Aug 2010 22:19:24 +0100 Subject: [PATCH 2/2] Change protocol to send Linux errno from daemon to library. This changes the protocol so that the Linux errno (if available) is sent back to the library. Note that the errno is not yet made available to callers, since it is not clear how best to present this Linux-specific number. --- daemon/proto.c | 9 +++++---- src/generator.ml | 1 + src/guestfs.pod | 5 ++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/daemon/proto.c b/daemon/proto.c index 6fa243f..628e86c 100644 --- a/daemon/proto.c +++ b/daemon/proto.c @@ -179,7 +179,7 @@ main_loop (int _sock) } } -static void send_error (const char *msg); +static void send_error (int errnum, const char *msg); void reply_with_error (const char *fs, ...) @@ -191,7 +191,7 @@ reply_with_error (const char *fs, ...) vsnprintf (err, sizeof err, fs, args); va_end (args); - send_error (err); + send_error (0, err); } void @@ -207,11 +207,11 @@ reply_with_perror_errno (int err, const char *fs, ...) snprintf (buf2, sizeof buf2, "%s: %s", buf1, strerror (err)); - send_error (buf2); + send_error (err, buf2); } static void -send_error (const char *msg) +send_error (int errnum, const char *msg) { XDR xdr; char buf[GUESTFS_ERROR_LEN + 200]; @@ -236,6 +236,7 @@ send_error (const char *msg) exit (EXIT_FAILURE); } + err.linux_errno = errnum; err.error_message = (char *) msg; if (!xdr_guestfs_message_error (&xdr, &err)) { diff --git a/src/generator.ml b/src/generator.ml index 7d35ac1..233f8bd 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -6331,6 +6331,7 @@ enum guestfs_message_status { pr "\ struct guestfs_message_error { + int linux_errno; /* Linux errno if available. */ string error_message; }; diff --git a/src/guestfs.pod b/src/guestfs.pod index a4d9c57..4dafb07 100644 --- a/src/guestfs.pod +++ b/src/guestfs.pod @@ -724,7 +724,7 @@ The error message you get from this is also a little obscure. This could be fixed in the generator by specially marking parameters and return values which take bytes or other units. -=item Protocol should return errno with error messages. +=item Library should return errno with error messages. It would be a nice-to-have to be able to get the original value of 'errno' from inside the appliance along error paths (where set). @@ -732,6 +732,9 @@ Currently L goes through hoops to try to reverse the error message string into an errno, see the function error() in fuse/guestmount.c. +In libguestfs 1.5.4, the protocol was changed so that the +Linux errno is sent back from the daemon. + =back =head2 PROTOCOL LIMITS -- 1.7.1