Fix windows compilation with --no-fork

--no-fork is a stub on windows.
This commit is contained in:
Julian Ospald 2018-06-16 11:11:27 +02:00
parent 53cde1c2b8
commit c7e1ed1af3
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
2 changed files with 17 additions and 11 deletions

View File

@ -36,6 +36,8 @@ regex = "0.2"
lazy_static = "1.0" lazy_static = "1.0"
unicode-width = "0.1.4" unicode-width = "0.1.4"
unicode-segmentation = "1.2.0" unicode-segmentation = "1.2.0"
[target.'cfg(unix)'.dependencies]
unix-daemonize = "0.1" unix-daemonize = "0.1"
serde = "1.0" serde = "1.0"

View File

@ -1,5 +1,6 @@
#![windows_subsystem = "windows"] #![windows_subsystem = "windows"]
#[cfg(unix)]
extern crate unix_daemonize; extern crate unix_daemonize;
extern crate cairo; extern crate cairo;
extern crate env_logger; extern crate env_logger;
@ -64,6 +65,7 @@ mod file_browser;
mod subscriptions; mod subscriptions;
mod misc; mod misc;
#[cfg(unix)]
use unix_daemonize::{daemonize_redirect, ChdirMode}; use unix_daemonize::{daemonize_redirect, ChdirMode};
use std::env; use std::env;
use std::io::Read; use std::io::Read;
@ -114,18 +116,20 @@ fn main() {
.filter(|a| !a.starts_with(NO_FORK)) .filter(|a| !a.starts_with(NO_FORK))
.collect(); .collect();
// fork to background by default #[cfg(unix)] {
let want_fork = env::args() // fork to background by default
.take_while(|a| *a != "--") let want_fork = env::args()
.skip(1) .take_while(|a| *a != "--")
.find(|a| a.starts_with(NO_FORK)) .skip(1)
.is_none(); .find(|a| a.starts_with(NO_FORK))
.is_none();
if want_fork { if want_fork {
daemonize_redirect(Some("/tmp/nvim-gtk_stdout.log"), daemonize_redirect(Some("/tmp/nvim-gtk_stdout.log"),
Some("/tmp/nvim-gtk_stderr.log"), Some("/tmp/nvim-gtk_stderr.log"),
ChdirMode::NoChdir) ChdirMode::NoChdir)
.unwrap(); .unwrap();
}
} }
app.run(&argv); app.run(&argv);