This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 372b5b8b8 system/nxinit: Check CONFIG_SYSTEM_NXINIT_UMASK at build
time.
372b5b8b8 is described below
commit 372b5b8b8da7ece9519979af26a0feda0a9b985a
Author: Marco Casaroli <[email protected]>
AuthorDate: Wed Nov 18 10:33:49 2026 +0100
system/nxinit: Check CONFIG_SYSTEM_NXINIT_UMASK at build time.
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 <[email protected]>
---
system/nxinit/CMakeLists.txt | 9 +++++++++
system/nxinit/Kconfig | 1 +
system/nxinit/Makefile | 6 ++++++
system/nxinit/init.c | 29 ++++++++++++++---------------
4 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/system/nxinit/CMakeLists.txt b/system/nxinit/CMakeLists.txt
index c6df81f18..fec98898e 100644
--- a/system/nxinit/CMakeLists.txt
+++ b/system/nxinit/CMakeLists.txt
@@ -26,6 +26,13 @@ if(CONFIG_SYSTEM_NXINIT)
list(APPEND CSRCS property_simple.c)
+ # The umask as an octal constant, so that init.c can check it with #if
+
+ set(DEFS)
+ if(NOT "${CONFIG_SYSTEM_NXINIT_UMASK}" STREQUAL "")
+ list(APPEND DEFS NXINIT_UMASK=0${CONFIG_SYSTEM_NXINIT_UMASK})
+ endif()
+
nuttx_add_application(
MODULE
${CONFIG_SYSTEM_NXINIT}
@@ -35,6 +42,8 @@ if(CONFIG_SYSTEM_NXINIT)
${CONFIG_SYSTEM_NXINIT_STACKSIZE}
PRIORITY
${CONFIG_SYSTEM_NXINIT_PRIORITY}
+ DEFINITIONS
+ ${DEFS}
SRCS
${CSRCS})
diff --git a/system/nxinit/Kconfig b/system/nxinit/Kconfig
index 84f34aef2..d6fee2d11 100644
--- a/system/nxinit/Kconfig
+++ b/system/nxinit/Kconfig
@@ -38,6 +38,7 @@ config SYSTEM_NXINIT_UMASK
with file permissions (FS_PERMISSION) can set "022", as sysvinit
and systemd do, so that files and directories created with mode
0666 or 0777 are not writable by all users.
+ A value that is not an octal number from 0 to 777 stops the
build.
comment "NXInit Run Control(RC)"
diff --git a/system/nxinit/Makefile b/system/nxinit/Makefile
index 095302c13..7bf1f9055 100644
--- a/system/nxinit/Makefile
+++ b/system/nxinit/Makefile
@@ -37,6 +37,12 @@ PRIORITY += $(CONFIG_SYSTEM_NXINIT_PRIORITY)
STACKSIZE += $(CONFIG_SYSTEM_NXINIT_STACKSIZE)
MODULE = $(CONFIG_SYSTEM_NXINIT)
+# The umask as an octal constant, so that init.c can check it with #if
+
+ifneq ($(CONFIG_SYSTEM_NXINIT_UMASK),"")
+CFLAGS += ${DEFINE_PREFIX}NXINIT_UMASK=0$(patsubst
"%",%,$(CONFIG_SYSTEM_NXINIT_UMASK))
+endif
+
# NxInit unit tests (cmocka), reusing the same parser/action/service CSRCS
# built above.
diff --git a/system/nxinit/init.c b/system/nxinit/init.c
index 4b966b44f..77b2a8e01 100644
--- a/system/nxinit/init.c
+++ b/system/nxinit/init.c
@@ -32,7 +32,6 @@
#include <sched.h>
#include <stdio.h>
#include <signal.h>
-#include <stdlib.h>
#include <string.h>
#include <sys/boardctl.h>
#include <sys/param.h>
@@ -59,6 +58,17 @@
#define INIT_POLLER_RETRY_MS 100
+/* The build gives NXINIT_UMASK, the octal value of a non-empty
+ * CONFIG_SYSTEM_NXINIT_UMASK. A digit that is not octal stops the build
+ * in the #if below.
+ */
+
+#ifdef NXINIT_UMASK
+# if NXINIT_UMASK < 0 || NXINIT_UMASK > 0777
+# error "CONFIG_SYSTEM_NXINIT_UMASK must be an octal number from 0 to 777"
+# endif
+#endif
+
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -244,26 +254,15 @@ int main(int argc, FAR char *argv[])
#ifdef CONFIG_ENABLE_ALL_SIGNALS
struct sigaction sa;
#endif
- unsigned long cmask;
- FAR char *end;
sigset_t mask;
size_t i;
int r;
+#ifdef NXINIT_UMASK
/* The file mode creation mask of every command and service */
- if (CONFIG_SYSTEM_NXINIT_UMASK[0] != '\0')
- {
- cmask = strtoul(CONFIG_SYSTEM_NXINIT_UMASK, &end, 8);
- if (*end != '\0' || cmask > 0777)
- {
- init_err("Bad umask %s", CONFIG_SYSTEM_NXINIT_UMASK);
- }
- else
- {
- umask(cmask);
- }
- }
+ umask(NXINIT_UMASK);
+#endif
#ifdef CONFIG_BMP
snprintf(ACTION_TRIGGER_KEY(&am), sizeof(ACTION_TRIGGER_KEY(&am)),