No daemon mode
- Move arg parsing on top of main function - Add support for --no-daemon argument - Fork the process only if --no-daemon was not passed (so forking is still the default)
This commit is contained in:
parent
79f0806958
commit
632b20f2e2
1 changed files with 34 additions and 28 deletions
62
src/main.rs
62
src/main.rs
|
|
@ -68,13 +68,41 @@ pub fn icon_cache_get(name: &'static str, size: u16) -> widget::icon::Icon {
|
|||
/// Runs application with these settings
|
||||
#[rustfmt::skip]
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut shell_program_opt = None;
|
||||
let mut shell_args = Vec::new();
|
||||
let mut parse_flags = true;
|
||||
let mut daemonize = true;
|
||||
for arg in env::args().skip(1) {
|
||||
if parse_flags {
|
||||
match arg.as_str() {
|
||||
// These flags indicate the end of parsing flags
|
||||
"-e" | "--command" | "--" => {
|
||||
parse_flags = false;
|
||||
}
|
||||
"--no-daemon" => {
|
||||
daemonize = false;
|
||||
}
|
||||
_ => {
|
||||
//TODO: should this throw an error?
|
||||
log::warn!("ignored argument {:?}", arg);
|
||||
}
|
||||
}
|
||||
} else if shell_program_opt.is_none() {
|
||||
shell_program_opt = Some(arg);
|
||||
} else {
|
||||
shell_args.push(arg);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(unix, not(target_os = "redox")))]
|
||||
match fork::daemon(true, true) {
|
||||
Ok(fork::Fork::Child) => (),
|
||||
Ok(fork::Fork::Parent(_child_pid)) => process::exit(0),
|
||||
Err(err) => {
|
||||
eprintln!("failed to daemonize: {:?}", err);
|
||||
process::exit(1);
|
||||
if daemonize {
|
||||
match fork::daemon(true, true) {
|
||||
Ok(fork::Fork::Child) => (),
|
||||
Ok(fork::Fork::Parent(_child_pid)) => process::exit(0),
|
||||
Err(err) => {
|
||||
eprintln!("failed to daemonize: {:?}", err);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,28 +127,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
};
|
||||
|
||||
let mut shell_program_opt = None;
|
||||
let mut shell_args = Vec::new();
|
||||
let mut parse_flags = true;
|
||||
for arg in env::args().skip(1) {
|
||||
if parse_flags {
|
||||
match arg.as_str() {
|
||||
// These flags indicate the end of parsing flags
|
||||
"-e" | "--command" | "--" => {
|
||||
parse_flags = false;
|
||||
}
|
||||
_ => {
|
||||
//TODO: should this throw an error?
|
||||
log::warn!("ignored argument {:?}", arg);
|
||||
}
|
||||
}
|
||||
} else if shell_program_opt.is_none() {
|
||||
shell_program_opt = Some(arg);
|
||||
} else {
|
||||
shell_args.push(arg);
|
||||
}
|
||||
}
|
||||
|
||||
let startup_options = if let Some(shell_program) = shell_program_opt {
|
||||
let options = tty::Options {
|
||||
shell: Some(tty::Shell::new(shell_program, shell_args)),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue