Skip to content

Process start OSAL abstraction using posix_spawn for QNX - Part 1 - #1023

Merged
NicolasFussberger merged 9 commits into
eclipse-score:mainfrom
etas-contrib:posix_spawn_impl
Nov 25, 2026
Merged

NicolasFussberger merged 9 commits into
eclipse-score:mainfrom
etas-contrib:posix_spawn_impl

Conversation

@NicolasFussberger

@NicolasFussberger NicolasFussberger commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Using posix_spawn on QNX yields much better performance compared to fork()+execve().
Therefore, we want to use posix_spawn on QNX and fork()+execve() on Linux.

This PR adds a OSAL function to start a process, which can have different implementations for QNX and Linux.
This PR provides the QNX-based implementation. The code is not actually used yet and will be wired in with a follow up PR.

Follow Up PRs:

  • Add the Linux-based implementation
  • Make use of the new OSAL function for process start

Detailed comparison of fork()+execve() vs posix_spawn (QNX-only)

Property (config) fork() + execve() (current) posix_spawn() (QNX, new) Difference
Executable / argv (process_command) access(X_OK) in the parent, then execve(executablePath, argv, envp) in the child posix_spawn(argv[0], …, argv, envp) (argv[0] is the executable path), no PATH lookup Same result. Exec errors (ENOENT, EACCES, …) are returned by posix_spawn() → kFail, instead of making the child exit with EXIT_FAILURE
Environment (environmental_variables) envp passed to execve() envp passed to posix_spawn() None
Comms fd (application_type ≠ Native) Child: dup2(fd, 111) + fcntl(F_SETFD, 0) to clear FD_CLOEXEC File action posix_spawn_file_actions_adddup2(fd, 111). The dup'ed fd is not FD_CLOEXEC Same result. Native processes get no comms fd in either case
Process group (implicit) Child: setpgid(0, getpid()) posix_spawnattr_setpgroup(0) + POSIX_SPAWN_SETPGROUP Same result
Signal dispositions / mask (implicit) Child: sigaction(SIG_DFL) for every signal except KILL/STOP, then pthread_sigmask(empty) posix_spawnattr_setsigdefault(all) + setsigmask(empty) (POSIX_SPAWN_SETSIGDEF | SETSIGMASK) Same result. There is no window between fork and reset in which Launch Manager's handlers run in the child
uid / gid (sandbox.uid, sandbox.gid) Child: setgid() → setgroups() → setuid() posix_spawnattr_setcred(uid, gid) + POSIX_SPAWN_SETCRED Same result. A failure makes posix_spawn() fail → kFail, no process is created
Supplementary groups (sandbox.supplementary_group_ids) Child: setgroups(n, list) before setuid(). Always called, so an empty list clears Launch Manager's groups Launch Manager: setgroupspid(n, list, pid) on the held process. Always called Same result. Applied by Launch Manager to another process instead of by the child to itself
Scheduling policy / priority (sandbox.scheduling_policy, sandbox.scheduling_priority) Child: sched_setscheduler(0, …) Launch Manager: sched_setscheduler(pid, …) on the held process. The spawn attribute is deliberately not used, to avoid priority inversion while posix_spawn() waits for the child to initialize Same priority: it is now clamped to sched_get_priority_min/max(policy) once at configuration load (with a warning) instead of in the forked child
CPU affinity (sandbox.affinity_mask, optional) Child: ThreadCtl(_NTO_TCTL_RUNMASK_GET_AND_SET_INHERIT) with runmask = inherit mask = configured mask (up to 64 CPUs) pthread_spawnattr_setrunmask_np(mask) (64 bit) + POSIX_SPAWN_EXPLICIT_CPU Set at process creation instead of before exec. Threads created later should inherit the mask, as they do with the explicit inherit mask on the fork path (to be confirmed)
Resource limits (sandbox.rlimits) Child: setrlimit() for each limit, before dropping privileges Launch Manager: prlimit(pid, …) for each limit on the held process Same limits, but set by Launch Manager on another process instead of by the child on itself
RLIMIT_STACK (in sandbox.rlimits) setrlimit() before execve(). The new image's main thread stack follows the limit Also posix_spawnattr_setstackmax(soft limit) + POSIX_SPAWN_SETSTACKMAX, because the main thread stack already exists while the process is held If the soft limit is RLIM_INFINITY or > 4 GiB, a warning is logged and the main thread gets the default stack size. The rlimit itself is still applied with prlimit()
Working directory (working_dir) Child: chdir(working_dir) after setuid(), so access is checked as the target uid Launch Manager opens the directory (O_RDONLY | O_DIRECTORY | O_CLOEXEC) and passes the fd via posix_spawnattr_setcwd_np() + POSIX_SPAWN_SETCWD, so access is checked as Launch Manager's uid A directory the target uid cannot access was rejected before and is now accepted. However, the child fails to access any files if its credentials do not allow it.
Security policy (sandbox.security_policy, optional) Child: secpol_transition_type(nullptr, name, 1) after setuid()/chdir(), just before execve(). ENOTSUP is ignored secpol_posix_spawnattr_settypeid(name, SECPOL_TYPE_NAME) (sets POSIX_SPAWN_SETTYPEID). kOperationNotSupported is ignored The process runs in its security type from the start, with no transition by the child. Launch Manager's policy must allow spawning into the type instead of the child's transition

Error handling and observable behavior

Aspect fork() + execve() (current) posix_spawn() (QNX, new)
Failure while preparing (attributes, open(working_dir), posix_spawn() itself) Child exits with EXIT_FAILURE. startProcess() already returned kSuccess startProcess() returns kFail, pid = -1, no process is created
Failure while configuring the held process (scheduling, groups, rlimits) n/a (all done in the child) SIGKILL sent to the held process, startProcess() returns kSuccess. Termination is reported through the normal path
Termination status seen by Launch Manager after a setup failure WIFEXITED, exit code 1 WIFSIGNALED, SIGKILL
Multiple failing settings setSchedulingAndSecurity() tries all settings and logs every failure, then exits Stops at the first failure
Logging signal_safe_log from the forked child (async-signal-safe only) Regular LM_LOG_* from Launch Manager, with the executable and pid
SIGCONT fails n/a Error logged and SIGKILL sent
fflush(stdout) before start Needed so buffered output is not duplicated Not needed
Order of application signals → comms fd → rlimits → pgid → scheduling → affinity → gid → groups → uid → chdir → secpol → exec At spawn: pgid, signals, affinity, uid/gid, stack max, cwd, security type, comms fd. While held: scheduling → groups → rlimits. Then SIGCONT

@github-actions

Copy link
Copy Markdown
Contributor

Documentation preview for this pull request is available at:
pr-1023: https://eclipse-score.github.io/lifecycle/pr-1023/

@paulquiring

Copy link
Copy Markdown
Contributor

Move "Detailed comparison of fork()+execve() vs posix_spawn (QNX-only)" from PR description to a markdown file in the osal folder.

@paulquiring paulquiring left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed in telco.

common:codeql --noremote_accept_cached
common:codeql --noremote_upload_local_results
common:codeql --disk_cache=
common:codeql --skip_incompatible_explicit_targets

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like QNX code might be missing from our CodeQL report?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we'll need another codeql target for QNX eventually. But it seems at the moment it is accepted to run CodeQL only for Linux

@NicolasFussberger

Copy link
Copy Markdown
Contributor Author

Move "Detailed comparison of fork()+execve() vs posix_spawn (QNX-only)" from PR description to a markdown file in the osal folder.

I know added a design decision that also links to this comparison table.
We do not yet have a proper detailed design for the launch manager component, so currently our design decisions are on the feature level.

Later, we would pull them down to the component level

@SimonKozik SimonKozik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good enough for first step

@NicolasFussberger
NicolasFussberger added this pull request to the merge queue Nov 25, 2026
Merged via the queue into eclipse-score:main with commit 2e23040 Nov 25, 2026
23 of 25 checks passed
@NicolasFussberger
NicolasFussberger deleted the posix_spawn_impl branch November 25, 2026 09:23
@github-project-automation github-project-automation Bot moved this from Backlog to Done in LCM - Lifecycle & Health FT Nov 25, 2026

This branch is waiting to be deployed

1 waiting deployment
workflow-approval — 180f22fc Waiting Nov 24, 2026 by NicolasFussberger via Build and test x86_64-qnx / approval #2753
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants