From 7942d18fd57810288b7f14d8a5076afcfe33781d Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Fri, 9 Oct 2026 08:17:00 +0200 Subject: [PATCH] sched/task: Do not log a missing or unloadable program as an exec error. posix_spawn() and execve() logged every failed exec at error level. A shell normally tries a program first: NSH with CONFIG_NSH_FILE_APPS spawns each command from PATH before its built-in command, and bash runs a script itself when execve() returns ENOEXEC. So every built-in NSH command printed nxposix_spawn_exec: ERROR: exec failed: 2 although nothing was wrong. The caller gets the error code and reports it if it needs to. Do not log ENOENT and ENOEXEC. Other errors are logged as before. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli --- sched/task/task_execve.c | 12 +++++++++++- sched/task/task_posixspawn.c | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/sched/task/task_execve.c b/sched/task/task_execve.c index f070ce29513..0971509a33c 100644 --- a/sched/task/task_execve.c +++ b/sched/task/task_execve.c @@ -128,7 +128,17 @@ int execve(FAR const char *path, FAR char * const argv[], ret = exec(path, argv, envp, symtab, nsymbols); if (ret < 0) { - serr("ERROR: exec failed: %d\n", get_errno()); + /* No such program (ENOENT) or not a loadable format (ENOEXEC) is an + * ordinary result for the caller, for example a shell that runs a + * script itself when execve() cannot. + */ + + ret = get_errno(); + if (ret != ENOENT && ret != ENOEXEC) + { + serr("ERROR: exec failed: %d\n", ret); + } + return ERROR; } diff --git a/sched/task/task_posixspawn.c b/sched/task/task_posixspawn.c index cc896c75717..b94b5d1f4c6 100644 --- a/sched/task/task_posixspawn.c +++ b/sched/task/task_posixspawn.c @@ -110,7 +110,17 @@ static int nxposix_spawn_exec(FAR pid_t *pidp, FAR const char *path, if (pid < 0) { ret = -pid; - serr("ERROR: exec failed: %d\n", ret); + + /* No such program (ENOENT) or not a loadable format (ENOEXEC) is an + * ordinary result for the caller, for example a shell that tries a + * program before its built-in command. + */ + + if (ret != ENOENT && ret != ENOEXEC) + { + serr("ERROR: exec failed: %d\n", ret); + } + return ret; }