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

Replace launcher's Process struct's unsafe implementations with rust stdlib #5733

Merged
merged 4 commits into from
Oct 11, 2018

Conversation

baumanj
Copy link
Contributor

@baumanj baumanj commented Oct 10, 2018

Now that try and try_wait exist, Process can be a thin wrapper around
std::process::Child on unix. Unfortunately, the same isn't currently feasible
on Windows, since the process spawning depends on additional features not
available in the rust stdlib currently.

Also, fix some typos.

Resolves #5361

…stdlib

Now that try and try_wait exist, Process can be a thin wrapper around
std::process::Child on unix. Unfortunately, the same isn't currently feasible
on Windows, since the process spawning depends on additional features not
available in the rust stdlib currently.

Also, fix some typos.

Resolves #5361

Signed-off-by: Jon Bauman <5906042+baumanj@users.noreply.github.com>
@thesentinels
Copy link
Contributor

Thanks for the pull request! Here is what will happen next:

  1. Your PR will be reviewed by the maintainers
  2. If everything looks good, one of them will approve it, and your PR will be merged.

Thank you for contributing!

pub use sys::service::*;

pub struct Service {
args: protocol::Spawn,
process: Process,
status: Option<ExitStatus>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this field was never mutated, so removing it should be safe

@@ -25,7 +24,7 @@ impl Handler for RestartHandler {
type Reply = protocol::SpawnOk;

fn handle(msg: Self::Message, services: &mut ServiceTable) -> HandleResult<Self::Reply> {
let mut service = match services.remove(msg.get_pid() as Pid) {
let mut service = match services.remove(msg.get_pid() as u32) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like descriptive types as much as the next person, but std::process::Child::id() returns a u32, so I think it's preferable to align with the stdlib. This ripples out in a number of places, but also requires some casts since certain libc calls take i32.

}
}
pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
self.0.try_wait()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

}
}
pub fn wait(&mut self) -> io::Result<ExitStatus> {
self.0.wait()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@christophermaier christophermaier left a comment

Choose a reason for hiding this comment

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

tenor-131370618

Signed-off-by: Jon Bauman <5906042+baumanj@users.noreply.github.com>
And only include use libc for unix to avoid warning
Signed-off-by: Jon Bauman <5906042+baumanj@users.noreply.github.com>
Signed-off-by: Jon Bauman <5906042+baumanj@users.noreply.github.com>
@baumanj baumanj merged commit 7c42148 into master Oct 11, 2018
@baumanj baumanj deleted the replace-unsafe-with-stdlib-take2/5361 branch October 11, 2018 14:37
chef-ci added a commit that referenced this pull request Oct 11, 2018
Obvious fix; these changes are the result of automation not creative thinking.
@christophermaier christophermaier added Type:BugFixes PRs that fix an existing bug and removed X-fix labels Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type:BugFixes PRs that fix an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unsafe, platform-specific Process struct is obviated by rust stdlib now
3 participants