]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-process: Notify process/thread signal files when possible
authorSergiu Moga <sergiu@unikraft.io>
Thu, 20 Mar 2025 18:51:06 +0000 (20:51 +0200)
committerUnikraft Bot <monkey@unikraft.io>
Wed, 23 Apr 2025 10:01:21 +0000 (10:01 +0000)
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 <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1619

lib/posix-process/signal/signal.c
lib/posix-process/signal/signal.h

index 9758fee222904329510ecfcffbaf0925a589738e..5e95f8832184163ec0b152c727140cfc716d4204 100644 (file)
@@ -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;
 }
 
index b69888450c112f16940fb8f0ae26e3e59c775e0d..0f59c44743f8ba238dd4c506dd474c992641e1c3 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <limits.h>
 #include <signal.h>
+#include <stdbool.h>
 
 #include <arch/signal.h>
 #include <uk/alloc.h>
@@ -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__ */