Skip to content

system/nxinit: Check CONFIG_SYSTEM_NXINIT_UMASK at build time. - #4082

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:fb-nxinit-umask-check-up
Nov 19, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:fb-nxinit-umask-check-up

Conversation

@casaroli

@casaroli casaroli commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#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.

init checked CONFIG_SYSTEM_NXINIT_UMASK at run time and reported a bad
value only with init_err().  Without init error logs, init then kept
the umask 0 with no message.

The Make and CMake builds now give the value to init.c as the octal
constant NXINIT_UMASK.  An #if with #error stops the build when the
value is less than 0 or more than 0777, and the compiler stops it when
the value has a character that is not an octal digit.  At run time,
init only calls umask() with the constant.  The default stays empty:
init then does not call umask().

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx-apps/actions/runs/44282204917

@casaroli
casaroli marked this pull request as draft November 18, 2026 14:15
@casaroli
casaroli marked this pull request as ready for review November 18, 2026 14:15
@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx-apps/actions/runs/44322318200

@xiaoxiang781216
xiaoxiang781216 merged commit 372b5b8 into apache:master Nov 19, 2026
70 of 78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants