Skip to content

Add setpgid for all called commands#1494

Merged
eikenb merged 2 commits into
masterfrom
child-set-process-group
Jul 28, 2021
Merged

Add setpgid for all called commands#1494
eikenb merged 2 commits into
masterfrom
child-set-process-group

Conversation

@eikenb
Copy link
Copy Markdown
Contributor

@eikenb eikenb commented Jul 27, 2021

Need to make sure signals are sent to all processes as sub-shells interfere with signal propagation. Using Setpgid to create a process group for the command and all it's subprocesses fixes this by allowing child to send the signals to the pgid, which thus gets sent to all processes in that group.

This is required for upcoming change to use sub-shells for all executed commands to eliminate need for shell parsing.

With this change it is always set to true and the pgid is always used to send signals to the process(es).

In the future it could be made configurable if needed.

Might be easier to review using the commits. The second commit is test cleanups and fixes where the first one contains the new code and tests.

@eikenb eikenb requested a review from a team July 27, 2021 23:01
@eikenb eikenb force-pushed the child-set-process-group branch from 41460d9 to 13b5204 Compare July 27, 2021 23:06
Copy link
Copy Markdown
Contributor

@findkim findkim left a comment

Choose a reason for hiding this comment

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

👍👍

Comment thread child/child.go Outdated
@eikenb eikenb force-pushed the child-set-process-group branch from 13b5204 to 306ce90 Compare July 28, 2021 18:49
eikenb added 2 commits July 28, 2021 11:58
Need to make sure signals are sent to all processes as sub-shells
interfere with signal propagation. Using Setpgid to create a process
group for the command and all it's subprocesses fixes this by allowing
child to send the signals to the pgid, which thus gets sent to all
processes in that group.

This is required for upcoming change to use sub-shells for all executed
commands to eliminate need for shell parsing.

With this change it is always set to true and the pgid is always used to
send signals to the process(es).

In the future it could be made configurable if needed.
Small issue with subshells sending text to STDERR about the signal
received, breaking the text check (result of sending signals to process
group). Changed them to only check STDOUT, where the test text is sent.

Previously used a sleep time of 500 milliseconds when 50 worked fine.
This sped up the child tests a lot.

Everything else are cleaning up lots of useless checks, hardcoded times,
and replace subshell test calls use of bash with standard /bin/sh.
@eikenb eikenb force-pushed the child-set-process-group branch from 306ce90 to 7d17648 Compare July 28, 2021 18:59
@eikenb eikenb merged commit 518b957 into master Jul 28, 2021
@eikenb eikenb deleted the child-set-process-group branch July 28, 2021 20:36
@eikenb eikenb added this to the 0.26.1 milestone Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants