Skip to content

librc: fix service startup without pty & crash regressions - #1054

Merged
navi-desu merged 2 commits into
OpenRC:masterfrom
pva:service-startup-without-PTY
Jul 28, 2026
Merged

navi-desu merged 2 commits into
OpenRC:masterfrom
pva:service-startup-without-PTY

Conversation

@pva

@pva pva commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

This MR fixes two regressions:

  • Continue service startup when openpty() fails, restoring the behavior from before 39eb8a9.
  • Avoid a crash during failure cleanup introduced by 68b0570.

pva added 2 commits July 28, 2026 23:55
PTY allocation was introduced by 45bd125 as an optional way to prefix
service output. Both that commit and the adjacent comment explicitly
state that service startup should continue without prefixes when no PTY
is available.

Commit d9b1e65 converted svc_exec() to posix_spawn() but queued dup2
actions even when openpty() failed and left slave_tty at -1.

Commit 39eb8a9 introduced regression - it started checking the result,
turning the failed PTY allocation into an EBADF service startup failure.

Only add the stdout and stderr file actions when openpty() succeeds.
Otherwise, let the service inherit the original output descriptors.

To reproduce, enable rc_parallel, run a test service from a terminal,
and make devpts unavailable in a private mount namespace:

    # unshare --mount --fork sh
    # mount --make-rprivate /
    # umount -l /dev/pts
    # cat >/etc/init.d/openpty-fallback-test <<'EOF'
      #!/sbin/openrc-run

      start()
      {
              ebegin "Starting PTY fallback test"
              printf '%s\n' "start() was reached"
              : > /run/openpty-fallback.started
              eend $?
      }
      EOF
    # rc-service openpty-fallback-test start
    openpty-fallback-test     | * openpty-fallback-test: posix_spawn_file_actions_adddup2: Bad file descriptor
    openpty-fallback-test     | * ERROR: openpty-fallback-test failed to start
    Segmentation fault         rc-service openpty-fallback-test start

Before this change, rc-service fails with "Bad file descriptor" and the
marker is not created.

BTW, Segmentation fault is interesting and will be fixed later.
free_rc_dirs() freed the allocation backing rc_path.entries but left the
non-owning pointer unchanged. A later rc_scriptdirs() therefore returned
the freed array instead of rebuilding the path, causing a crash.

This is a regression from 68b0570.
@pva pva changed the title Fix service startup without pty & crash regressions fix service startup without pty & crash regressions Jul 28, 2026
@pva pva changed the title fix service startup without pty & crash regressions librc: fix service startup without pty & crash regressions Jul 28, 2026
@navi-desu
navi-desu merged commit 2fed7e0 into OpenRC:master Jul 28, 2026
5 checks passed
@navi-desu

Copy link
Copy Markdown
Member

thx

@pva
pva deleted the service-startup-without-PTY branch July 29, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants