casaroli opened a new pull request, #20468: URL: https://github.com/apache/nuttx/pull/20468
## Summary `exec()` swaps the pids of the caller and the new task, so that the new program keeps the pid of the caller. `exec_swap()` changes `tcb->pid` and `group->tg_pid`. But since 8bb67584906, `getpid()` and `gettid()` read copies in TLS (`tg_info->ta_pid` and `tl_tid`), and `exec_swap()` does not change them. So `getpid()` in the new program returns the pid that the caller has now, and `kill(getpid(), sig)` sends the signal to the caller. This change updates both copies for both tasks. Each task gets its update when its address environment is current: the new task right after the swap, the caller after `addrenv_restore()`. ## Impact Every `exec()` and `execve()` that does not spawn. Before this change, a program started by `exec()` in a flat build signals its caller when it signals itself, and in a kernel build a program sees its pid change across `execv()`. No API change. ## Testing Host: macOS arm64, Arm GNU Toolchain 15.3.rel1, QEMU 11.0.0. `lm3s6965-ek:qemu-nxflat` with apache/nuttx-apps#3803. The NXFLAT `signal` test sends SIGUSR1 to `getpid()`. Before, `getpid()` returns the pid of `nxflat_main`, which then gets the signal: ``` Setting up signal handlers from pid=12 Kill-ing SIGUSR1 from pid=12 SIGUSR1 not received ``` After, the module gets both signals and the test passes: ``` Setting up signal handlers from pid=10 siguser_action: Received signo=10 siginfo=0x20001138 arg=0 siguser_action: Received signo=12 siginfo=0x20001158 arg=0 Signal test PASSED ``` `qemu-armv7a:knsh` with a small program that calls `execv()` on itself and compares `getpid()` before and after: ``` before: pidexec: after execv getpid=5 gettid=5 expected=4 -> FAIL after: pidexec: after execv getpid=4 gettid=4 expected=4 -> PASS ``` `ostest` on `qemu-armv7a:knsh` ends with `ostest_main: Exiting with status 0`, before and after. `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]
