[LTP] nanosleep: use POSIX runtime detection for CLOCK_MONOTONIC

linuxtestproject.agent@gmail.com linuxtestproject.agent@gmail.com
Thu Apr 16 15:45:04 CEST 2026


Hi Andrea,

On 2026-04-16, Andrea Cervesato wrote:
> nanosleep: use POSIX runtime detection for CLOCK_MONOTONIC

> +static inline clockid_t get_supported_clock(void)
> +{
> +#ifdef _POSIX_MONOTONIC_CLOCK
> +	if (_POSIX_MONOTONIC_CLOCK > 0)
> +		return CLOCK_MONOTONIC;
> +
> +	if (!_POSIX_MONOTONIC_CLOCK && sysconf(_SC_MONOTONIC_CLOCK) > 0)
> +		return CLOCK_MONOTONIC;
> +#endif
> +
> +	printf("CLOCK_MONOTONIC unavailable, test may fail due to "
> +	       "external clock adjustments\n");
> +	return CLOCK_REALTIME;
> +}

Correct POSIX runtime detection — handles all three _POSIX_MONOTONIC_CLOCK
states (>0, ==0, undefined) properly, and the unistd.h include in helpers.h
closes the silent fallback that affected 1-1.c, 2-1.c, and 10000-1.c.

Reviewed-by: LTP AI Reviewer <ltp-ai@noreply.github.com>

---
Note:

Our agent completed the review of the patch.

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer


More information about the ltp mailing list