librc: fix service startup without pty & crash regressions - #1054
Merged
Merged
Conversation
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.
Member
|
thx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This MR fixes two regressions: