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

Re: [Xen-devel] [PATCH 17/28] libxl: gettimeofday doesn't return an errno on failure



On Wed, 2013-09-18 at 15:37 +1200, Matthew Daley wrote:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/gettimeofday.html
agrees with this but the Linux manpages gettimeofday(2) disagrees:
       gettimeofday() and settimeofday() return 0 for success,  or  -1  for
       failure (in which case errno is set appropriately).

They may just have confused themselves by lumping get in with set, but
at least one error code (EFAULT) seems like it could apply to get too.

Since the spec says it cannot fail I think there's no harm in reporting
errno if it does fail.

is the CHK_ERRNO macro correct? 
#define CHK_ERRNO( call ) ({                                            \
        int chk_errno = (call);                                         \
        if (chk_errno < 0) {                                                \
            fprintf(stderr,"xl: fatal error: %s:%d: %s: %s\n",          \
                    __FILE__,__LINE__, strerror(chk_errno), #call);     \
            exit(-ERROR_FAIL);                                          \
        }                                                               \
    })

It seems to report the reutrn code and not errno, so it will always say
-1 won't it?

I think the actual coverity error "chk_errno" is passed to a parameter
that cannot be negative." stems from this not the lack of errno, because
coverity seems to know that strerror cannot take a negative number.

> Coverity-ID: 1055570
> Signed-off-by: Matthew Daley <mattjd@xxxxxxxxx>
> ---
>  tools/libxl/xl_cmdimpl.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> index 642b130..7ec5d6a 100644
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -3392,7 +3392,7 @@ static void migration_child_report(int recv_fd) {
>  
>      if (!xl_child_pid(child_migration)) return;
>  
> -    CHK_ERRNO( gettimeofday(&waituntil, 0) );
> +    MUST( gettimeofday(&waituntil, 0) );
>      waituntil.tv_sec += 2;
>  
>      for (;;) {
> @@ -3413,7 +3413,7 @@ static void migration_child_report(int recv_fd) {
>          }
>          assert(child == 0);
>  
> -        CHK_ERRNO( gettimeofday(&now, 0) );
> +        MUST( gettimeofday(&now, 0) );
>          if (timercmp(&now, &waituntil, >)) {
>              fprintf(stderr, "migration child [%ld] not exiting, no longer"
>                      " waiting (exit status will be unreported)\n",



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.