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

Introduce supervisor.procHandle interface #5137

Merged
merged 8 commits into from
Oct 23, 2024

Conversation

twz123
Copy link
Member

@twz123 twz123 commented Oct 22, 2024

Description

This encapsulates all OS-specific code for interacting with processes identified by PID files. This allows OS agnostic code parts to be shared across OSes, and it opens a way to more easily add Windows support in the future.

The OS specific features are:

  • Inspect the command line of a running process
  • Inspect the environment of a running process
  • Gracefully and forcibly terminate that process

The code has been refactored to first introduce freestanding functions for command line and environment inspection, then add a new type to which these functions have been moved and which is used by the OS agnostic methods. Finally, the methods have been moved out of platform-specific files, and the platform-specific files have been renamed to reflect that they belong to the new procHandle abstraction.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

  • Manual test
  • Auto test added

Checklist:

  • My code follows the style guidelines of this project
  • My commit messages are signed-off
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Add the cmdline and environ functions to it.

Signed-off-by: Tom Wieczorek <[email protected]>
This encapsulates the kill syscall.

Signed-off-by: Tom Wieczorek <[email protected]>
@twz123 twz123 added the chore label Oct 22, 2024
@twz123 twz123 marked this pull request as ready for review October 22, 2024 11:45
@twz123 twz123 requested review from a team as code owners October 22, 2024 11:45
Comment on lines 39 to 41
// killPid tries to gracefully terminate a PID. If it's still running after
// s.TimeoutStop the process will be terminated forcibly.
func (s *Supervisor) killPid(ph procHandle) error {
Copy link
Contributor

@juanluisvaladas juanluisvaladas Oct 22, 2024

Choose a reason for hiding this comment

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

I think it would make more sense to avoid the term PID entirely in this function because the interface is an abstraction that doesn't include the PID itself, even though it's there underneath.

Suggested change
// killPid tries to gracefully terminate a PID. If it's still running after
// s.TimeoutStop the process will be terminated forcibly.
func (s *Supervisor) killPid(ph procHandle) error {
// killProcess tries to gracefully terminate a Process. If it's still running after
// s.TimeoutStop the process will be terminated forcibly.
func (s *Supervisor) killProcess(ph procHandle) error {

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, done.

This encapsulates all of the OS-specific code for interacting with
processes identified by PID files.

Signed-off-by: Tom Wieczorek <[email protected]>
This will be the new factory function for OS-specific process
interaction.

Signed-off-by: Tom Wieczorek <[email protected]>
Move the now OS-agnostic Supervisor methods maybeKillPidFile,
shouldKillProcess and killPid from the UNIX-specific file into the
general one.

Signed-off-by: Tom Wieczorek <[email protected]>
The supervisor code is now completely OS independent. It uses the
procHandle interface to abstract away any OS specifics. Rename the
old OS-specific supervisor files to prochandle, since that's what they
contain now.

Signed-off-by: Tom Wieczorek <[email protected]>
@twz123 twz123 force-pushed the supervisor-prochandle branch from 1186969 to ceaa0f9 Compare October 23, 2024 09:07
@twz123 twz123 merged commit ba5c8d1 into k0sproject:main Oct 23, 2024
89 checks passed
@twz123 twz123 deleted the supervisor-prochandle branch October 23, 2024 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants