xfs
[Top] [All Lists]

Re: [PATCH 10/14] xfsprogs: Add a timer implementation for OS X

To: Jan Tulak <jtulak@xxxxxxxxxx>
Subject: Re: [PATCH 10/14] xfsprogs: Add a timer implementation for OS X
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Wed, 23 Sep 2015 13:25:50 +1000
Cc: xfs@xxxxxxxxxxx
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1442311164-12921-11-git-send-email-jtulak@xxxxxxxxxx>
References: <1442311164-12921-1-git-send-email-jtulak@xxxxxxxxxx> <1442311164-12921-11-git-send-email-jtulak@xxxxxxxxxx>
User-agent: Mutt/1.5.21 (2010-09-15)
On Tue, Sep 15, 2015 at 11:59:20AM +0200, Jan Tulak wrote:
> OS X does not have the timer used in xfs_repair.
> Add a simple implementation providing the required
> capabilities.
....
>  #endif       /* __XFS_DARWIN_H__ */
> diff --git a/repair/progress.c b/repair/progress.c
> index 27cbaef..0fee7dc 100644
> --- a/repair/progress.c
> +++ b/repair/progress.c
> @@ -184,10 +184,22 @@ progress_rpt_thread (void *p)
>        */
>  
>       timespec.it_value.tv_sec = msgp->interval;
> -     timespec.it_value.tv_nsec = 0;
>       timespec.it_interval.tv_sec = msgp->interval;
> +     /*
> +      * On some platforms (like OS X), timers and time things are slightly
> +      * different: itimerspec is replaced with itimerval and timeval struct
> +      * has no tv_nsec, but just tv_usec member.
> +      * For compatibility, itimerspec is a macro defined to the existing
> +      * itimerval on these platforms, and in such case, use usec instead
> +      * of nsec.
> +      */
> +#ifndef itimerspec
> +     timespec.it_value.tv_nsec = 0;
>       timespec.it_interval.tv_nsec = 0;
> -
> +#else
> +     timespec.it_value.tv_usec = 0;
> +     timespec.it_interval.tv_usec = 0;
> +#endif

That's pretty nasty. How about this:

        memset(&timespec, 0, sizeof(timespec));
        timespec.it_value.tv_sec = msgp->interval;
        timespec.it_interval.tv_sec = msgp->interval;

Cheers,

Dave.
-- 
Dave Chinner
david@xxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>