casaroli opened a new pull request, #21726: URL: https://github.com/apache/nuttx/pull/21726
## Summary Three small C library fixes, one commit each, plus one whitespace commit and one cleanup commit: - `libs/libm/libm/lib_gamma.c`: GCC 16 has the C23 function `sinpi()` as a built-in. The static helper `sinpi()` of `lib_gamma.c` shadows it, and a build with `-Werror` and the NuttX libm stops: `declaration of 'sinpi' shadows a built-in function [-Werror=shadow]`. The helper is now `sin_pi()`, the name of the same helper in `lib_lgamma.c`. A first commit fixes the indentation of the `switch` in that helper (nxstyle "Bad alignment"), with no code change. - `libs/libc/unistd` `execvp()`: POSIX says that `execlp()`, `execvp()` (and `execvpe()`) run a file that `execve()` refuses with `ENOEXEC` (a shell script without `#!`, an empty file) with the shell, with the file and the arguments after `argv[0]`. NuttX returned the error. `execvpe()` now calls `execve()` again with the shell on `ENOEXEC`: `sh` from `PATH` with `CONFIG_LIBC_ENVPATH` (as `popen()` does), else `_PATH_BSHELL`. `execvp()` calls `execvpe()`, `execlp()` calls `execvp()`. `execl()`, `execv()` and `execve()` do not change. - `libs/libc/unistd` `daemon()`: `daemon()` did not fork; it "pretended" that it forked. With `CONFIG_ARCH_HAVE_FORK` (kernel build with address environments) the caller stayed the child of its parent, so a shell that starts a daemon waited until the daemon ended. With `CONFIG_ARCH_HAVE_FORK`, `daemon()` now forks as glibc and the BSDs do: the parent calls `_exit(0)`, the child calls `setsid()`, then the `chdir()` and the redirection as before. Without `fork()` the code does not change. - `lib_exit.c`, `lib_daemon.c`: the guard `defined(CONFIG_BUILD_FLAT) || !defined(__KERNEL__)` is now `!defined(__KERNEL__)`, as in the other user-only files of libc. A flat build compiles libc without `__KERNEL__` with make and with CMake (since 9eac74330ae), so the `CONFIG_BUILD_FLAT` test has no effect. ## Impact - `lib_gamma.c`: a rename of a static function; no behavior change. - `execvp()`, `execlp()`, `execvpe()`: a file that is not a program now runs with the shell, in all build modes. Before, the call returned -1 with `ENOEXEC`. A program that relied on that error now gets the shell; if the shell does not start, the call returns -1 with the errno of the shell's `execve()`. `execl()`, `execv()` and `execve()` still return `ENOEXEC`. - `daemon()`: changes only with `CONFIG_ARCH_HAVE_FORK`, which needs `CONFIG_ARCH_ADDRENV`, so only kernel builds (arm64, armv7-a, RISC-V, x86_64, Xtensa). Flat and protected builds compile the same code as before (the flat `daemon()` is 0xa4 bytes on master and with this PR). The only caller in apps (`testing/drivers/nand_sim`) calls `daemon()` from its `main()`, so in a kernel build its parent now returns at once. `setsid()` is a stub in NuttX today (it returns the PID); `daemon()` calls it as the other systems do. - `lib_exit.c`, `lib_daemon.c` guards: no change in any build (see Testing). - No Kconfig, ABI or documentation change: no page in Documentation/ describes `execvp()`, `execlp()` or `daemon()`. ## Testing Test programs: `execvpsh.c` (fork, then `execvp()`/`execlp()`/`execv()` of an empty file, of a script without `#!` by path and by bare name in `PATH`, of a missing file), `daemonfork.c` (a child calls `daemon(1, 1)`: it must end at once with status 0, and the daemon is another process), and `libsfxflat.c` for the flat build (no `fork()`: it starts itself again with `posix_spawn()`; a copy of it is `/system/bin/sh` and writes its arguments to a file; `daemon(0, 1)` must return in the same task, which goes on and sees `/` as its directory). | Configuration | master 3117ab10467 | this PR | |---|---|---| | `qemu-armv8a:knsh` (kernel, arm64, QEMU HVF), execvpsh | empty, script, bare, execlp FAIL: the child exits with `ENOEXEC`; execv, noent PASS | 6 PASS; args SKIP (NSH has no `$1`) | | `qemu-armv8a:knsh`, daemonfork | return FAIL (the child does not end), newpid FAIL (same PID), session PASS | 3 PASS | | `qemu-armv8a:nsh` (flat, ELF programs with the system symbol table), libsfxflat | script, bare FAIL (`ENOEXEC`); execv, noent, daemon PASS | 5 PASS (the shell gets `/system/libsfx.d/script a1`) | ostest: exit status 0 on `qemu-armv8a:knsh` and `qemu-armv8a:nsh` (also the flat ELF image), on master and with this PR. Builds with `EXTRAFLAGS="-Wno-cpp -Werror"`, no warning: `qemu-armv8a:knsh` (kernel, arm64), `qemu-armv8a:nsh` (flat, arm64, `ELF`), `rv-virt:knsh64` (kernel, RISC-V), `qemu-armv7a:knsh` (kernel, armv7-a), `mps2-an500:knsh` (protected, armv7-m), each with `LIBC_EXECFUNCS` and `LIBC_ENVPATH`. GCC 16 (Homebrew x86_64-elf-gcc 16.2.0 and arm-none-eabi-gcc 16.2.0) with the NuttX libm (`CONFIG_LIBM`) and `-Werror`: `qemu-intel64:nsh` and `mps2-an500:nsh` stop on master with `lib_gamma.c: error: declaration of 'sinpi' shadows a built-in function [-Werror=shadow]`, and build with this PR. The GCC of the CI is older and has no `sinpi()` built-in, so the CI does not show the error. Guard cleanup: `exit()` and `daemon()` are in `libc.a` of `qemu-armv8a:nsh` (flat, make and CMake) and of `mps2-an500:knsh` (protected), and not in its `libkc.a`, as on master. `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]
