Deamonize nvim-gtk by default

--no-fork can be passed for normal behavior
This commit is contained in:
Julian Ospald 2018-06-15 21:42:40 +02:00
parent 21e74c7ca7
commit 53cde1c2b8
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
3 changed files with 30 additions and 0 deletions

10
Cargo.lock generated
View File

@ -369,6 +369,7 @@ dependencies = [
"toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"unix-daemonize 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -677,6 +678,14 @@ name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unix-daemonize"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unix_socket"
version = "0.5.0"
@ -803,6 +812,7 @@ dependencies = [
"checksum unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8083c594e02b8ae1654ae26f0ade5158b119bd88ad0e8227a5d8fcd72407946"
"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unix-daemonize 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "531faed80732acaa13d1016c66d6a9180b5045c4fcef8daa20bb2baf46b13907"
"checksum unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6aa2700417c405c38f5e6902d699345241c28c0b7ade4abaad71e35a87eb1564"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"

View File

@ -36,6 +36,7 @@ regex = "0.2"
lazy_static = "1.0"
unicode-width = "0.1.4"
unicode-segmentation = "1.2.0"
unix-daemonize = "0.1"
serde = "1.0"
serde_derive = "1.0"

View File

@ -1,5 +1,6 @@
#![windows_subsystem = "windows"]
extern crate unix_daemonize;
extern crate cairo;
extern crate env_logger;
extern crate gdk;
@ -63,6 +64,7 @@ mod file_browser;
mod subscriptions;
mod misc;
use unix_daemonize::{daemonize_redirect, ChdirMode};
use std::env;
use std::io::Read;
use std::cell::RefCell;
@ -77,6 +79,7 @@ use shell::ShellOptions;
const BIN_PATH_ARG: &str = "--nvim-bin-path";
const TIMEOUT_ARG: &str = "--timeout";
const DISABLE_WIN_STATE_RESTORE: &str = "--disable-win-restore";
const NO_FORK: &str = "--no-fork";
fn main() {
env_logger::init();
@ -108,7 +111,23 @@ fn main() {
.filter(|a| !a.starts_with(BIN_PATH_ARG))
.filter(|a| !a.starts_with(TIMEOUT_ARG))
.filter(|a| !a.starts_with(DISABLE_WIN_STATE_RESTORE))
.filter(|a| !a.starts_with(NO_FORK))
.collect();
// fork to background by default
let want_fork = env::args()
.take_while(|a| *a != "--")
.skip(1)
.find(|a| a.starts_with(NO_FORK))
.is_none();
if want_fork {
daemonize_redirect(Some("/tmp/nvim-gtk_stdout.log"),
Some("/tmp/nvim-gtk_stderr.log"),
ChdirMode::NoChdir)
.unwrap();
}
app.run(&argv);
}