From: Marco Schlumpp Date: Wed, 30 Apr 2025 13:33:50 +0000 (+0200) Subject: lib/posix-process: Make rt_sitgimedwait stub block X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=417554a35ef8ec6487b8f7f8a78fe67a67813d2b;p=unikraft%2Funikraft.git lib/posix-process: Make rt_sitgimedwait stub block According to rt_sigtimedwait(2) the syscall should return a signal number on success (> 0) or -1 on failure, so the zero value currently returned by the stubbed implementation can be misinterpreted by applications that check against failure. Update the stub to return implementation to block and never return a signal. Co-authored-by: Michalis Pappas Signed-off-by: Marco Schlumpp Signed-off-by: Michalis Pappas Reviewed-by: Sergiu Moga Reviewed-by: Andrei Tatar Approved-by: Sergiu Moga GitHub-Closes: #1639 --- diff --git a/lib/posix-process/signal/rt_sigtimedwait.c b/lib/posix-process/signal/rt_sigtimedwait.c index bd7fbda47..4fe54762b 100644 --- a/lib/posix-process/signal/rt_sigtimedwait.c +++ b/lib/posix-process/signal/rt_sigtimedwait.c @@ -12,6 +12,11 @@ #include #include +#if !CONFIG_LIBPOSIX_PROCESS_SIGNAL +#include +#include +#endif /* !CONFIG_LIBPOSIX_PROCESS_SIGNAL */ + #include "process.h" #include "signal.h" @@ -64,9 +69,31 @@ UK_LLSYSCALL_R_DEFINE(int, rt_sigtimedwait, const struct timespec *, timeout, size_t, sigsetsize) { - UK_WARN_STUBBED(); + struct uk_thread *current = uk_thread_current(); + __nsec timeout_ns; + int rc; + + if (timeout) { + if (unlikely(!(uk_time_spec_canonical(timeout) && + uk_time_spec_positive(timeout)))) + return -EINVAL; + timeout_ns = ukplat_monotonic_clock() + + ukarch_time_sec_to_nsec(timeout->tv_sec) + + timeout->tv_nsec; + uk_thread_block_until(current, (__snsec)timeout_ns); + uk_sched_yield(); + rc = -EAGAIN; + } else { + uk_thread_block(current); + uk_sched_yield(); + /* If this ever returns then just return an EINTR to not + * confuse the application + */ + rc = -EINTR; + } + + /* We currently never return a signal */ *info = (siginfo_t){0}; - info->si_signo = SIGINT; - return 0; + return rc; } #endif /* !CONFIG_LIBPOSIX_PROCESS_SIGNAL */