Re: [PATCH] testptp: Fix compile with musl libc

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

 



Hi Hauke,

On Sun, Feb 14, 2021 at 06:09:40PM +0100, Hauke Mehrtens wrote:
> Musl libc does not define the glibc specific macro __GLIBC_PREREQ(), but
> it has the clock_adjtime() function. Assume that a libc implementation
> which does not define __GLIBC_PREREQ at all still implements
> clock_adjtime().
> 
> This fixes a build problem with musl libc because the __GLIBC_PREREQ()
> macro is missing.
> 
> Fixes: 42e1358e103d ("ptp: In the testptp utility, use clock_adjtime from glibc when available")
> Signed-off-by: Hauke Mehrtens <hauke@xxxxxxxxxx>
> ---
>  tools/testing/selftests/ptp/testptp.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tools/testing/selftests/ptp/testptp.c b/tools/testing/selftests/ptp/testptp.c
> index f7911aaeb007..ecffe2c78543 100644
> --- a/tools/testing/selftests/ptp/testptp.c
> +++ b/tools/testing/selftests/ptp/testptp.c
> @@ -38,6 +38,7 @@
>  #define NSEC_PER_SEC 1000000000LL
>  
>  /* clock_adjtime is not available in GLIBC < 2.14 */
> +#ifdef __GLIBC_PREREQ
>  #if !__GLIBC_PREREQ(2, 14)
>  #include <sys/syscall.h>
>  static int clock_adjtime(clockid_t id, struct timex *tx)
> @@ -45,6 +46,7 @@ static int clock_adjtime(clockid_t id, struct timex *tx)
>  	return syscall(__NR_clock_adjtime, id, tx);
>  }
>  #endif
> +#endif /* __GLIBC_PREREQ */

I guess this works, but as you say, there is still an assumption to be
made there, which is that all other C libraries provide the clock_adjtime
syscall definition. So it is likely that this set of #if's and #ifdef's
will be revisited again and again and ...

Maybe this is a matter of personal preference, but I wonder if it's not
actually preferable to do something like this?

#include <sys/syscall.h>

static int compat_clock_adjtime(clockid_t id, struct timex *tx)
{
	return syscall(__NR_clock_adjtime, id, tx);
}

#define clock_adjtime compat_clock_adjtime

This way, everybody uses the same definition of clock_adjtime, and we
bypass the definition provided by libc if there is one, and we provide
our own if there is none.



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux