Skip to content

Commit

Permalink
Fixed Tokio Runtime on Windows service
Browse files Browse the repository at this point in the history
  • Loading branch information
okynos committed Oct 10, 2024
1 parent bbb29b0 commit 65ebf8d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/appconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl AppConfig {
// Manage null value on audit value
let audit = match yaml[0]["audit"].as_vec() {
Some(value) => {
if utils::get_os() != "linux"{
if utils::get_os() != "linux" {
panic!("Audit only supported in Linux systems.");
}
value.to_vec()
Expand Down
12 changes: 11 additions & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,31 @@ use log::{info, debug, error};
use std::path::Path;
// Handle time intervals
use std::time::Duration;
use std::env;

use crate::appconfig::*;
use crate::utils;

fn get_template_path() -> String {
let relative_path = "./../../config/index_template.json";
let config_path = "/etc/fim/index_template.json";
let default_path = "config/index_template.json";
let executable_path = env::current_exe().unwrap();

if Path::new(default_path).exists() {
String::from(default_path)
}else if Path::new("./index_template.json").exists() {
String::from("./index_template.json")
}else if Path::new(relative_path).exists() {
String::from(relative_path)
}else{
}else if Path::new(config_path).exists() {
String::from(config_path)
}else{
if utils::get_os() != "windows"{
format!("{}/{}", executable_path.clone().parent().unwrap().to_str().unwrap(), "index_template.json")
}else{
format!("{}\\{}", executable_path.clone().parent().unwrap().to_str().unwrap(), "index_template.json")
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Parts of the code here is based on mullvad/windows-service-rs crate examples
// Crate link: https://github.com/mullvad/windows-service-rs

use futures::executor::block_on;
use notify::event::{Event, EventKind, EventAttributes};
use std::thread;
use tokio::runtime::Runtime;

use crate::monitor;
use crate::rotator;
Expand Down Expand Up @@ -108,7 +108,9 @@ pub fn run_service() -> Result<()> {
Ok(_v) => info!("FIM rotator thread started."),
Err(e) => error!("Could not start FIM rotator thread, error: {}", e)
};
block_on(monitor::monitor(tx, rx, cfg, ruleset));

let rt = Runtime::new().unwrap();
rt.block_on(monitor::monitor(tx, rx, cfg, ruleset));

// Tell the system that service has stopped.
status_handle.set_service_status(ServiceStatus {
Expand Down

0 comments on commit 65ebf8d

Please sign in to comment.