qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 07/22] qemu-error: Introduce get_errno_string()


From: Kevin Wolf
Subject: Re: [Qemu-devel] [PATCH 07/22] qemu-error: Introduce get_errno_string()
Date: Wed, 21 Apr 2010 15:38:15 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100330 Fedora/3.0.4-1.fc12 Thunderbird/3.0.4

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 <address@hidden>
>> ---
>>  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.

Kevin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]