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 d3098f153 system/nxinit: Add an option to set the umask at start.
d3098f153 is described below
commit d3098f1531f58d5b70f1494b2605369e04e6096d
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Nov 2 12:30:49 2026 +0100
system/nxinit: Add an option to set the umask at start.
NuttX starts the first task with the umask 0, and init keeps it, so
every command and service inherits it. Files and directories that
programs create with mode 0666 or 0777 can then be written by all
users, where the file system keeps file modes. Some programs refuse
to run in this case: sshd stops with "/run/sshd must be owned by root
and not group or world-writable".
Add CONFIG_SYSTEM_NXINIT_UMASK, an octal string. init calls umask()
with it at the start of main(), before it starts anything. A bad
value gives an error message, and init keeps the umask.
The default is empty: init keeps the umask that it got, so no board
changes. A system with file permissions can set "022", as sysvinit
and systemd do.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
system/nxinit/Kconfig | 11 +++++++++++
system/nxinit/init.c | 19 +++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/system/nxinit/Kconfig b/system/nxinit/Kconfig
index 54bfaadb4..84f34aef2 100644
--- a/system/nxinit/Kconfig
+++ b/system/nxinit/Kconfig
@@ -28,6 +28,17 @@ config SYSTEM_NXINIT_PROGNAME
string "Program name"
default "init"
+config SYSTEM_NXINIT_UMASK
+ string "File mode creation mask"
+ default ""
+ ---help---
+ The umask (octal) that init sets when it starts. Every command
+ and service of init inherits it. Empty: init keeps the umask
that
+ it got (NuttX starts the first task with the umask 0). A system
+ 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.
+
comment "NXInit Run Control(RC)"
config SYSTEM_NXINIT_RC_FILE_PATH
diff --git a/system/nxinit/init.c b/system/nxinit/init.c
index 7dbace1b8..4b966b44f 100644
--- a/system/nxinit/init.c
+++ b/system/nxinit/init.c
@@ -32,9 +32,11 @@
#include <sched.h>
#include <stdio.h>
#include <signal.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/boardctl.h>
#include <sys/param.h>
+#include <sys/stat.h>
#include <sys/wait.h>
#include <nuttx/usb/usbdev_trace.h>
@@ -242,10 +244,27 @@ 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;
+ /* 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);
+ }
+ }
+
#ifdef CONFIG_BMP
snprintf(ACTION_TRIGGER_KEY(&am), sizeof(ACTION_TRIGGER_KEY(&am)),
ACTION_PROP_KEY_TRIGGER ".core%d", sched_getcpu());