Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the double fork method to daemonize jailer #4259

Merged
merged 1 commit into from
Nov 24, 2023
Merged

Use the double fork method to daemonize jailer #4259

merged 1 commit into from
Nov 24, 2023

Conversation

wearyzen
Copy link
Contributor

@wearyzen wearyzen commented Nov 22, 2023

Changes

In addition to the CI tried running --daemonize manually as per steps mentioned in #4140 and didn't see the setsid error.

Reason

  • When running jailer with --daemonize, the jailer used to fail
    to start if it was started a process group leader, because setsid()
    returns an error if the calling process is already a process group
    leader.
    This was a common reported issue by users running jailer manually.
    Compared to maintaining a document which was rather difficult to
    understand and explain, it is easier to handle this case in jailer by not
    calling setsid when process id is same as process groud id (i.e. when
    jailer is not the process group leader).

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following
Developer Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • [ ] If a specific issue led to this PR, this PR closes the issue.
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • [ ] API changes follow the Runbook for Firecracker API changes.
  • [ ] User-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.
  • [ ] New TODOs link to an issue.
  • Commits meet contribution quality standards.

  • This functionality cannot be added in rust-vmm.

Copy link

codecov bot commented Nov 22, 2023

Codecov Report

Attention: 20 lines in your changes are missing coverage. Please review.

Comparison is base (fcd5269) 81.72% compared to head (7093090) 81.66%.

Files Patch % Lines
src/jailer/src/env.rs 0.00% 20 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4259      +/-   ##
==========================================
- Coverage   81.72%   81.66%   -0.07%     
==========================================
  Files         240      240              
  Lines       29266    29288      +22     
==========================================
  Hits        23917    23917              
- Misses       5349     5371      +22     
Flag Coverage Δ
4.14-c7g.metal 77.10% <0.00%> (-0.07%) ⬇️
4.14-m5d.metal 79.00% <0.00%> (-0.07%) ⬇️
4.14-m6a.metal 78.11% <0.00%> (-0.07%) ⬇️
4.14-m6g.metal 77.10% <0.00%> (-0.07%) ⬇️
4.14-m6i.metal 78.99% <0.00%> (-0.07%) ⬇️
5.10-c7g.metal 79.98% <0.00%> (-0.08%) ⬇️
5.10-m5d.metal 81.65% <0.00%> (-0.07%) ⬇️
5.10-m6a.metal 80.86% <0.00%> (-0.07%) ⬇️
5.10-m6g.metal 79.98% <0.00%> (-0.08%) ⬇️
5.10-m6i.metal 81.64% <0.00%> (-0.07%) ⬇️
6.1-c7g.metal 79.98% <0.00%> (-0.08%) ⬇️
6.1-m5d.metal 81.64% <0.00%> (-0.07%) ⬇️
6.1-m6a.metal 80.86% <0.00%> (-0.07%) ⬇️
6.1-m6g.metal 79.98% <0.00%> (-0.08%) ⬇️
6.1-m6i.metal 81.64% <0.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wearyzen wearyzen self-assigned this Nov 22, 2023
@wearyzen wearyzen changed the title fix: ignore setsid error when pid is same as pgid [jailer] call setsid only when jailer is not the process group leader Nov 23, 2023
@wearyzen wearyzen changed the title [jailer] call setsid only when jailer is not the process group leader jailer: call setsid only when jailer is not the process group leader Nov 23, 2023
@wearyzen wearyzen changed the title jailer: call setsid only when jailer is not the process group leader fix: call setsid only when jailer is not the process group leader Nov 23, 2023
@wearyzen wearyzen added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Nov 23, 2023
src/jailer/src/env.rs Outdated Show resolved Hide resolved
@wearyzen wearyzen changed the title fix: call setsid only when jailer is not the process group leader Use the double fork method to daemonize jailer Nov 23, 2023
@wearyzen wearyzen requested a review from pb8o November 24, 2023 08:14
pb8o
pb8o previously approved these changes Nov 24, 2023
src/jailer/src/env.rs Outdated Show resolved Hide resolved
src/jailer/src/env.rs Outdated Show resolved Hide resolved
kalyazin
kalyazin previously approved these changes Nov 24, 2023
@wearyzen wearyzen dismissed stale reviews from kalyazin and pb8o via d464286 November 24, 2023 11:28
src/jailer/src/env.rs Outdated Show resolved Hide resolved
src/jailer/src/env.rs Outdated Show resolved Hide resolved
Use the double fork method to daemonize jailer
as suggested in https://0xjet.github.io/3OHA/2022/04/11/post.html
1st fork to make sure setsid doesn't fail and 2nd fork is to
make sure the daemon code cannot reacquire a controlling terminal.

Signed-off-by: Sudan Landge <sudanl@amazon.com>
@wearyzen wearyzen merged commit da92bf6 into firecracker-microvm:main Nov 24, 2023
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting review Indicates that a pull request is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants