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

   ## Summary
   
   POSIX requires that `waitpid()` returns the exit status of a child that 
exited before the parent waits for it. NuttX does this only with 
`CONFIG_SCHED_CHILD_STATUS`, which is off by default. Without it, `waitpid()` 
fails with `ECHILD` when the child exits first. In a kernel build this is a 
usual case: a program starts another program with `posix_spawn()`, or with 
`vfork()` and `exec()`, and the new program can exit before the parent calls 
`waitpid()`. After `vfork()`, a child that calls `_exit()` has always exited 
when the parent continues.
   
   This PR makes `CONFIG_SCHED_CHILD_STATUS` default to `y` in 
`CONFIG_BUILD_KERNEL`, and removes the line that is now redundant from the four 
kernel defconfigs that set it (imx93-evk:knsh, imx93-evk:koptee, 
qemu-intel64:knsh_romfs, qemu-intel64:knsh_romfs_pci). The Kconfig help, the 
task control reference and the fork()/vfork() guide say this.
   
   ## Impact
   
   - Kernel builds only. All 43 kernel defconfigs already select 
`CONFIG_SCHED_HAVE_PARENT`, and all of them now configure with 
`CONFIG_SCHED_CHILD_STATUS=y`. `make savedefconfig` gives the same defconfig 
for all of them, except three that differ already on master (a `CONFIG_HOST_*` 
line).
   - `waitpid()`, `wait()` and `waitid()` return the status of a child that 
already exited, instead of `ECHILD`.
   - Size: qemu-armv8a:knsh text +1584 bytes, bss +408 bytes (16 status entries 
that the kernel allocates at boot). rv-virt:knsh64 text +1042 bytes, bss +384 
bytes.
   - A parent that starts children and does not wait for them now keeps a small 
status entry in the kernel heap for each child, until it waits or exits. NSH 
did this for background commands and pipeline stages; the apps PR fixes it. A 
configuration that does not want this can set `# CONFIG_SCHED_CHILD_STATUS is 
not set`.
   
   ## Testing
   
   qemu-armv8a:knsh and qemu-armv8a:nsh under HVF.
   
   A test program checks `waitpid()` after `vfork()` + `exec()`, `vfork()` + 
`_exit()`, `posix_spawn()` and `fork()` + `exec()`. On knsh, master fails 3 of 
the 6 cases with `ECHILD`; this PR passes all of them:
   
   ```
   vforkexec: vfork + exec: waitpid(6)=6 errno 0 exited 1 status 42 (want 42): 
PASS
   vforkexec: vfork + exec ENOENT: waitpid(10)=10 errno 0 exited 1 status 127 
(want 127): PASS
   vforkexec: vfork + _exit(7): waitpid(11)=11 errno 0 exited 1 status 7 (want 
7): PASS
   vforkexec: PASS
   ```
   
   ostest passes on knsh and nsh (`Exiting with status 0`). With the apps PR, 
the kernel heap of knsh stays flat after 1500 background commands and 200 
pipelines in NSH; without it, it grows by one entry for each of them.
   
   Every kernel defconfig configures with `make olddefconfig`. qemu-armv8a:knsh 
and rv-virt:knsh64 build.
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   
   depends-on: [apache/nuttx-apps/pull/3889]
   


-- 
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]

Reply via email to