-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from ifd3f/refactor/rename-to-writer-process
Terminology change: rename "child" to "writer process"
- Loading branch information
Showing
17 changed files
with
186 additions
and
151 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
use burn::child::is_in_burn_mode; | ||
use run_mode::RunMode; | ||
|
||
mod burn; | ||
mod byteseries; | ||
mod compression; | ||
mod device; | ||
mod escalation; | ||
mod hash; | ||
mod logging; | ||
mod native; | ||
mod run_mode; | ||
mod ui; | ||
mod writer_process; | ||
|
||
fn main() { | ||
if is_in_burn_mode() { | ||
burn::child::main(); | ||
} else { | ||
ui::main::main(); | ||
match RunMode::detect() { | ||
RunMode::Main => ui::main::main(), | ||
RunMode::Writer => writer_process::child::main(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
pub const RUN_MODE_ENV_NAME: &str = "__CALIGULA_RUN_MODE"; | ||
|
||
/// [RunMode] is a flag set in the environment variable `__CALIGULA_RUN_MODE` | ||
/// to signal which process we are. | ||
/// | ||
/// # Motivation | ||
/// | ||
/// What we would ideally like to do is write code that looks like this, to | ||
/// escalate privileges: | ||
/// | ||
/// ``` | ||
/// let is_child_process = fork(); | ||
/// | ||
/// if is_child_process { | ||
/// if need_to_sudo { | ||
/// become_root(); | ||
/// } | ||
/// run_child_procedure(); | ||
/// } else { | ||
/// run_parent_procedure(); | ||
/// } | ||
/// ``` | ||
/// | ||
/// Unfortunately, the best we can do is call `sudo`/`doas`/`su` on ourself, | ||
/// and detect if we are the child process. | ||
/// | ||
/// Thus, this "private" environment variable and detection code is here to | ||
/// help us achieve that. | ||
/// | ||
/// *Why is this an environment variable instead of a CLI subcommand?* It's | ||
/// meant to be hidden from the user as much as possible. There is no reason | ||
/// that the user should ever set the run mode. | ||
#[derive(Debug, PartialEq, Eq, Clone, Copy)] | ||
pub enum RunMode { | ||
Main, | ||
Writer, | ||
} | ||
|
||
impl RunMode { | ||
pub fn detect() -> Self { | ||
match std::env::var(RUN_MODE_ENV_NAME).as_deref() { | ||
Ok("writer") => Self::Writer, | ||
_ => Self::Main, | ||
} | ||
} | ||
|
||
pub fn as_str(&self) -> &str { | ||
match self { | ||
RunMode::Main => "main", | ||
RunMode::Writer => "writer", | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.