You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The --pidfile argument is pushed to vec_of_sur_cmd without a corresponding path value. Suricata expects --pidfile <path> or --pidfile=<path>. Without the path, Suricata will either fail to start or misinterpret the next argument (from get_capture_mode) as the pidfile path. Meanwhile, get_suricata_pid hardcodes the read path as /var/run/suricata.pid, so even if Suricata uses a default, it may not match this path, causing the startup detection to always fail and panic.
suricatasc -c uptime is invoked without specifying a socket path (e.g., via --socket). If the Suricata configuration uses a non-default socket location, suricatasc will fail even though Suricata is running, causing wait_on_suricata_start to return an error and panic. The socket path should be derived from the configuration and passed to suricatasc to ensure the check is valid.
let output = Command::new("sudo").arg("suricatasc").arg("-c").arg("uptime").status().expect("Unable to execute Suricata socket control tool.");
The --pidfile flag requires a path argument. Without it, Suricata will either fail to start or consume the next argument (added by get_capture_mode) as the pidfile path, breaking both settings. Add the path /var/run/suricata.pid to match the location read by get_suricata_pid.
Why: The --pidfile flag requires a path argument, and without it Suricata may either fail to start or consume the next argument from get_capture_mode as the path. This is critical because get_suricata_pid reads from /var/run/suricata.pid, so the path must match.
High
Kill child process before panic on failure
When wait_on_suricata_start() fails, the already-spawned child process is not killed before panicking. Since Rust's Child drop does not kill the process by default, this leaks a running Suricata process. Call child.kill() before panicking to clean up properly.
let suri_pid = match wait_on_suricata_start() {
Ok(pid) => pid,
Err(e) => {
+ let _ = child.kill();
panic!("{e}")
}
};
Suggestion importance[1-10]: 7
__
Why: When wait_on_suricata_start() fails, the already-spawned child process is not killed before panicking, which leaks a running Suricata process. Calling child.kill() before the panic is a good cleanup practice, though it only affects the error path.
Medium
General
Propagate error instead of panicking on command failure
Using .expect() on the suricatasc command execution causes a panic if the tool is unavailable, instead of propagating the error. Since wait_on_suricata_start returns Result, use ? with map_err to handle the error gracefully and allow the caller to decide how to respond.
let output = Command::new("sudo")
.arg("suricatasc")
.arg("-c")
.arg("uptime")
.status()
- .expect("Unable to execute Suricata socket control tool.");+ .map_err(|e| format!("Unable to execute Suricata socket control tool: {e}"))?;
Suggestion importance[1-10]: 6
__
Why: Using .expect() causes a panic if suricatasc is unavailable, whereas the function returns a Result. Propagating the error with ? and map_err is a better practice, but the impact is moderate since it only changes error handling behavior.
Low
Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Bug fix, Enhancement
Description
Replace process scanning with PID file reading
Add socket availability check via
suricatascPass
--pidfileargument to Suricata commandEnsure Suricata is fully ready before proceeding
Diagram Walkthrough
File Walkthrough
suricata.rs
Refactor Suricata startup detection logicsrc/suricata.rs
--pidfileargument to Suricata commandwait_on_suricata_startfor socket verificationall_processesdependency for startup detection