Skip to content

Commit 3597f9d

Browse files
Merge remote-tracking branch 'origin/main' into release/current
2 parents c6dcc11 + 86bb1b9 commit 3597f9d

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "openbas-agent"
3-
version = "1.18.19"
3+
version = "1.18.20"
44
edition = "2021"
55

66
[dependencies]

installer/linux/agent-installer-session-user.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ systemd_status=$(systemctl is-system-running)
88
os=$(uname | tr '[:upper:]' '[:lower:]')
99
install_dir="$HOME/${OPENBAS_INSTALL_DIR}"
1010
session_name="${OPENBAS_SERVICE_NAME}"
11+
systemd_unit_dir="$HOME/.config/systemd/user/"
1112

1213
if [ "${os}" != "linux" ]; then
1314
echo "Operating system $OSTYPE is not supported yet, please create a ticket in openbas github project"
@@ -60,7 +61,8 @@ EOF
6061

6162
echo "05. Starting agent service"
6263
(
63-
ln -sf ${install_dir}/${session_name}.service $HOME/.config/systemd/user/
64+
mkdir -p $systemd_unit_dir
65+
ln -sf ${install_dir}/${session_name}.service $systemd_unit_dir
6466
systemctl --user daemon-reload
6567
systemctl --user enable ${session_name}
6668
systemctl --user start ${session_name}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::env;
1313
use std::fs::create_dir_all;
1414
use std::ops::Deref;
1515
use std::panic;
16-
use std::path::{PathBuf};
16+
use std::path::PathBuf;
1717
use std::sync::atomic::AtomicBool;
1818
use std::thread::JoinHandle;
1919

src/process/agent_cleanup.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ static EXECUTING_MAX_TIME: u64 = 20; // 20 minutes
1515
// After X minutes define in this constant, all dir matching 'execution-' will be removed
1616
static DIRECTORY_MAX_TIME: u64 = 2880; // 2 days
1717

18-
fn get_old_execution_directories(subfolder: &str, path: &str, since_minutes: u64) -> Result<Vec<DirEntry>, Error> {
18+
fn get_old_execution_directories(
19+
subfolder: &str,
20+
path: &str,
21+
since_minutes: u64,
22+
) -> Result<Vec<DirEntry>, Error> {
1923
let now = SystemTime::now();
2024
let current_exe_patch = env::current_exe().unwrap();
2125
let executable_path = current_exe_patch.parent().unwrap();
@@ -64,7 +68,8 @@ pub fn clean() -> Result<JoinHandle<()>, Error> {
6468
// While no stop signal received
6569
while THREADS_CONTROL.load(Ordering::Relaxed) {
6670
let kill_runtimes_directories =
67-
get_old_execution_directories("runtimes", "execution-", EXECUTING_MAX_TIME).unwrap();
71+
get_old_execution_directories("runtimes", "execution-", EXECUTING_MAX_TIME)
72+
.unwrap();
6873
// region Handle killing old execution- directories
6974
for dir in kill_runtimes_directories {
7075
let dir_path = dir.path();
@@ -91,7 +96,9 @@ pub fn clean() -> Result<JoinHandle<()>, Error> {
9196
// After kill, rename from execution to executed
9297
fs::rename(dirname, dirname.replace("execution", "executed")).unwrap();
9398
}
94-
let rename_payloads_directories = get_old_execution_directories("payloads", "execution-", EXECUTING_MAX_TIME).unwrap();
99+
let rename_payloads_directories =
100+
get_old_execution_directories("payloads", "execution-", EXECUTING_MAX_TIME)
101+
.unwrap();
95102
for dir in rename_payloads_directories {
96103
let dir_path = dir.path();
97104
let dirname = dir_path.to_str().unwrap();

src/process/agent_exec.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use crate::common::error_model::Error;
1010
fn compute_working_dir(asset_agent_id: &str) -> PathBuf {
1111
let current_exe_patch = env::current_exe().unwrap();
1212
let executable_path = current_exe_patch.parent().unwrap();
13-
executable_path.join("runtimes").join(format!("execution-{asset_agent_id}"))
13+
executable_path
14+
.join("runtimes")
15+
.join(format!("execution-{asset_agent_id}"))
1416
}
1517

1618
fn command_with_context(asset_agent_id: &str, command: &str) -> String {

src/tests/process/agent_exec_tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ mod tests {
33
use crate::process::agent_exec::command_execution;
44
use std::env;
55
use std::fs;
6+
use std::fs::create_dir_all;
67
use std::panic;
78
use std::path::PathBuf;
8-
use std::fs::create_dir_all;
99

1010
const TEST_AGENT_ID: &str = &"62e1e7a6-79af-47ae-ac4a-8324c2b82197";
1111
const CLEANUP_ENABLED: bool = true;
@@ -18,7 +18,9 @@ mod tests {
1818
fn cleanup_after_tests() {
1919
if CLEANUP_ENABLED {
2020
let working_dir = compute_working_dir();
21-
let path = working_dir.join("runtimes").join(format!("execution-{}", TEST_AGENT_ID));
21+
let path = working_dir
22+
.join("runtimes")
23+
.join(format!("execution-{}", TEST_AGENT_ID));
2224
let _ = fs::remove_dir_all(path);
2325
}
2426
}

0 commit comments

Comments
 (0)