From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O4bsC-00020d-Ul for qemu-devel@nongnu.org; Wed, 21 Apr 2010 11:29:57 -0400 Received: from [140.186.70.92] (port=46298 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4bsA-0001yv-QE for qemu-devel@nongnu.org; Wed, 21 Apr 2010 11:29:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O4bs7-0001Ao-Mg for qemu-devel@nongnu.org; Wed, 21 Apr 2010 11:29:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54161) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4bs7-0001Ah-Dt for qemu-devel@nongnu.org; Wed, 21 Apr 2010 11:29:51 -0400 Date: Wed, 21 Apr 2010 12:29:28 -0300 From: Luiz Capitulino Subject: Re: [Qemu-devel] [PATCH 07/22] qemu-error: Introduce get_errno_string() Message-ID: <20100421122928.7fa3546b@redhat.com> In-Reply-To: <20100421151558.GB22912@redhat.com> References: <1271797792-24571-1-git-send-email-lcapitulino@redhat.com> <1271797792-24571-8-git-send-email-lcapitulino@redhat.com> <20100421082855.GB12843@redhat.com> <4BCEFFC7.9080308@redhat.com> <20100421121214.1bbf339a@redhat.com> <20100421151558.GB22912@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: Kevin Wolf , qemu-devel@nongnu.org, armbru@redhat.com, quintela@redhat.com On Wed, 21 Apr 2010 16:15:58 +0100 "Daniel P. Berrange" wrote: > On Wed, Apr 21, 2010 at 12:12:14PM -0300, Luiz Capitulino wrote: > > On Wed, 21 Apr 2010 18:42:38 +0400 (MSD) > > malc wrote: > > > > > On Wed, 21 Apr 2010, Kevin Wolf wrote: > > > > > > > Am 21.04.2010 10:28, schrieb Daniel P. Berrange: > > > > > On Tue, Apr 20, 2010 at 06:09:37PM -0300, Luiz Capitulino wrote: > > > > >> There are error handling functions in QEMU which print errno codes > > > > >> to the user. While it's debatable if this is good from a user > > > > >> perspective, sometimes it's the best you can do because it's what > > > > >> system calls return and this is also useful for debugging. > > > > >> > > > > >> So, we need a way to expose those codes in QMP. We can't use the > > > > >> codes themselfs because they may vary between systems. > > > > >> > > > > >> The best solution I can think of is returning the string > > > > >> representation of the name. For example, EIO becomes "EIO". > > > > >> > > > > >> This is what get_errno_string() does. > > > > >> > > > > >> Signed-off-by: Luiz Capitulino > > > > >> --- > > > > >> qemu-error.c | 25 +++++++++++++++++++++++++ > > > > >> qemu-error.h | 1 + > > > > >> 2 files changed, 26 insertions(+), 0 deletions(-) > > > > >> > > > > >> diff --git a/qemu-error.c b/qemu-error.c > > > > >> index 5a35e7c..55ce133 100644 > > > > >> --- a/qemu-error.c > > > > >> +++ b/qemu-error.c > > > > >> @@ -207,3 +207,28 @@ void error_report(const char *fmt, ...) > > > > >> va_end(ap); > > > > >> error_printf("\n"); > > > > >> } > > > > >> + > > > > >> +/* > > > > >> + * This is probably only useful for QMP > > > > >> + */ > > > > >> +const char *get_errno_string(int err) > > > > >> +{ > > > > >> + assert(err < 0); > > > > >> + > > > > >> + switch (err) { > > > > >> + case -EINVAL: > > > > >> + return "EINVAL"; > > > > >> + case -EIO: > > > > >> + return "EIO"; > > > > >> + case -ENOENT: > > > > >> + return "ENOENT"; > > > > >> + case -ENOMEDIUM: > > > > >> + return "ENOMEDIUM"; > > > > >> + case -ENOTSUP: > > > > >> + return "ENOTSUP"; > > > > >> + default: > > > > >> + return "unknown"; > > > > >> + } > > > > >> + > > > > >> + abort(); > > > > >> +} > > > > > > > > > > Wouldn't it be nicer to return strerror_r() output instead of errno > > > > > names ? > > > > > > > > I agree. And it would be more complete, too. > > > > > > OTOH it has a problem of returning translated messages (subject to > > > LC_MESSAGES value). > > > > Exactly, and I'm not sure if there's anything that ensure they're > > exactly the same among different systems. > > I thought QMP already declared that the printable error strings are subject > to arbitrary change at any time, which includes translation? Apps needing > something reliable should be hooking onto the error code. Fair enough, although mixed languages would be a pain (ie. error desc in english and this one in something else). > > Regards, > Daniel