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

Dave Chinner david at fromorbit.com
Tue Sep 22 22:25:50 CDT 2015


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 at fromorbit.com



More information about the xfs mailing list