From: Sergiu Moga Date: Thu, 20 Mar 2025 18:51:06 +0000 (+0200) Subject: lib/posix-process: Notify process/thread signal files when possible X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=755234d5d8a47bfa43563f127d0c2b2bbb238e7e;p=unikraft%2Funikraft.git lib/posix-process: Notify process/thread signal files when possible Whenever a signal shouldn't be dropped, meaning it is either not ignored by the process or the process has signal files that are monitoring that particular signal, notify the existing signal files in question of the posix thread/process by setting the input event on said files. Signed-off-by: Sergiu Moga Approved-by: Michalis Pappas Reviewed-by: Michalis Pappas Reviewed-by: Andrei Tatar GitHub-Closes: #1619 --- diff --git a/lib/posix-process/signal/signal.c b/lib/posix-process/signal/signal.c index 9758fee22..5e95f8832 100644 --- a/lib/posix-process/signal/signal.c +++ b/lib/posix-process/signal/signal.c @@ -196,6 +196,10 @@ int pprocess_signal_send(struct posix_process *proc, int signum, return -EAGAIN; } +#if CONFIG_LIBPOSIX_PROCESS_SIGNALFD + pprocess_signal_files_notify(proc, signum); +#endif /* CONFIG_LIBPOSIX_PROCESS_SIGNALFD */ + return 0; } @@ -231,7 +235,7 @@ int pprocess_signal_process_do(pid_t pid, int signum, siginfo_t *siginfo) if (!signal_check_perm(pproc)) continue; - if (IS_IGNORED(pproc, signum)) + if (pprocess_signal_should_drop(pproc, signum)) continue; rc = pprocess_signal_send(pproc, signum, siginfo); @@ -254,7 +258,7 @@ int pprocess_signal_process_do(pid_t pid, int signum, siginfo_t *siginfo) return 0; /* If this signal is currently ignored, don't even try */ - if (IS_IGNORED(pproc, signum)) + if (pprocess_signal_should_drop(pproc, signum)) return 0; rc = pprocess_signal_send(pproc, signum, siginfo); @@ -306,6 +310,10 @@ int pprocess_signal_thread_do(int tid, int signum, siginfo_t *siginfo) if (pthread->state == POSIX_THREAD_BLOCKED_SIGNAL) uk_semaphore_up(&pthread->signal->deliver_semaphore); +#if CONFIG_LIBPOSIX_PROCESS_SIGNALFD + pthread_signal_files_notify(pproc, pthread, signum); +#endif /* CONFIG_LIBPOSIX_PROCESS_SIGNALFD */ + return 0; } diff --git a/lib/posix-process/signal/signal.h b/lib/posix-process/signal/signal.h index b69888450..0f59c4474 100644 --- a/lib/posix-process/signal/signal.h +++ b/lib/posix-process/signal/signal.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -318,8 +319,51 @@ void pprocess_signal_file_del(struct posix_process *pproc, { uk_signal_files_ctx_del(&pproc->signal->sigfiles_ctx, sigf); } + +/* Notify the signal files of a process */ +static inline +void pprocess_signal_files_notify(struct posix_process *pproc, int signum) +{ + uk_signal_files_ctx_notify(&pproc->signal->sigfiles_ctx, signum); +} + +/* Notify the signal files of a thread */ +static inline +void pthread_signal_files_notify(struct posix_process *pproc, + struct posix_thread *pthread __unused, + int signum) +{ + /* + * TODO: Set file event for one specific thread only. + * We do it like this for now because we don't have individual + * thread notification yet + */ + uk_signal_files_ctx_notify(&pproc->signal->sigfiles_ctx, signum); +} #endif /* CONFIG_LIBPOSIX_PROCESS_SIGNALFD */ +/* + * Check if a signal should be dropped: it is ignored by the process and + * there are no signal files that are monitoring for this signal. + */ +#if CONFIG_LIBPOSIX_PROCESS_SIGNAL +#if CONFIG_LIBPOSIX_PROCESS_SIGNALFD +static inline +bool pprocess_signal_should_drop(struct posix_process *pproc, int signum) +{ + return IS_IGNORED(pproc, signum) && + !uk_signal_files_ctx_is_set(&pproc->signal->sigfiles_ctx, + signum); +} +#else /* !CONFIG_LIBPOSIX_PROCESS_SIGNALFD */ +static inline +bool pprocess_signal_should_drop(struct posix_process *pproc, int signum) +{ + return IS_IGNORED(pproc, signum); +} +#endif /* !CONFIG_LIBPOSIX_PROCESS_SIGNALFD */ +#endif /* CONFIG_LIBPOSIX_PROCESS_SIGNAL */ + #endif /* CONFIG_LIBPOSIX_PROCESS_PIDS */ #endif /* __UK_PROCESS_SIGNAL_H__ */