casaroli opened a new pull request, #4082: URL: https://github.com/apache/nuttx-apps/pull/4082
depends-on: apache/nuttx/pull/21987 ## Summary apache/nuttx-apps#4077 added `CONFIG_SYSTEM_NXINIT_UMASK`, an octal string. init checked the value at run time and reported a bad value only with `init_err()`. A review of #4077 noted that `init_err()` compiles out without the init error log, so init then keeps the umask 0 with no message. This PR checks the value at build time. The Make and CMake builds give a non-empty value to init.c as the octal constant `NXINIT_UMASK` (the build puts a `0` before the digits). In init.c, `#if` with `#error` stops the build when the value is less than 0 or more than 0777. A character that is not an octal digit stops the build in the same `#if`, because the constant is not a valid octal number. At run time, init only calls `umask(NXINIT_UMASK)`. The option stays a string, so that empty means "do not call `umask()`", and the usual form `022` stays. ## Impact No change for existing configurations: the default is empty, the build then gives no `NXINIT_UMASK`, and init does not call `umask()`. A valid value works as before. A bad value now stops the build, before it gave an error message at run time (only with the init error log) and init kept the umask. The code is in the init program only, the same in flat, protected and kernel builds. The documentation (Documentation/applications/system/nxinit/index.rst) does not describe a bad value, so it needs no change. ## Testing Build checks (the logs have the full messages). Make: qemu-armv8a:nsh (arm64, GCC 14.2.1) and sim:nsh (macOS host, Apple clang 21.0.0). CMake: qemu-armv8a:nsh (GCC 14.2.1, Ninja). | `CONFIG_SYSTEM_NXINIT_UMASK` | GCC | clang | |---|---|---| | empty | builds, no `NXINIT_UMASK` | builds | | `022`, `0022`, `0`, `777`, `0777` | builds | builds | | `1000`, `-1` | `#error "CONFIG_SYSTEM_NXINIT_UMASK must be an octal number from 0 to 777"` | the same `#error` | | `8` | `error: invalid digit "8" in octal constant` | `error: invalid digit '8' in octal constant` | | `abc` | `error: invalid suffix "abc" on integer constant` | `error: invalid digit 'a' in octal constant` | | `0x12` | `error: invalid suffix "x12" on integer constant` | `error: invalid suffix 'x12' on integer constant` | | ` 022` (a space before) | `error: missing binary operator before token "022"` | `error: token is not a valid binary operator in a preprocessor subexpression` | Each compiler error points at the `#if` line in init.c (GCC: "in expansion of macro 'NXINIT_UMASK'", clang: "expanded from macro 'NXINIT_UMASK'"). The CMake build ran `""`, `022`, `8`, `1000`, ` 022`, `0x12`, `-1`, `777`, `""`, `022` in one build directory, with the same results and messages as Make. The define follows the value, and it goes away again for the empty value. Run: qemu-armv8a:nsh (flat build, arm64, QEMU), Make build, with `CONFIG_FS_PERMISSION` (and `SCHED_USER_IDENTITY`, `PSEUDOFS_ATTRIBUTES`), so that tmpfs keeps the file modes. Commands in nsh: `mkdir /tmp/d`, `echo x > /tmp/f`, `ls -l /tmp`. | `CONFIG_SYSTEM_NXINIT_UMASK` | `/tmp/d` | `/tmp/f` | |---|---|---| | empty (default) | `drwxrwxrwx` | `-rw-rw-rw-` | | `022` | `drwxr-xr-x` | `-rw-r--r--` | Size (text, the same configuration, master -> this PR): with `022`, init.c 1084 -> 993 bytes and the image 371676 -> 371584 bytes. With the default, no change: init.c 985 bytes, the image 371516 bytes. The cmocka unit tests (`CONFIG_SYSTEM_NXINIT_TEST`) with `022`: the Make build builds, and `nxinit_unit_test` passes 22 of 22 tests in QEMU. The CMake build builds; there the define is only on the sources of init, not on those of `nxinit_unit_test`. tools/checkpatch.sh 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]
