-
Notifications
You must be signed in to change notification settings - Fork 79
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 fork
and exec
for the command
#468
Conversation
Number of dependencies and binary size impact report
Dependencies diff └─ sudo [v0.1.0-alpha.1]
├─ env_logger [v0.9.3]
| └─ log [v0.4.17]
| └─ cfg-if [v1.0.0]
├─ glob [v0.3.1]
├─ libc [v0.2.144]
├─ log [v0.4.17]
├─ signal-hook [v0.3.15]
| ├─ libc [v0.2.144]
| ├─ signal-hook-registry [v1.4.1]
| | └─ libc [v0.2.144]
| └─ cc [v1.0.79]
└─ signal-hook-registry [v1.4.1] |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #468 +/- ##
==========================================
+ Coverage 82.77% 82.93% +0.15%
==========================================
Files 52 52
Lines 6852 6961 +109
==========================================
+ Hits 5672 5773 +101
- Misses 1180 1188 +8
☔ View full report in Codecov by Sentry. |
9d5f1bd
to
21c7d8b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
err | ||
})?; | ||
|
||
let command_pid = command.id() as ProcessId; | ||
if command_pid == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this pattern comes up often when fork
-ing. perhaps the signature of fork
could be changed to take a child closure then this if ret == 0
can be moved into the body of the fork
function. not something that needs to be addressed in this PR; just an idle though
@@ -47,6 +54,9 @@ pub(super) fn exec_monitor( | |||
err | |||
})?; | |||
|
|||
// Use a pipe to get the IO error if `exec_command` fails. | |||
let (mut errpipe_tx, errpipe_rx) = UnixStream::pair()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idle thought: this binary serialization over a pipe comes up in other places. perhaps a bit of abstraction could help with the buffer sizes and ser/de steps, e.g. Pipe<T: BinSerDe>
, impl BinSerDef for i32 { const NUM_BYTES: usize = 4; /* .. */
, Pipe::write(val: &T)
, Pipe::read() -> io::Result<T>
, etc.
21c7d8b
to
1e8b055
Compare
Describe the changes done on this pull request
This PR uses
fork
andCommand::exec
to run the command instead of usingCommand::spawn
. This is done because we need to set the command's process group as the foreground process group for the terminal and we cannot execute the command until it is set.We cannot use
Command::pre_exec
to wait for the foreground process group to be set before executing the command because the monitor process will get stuck asCommand::spawn
will block until all theCommand::pre_exec
closures are executed.This PR also adds the new concept of "exit reason" for the event loop. The main difference between an exit and a break is that setting the loop to break will stop the loop after the current callback is done, meanwhile setting the loop to exit will stop the loop after all the callbacks for the events that have already been polled are done. Meaning that "exit" is the "nice" way to stop the event loop.
This is another chunk of #363 and it is blocked by #467.
Pull Request Checklist