casaroli opened a new pull request, #22582:
URL: https://github.com/apache/nuttx/pull/22582

   ## Summary
   
   When a process stops (`SIGSTOP`, `SIGTSTP`, `SIGTTIN`, `SIGTTOU`), one 
thread gets the signal and `nxsched_suspend()` stops the other threads. A 
thread that waits for a signal (`sigtimedwait()`, `sigwaitinfo()`, 
`sigsuspend()`, `pause()`, `nanosleep()`) is taken out of its wait, but 
`nxsched_suspend()` does not write the siginfo of that wait. After `SIGCONT`, 
`nxsig_timedwait()` and `nxsig_clockwait()` read the cause of the wake from a 
siginfo that nothing wrote, so the wait gives a wrong result. The timeout of 
the wait also stays active and can end the next wait of the thread.
   
   This PR ends such a wait as a signal that the wait does not wait for: 
`nxsched_suspend()` writes `SIGSTOP` (`SI_USER`) into the siginfo, clears the 
wait set and cancels the timeout. The wait then fails with `EINTR`. For 
`sigtimedwait()` and `sigwaitinfo()` this is what Linux does (signal(7), 
"Interruption of system calls and library functions by stop signals").
   
   ## Impact
   
   `sched/sched/sched_suspend.c` only, under `CONFIG_SIG_SIGSTOP_ACTION` (the 
only caller of `nxsched_suspend()` is the stop action) and not 
`CONFIG_DISABLE_ALL_SIGNALS`. Shared code: the same in flat, protected and 
kernel builds, with and without SMP; no arch code.
   
   A thread of a stopped process that waits for a signal now always gets 
`EINTR` after `SIGCONT`. This includes `nanosleep()` and `clock_nanosleep()` in 
such a thread, which before returned an undefined result; Linux restarts those 
two, which this PR does not change. The thread that gets the stop signal does 
not change. No API changes.
   
   ## Testing
   
   New case `stop-sigwait` in `testing/sched/waitstop` (apache/nuttx-apps#N): a 
thread of a child waits in `sigtimedwait()` (3 s), another thread of the child 
gets `SIGSTOP`, the parent continues the child; the wait must fail with 
`EINTR`, and the next `sigwaitinfo()` of the thread must get the signal that 
the parent sends after the 3 s (the old timeout must not end it).
   
   Run on Fedora in the NuttX CI image (gcc, `-Wno-cpp -Werror`), QEMU on the 
host. "master" is apache/nuttx 1af7ac541e4 with the apps test; "this PR" adds 
this commit. The test configurations add `CONFIG_SIG_DEFAULT`, 
`CONFIG_SIG_SIGSTOP_ACTION`, `CONFIG_SCHED_HAVE_PARENT`, 
`CONFIG_SCHED_CHILD_STATUS`, `CONFIG_LIBC_EXECFUNCS` and 
`CONFIG_TESTING_WAITSTOP` where the defconfig does not have them.
   
   | Configuration | master: `stop-sigwait` | this PR: `stop-sigwait` | ostest |
   |---|---|---|---|
   | qemu-intel64:nsh (flat, x86_64, CMake, KVM) | FAIL: the first wait does 
not end with `EINTR` | PASS | exit status 0 |
   | qemu-intel64:knsh_romfs (kernel, x86_64, CMake, KVM) | FAIL: the old 
timeout ends the `sigwaitinfo()` | PASS | exit status 0 |
   | qemu-armv8a:nsh_smp (flat, SMP 2 CPUs, arm64, Make, TCG) | FAIL: the old 
timeout ends the `sigwaitinfo()` | PASS | exit status 0 |
   | rv-virt:knsh64 (kernel, riscv64, Make + export/import, TCG) | FAIL: the 
old timeout ends the `sigwaitinfo()` | PASS | exit status 0 |
   | rv-virt:pnsh64 (protected, riscv64) | - | builds | - |
   | qemu-armv8a:knsh (kernel, arm64) | - | builds | - |
   
   The other `waitstop` cases give the same result on master and with this PR. 
On qemu-intel64:knsh_romfs, `kill-stopped` fails on master and with this PR 
alike (not changed here).
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] sched/sched: End a signa... casaroli (via GitHub) via commits

Reply via email to