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 new socket field is required with no fallback default. Existing suriconf.yaml files that don't contain a socket key will make find_socket return None, and the .expect("Unable to parse path to unix socket.") call will panic on startup. Consider defaulting to the common /var/run/suricata/suricata-command.socket (or deriving it) when the key is absent, or documenting the migration.
self.socket = ifletSome(Commands::Suricata{path_to_socket:Some(p), .. }) = &args.cmd{
p.clone()}else{self.find_socket(suriconf_string).expect("Unable to parse path to unix socket.")};
delete_pid_file unconditionally removes /var/run/suricata.pid via sudo rm -f. If a Suricata instance not managed by this tool is already running (e.g., on a different interface), its pidfile is silently deleted and a second Suricata is started, which then overwrites the pidfile. This can leave the original instance untrackable by PID and result in two Suricata processes running concurrently.
pubfndelete_pid_file() -> std::io::Result<()>{let status = Command::new("sudo").arg("-n").arg("rm").arg("-f").arg(PIDFILE).status()?;if status.success(){Ok(())}else{Err(std::io::Error::other("Failed to delete Suricata PID file."))}}
In wait_on_suricata_start, each failed suricatasc poll uses Command::status(), which inherits the process's stdout/stderr. While Suricata is starting, suricatasc connection errors will be printed to the console once per second for potentially up to 120 iterations, flooding output. Redirect the command's output (e.g., Stdio::null()) unless the errors are intended to be visible.
let output = Command::new("sudo").arg("-n").arg("suricatasc").arg("-c").arg("uptime").arg(socket).status().map_err(|e| format!("Unable to execute Suricata socket control tool: {e}"))?;if output.success(){returnOk(pid)}
thread::sleep(Duration::from_millis(1000));
Checking only that /proc/{pid} exists can match an unrelated process if a stale PID file was not removed or a PID was reused, causing monitoring of the wrong process (as the old comm == "Suricata-Main" check guarded against). Verify the process name via /proc/{pid}/comm before returning the PID.
if let Ok(pid) = content.trim().parse::<i32>() {
- if Path::new(&format!("/proc/{}", pid)).exists() {+ let comm = fs::read_to_string(format!("/proc/{}/comm", pid)).unwrap_or_default();+ if comm.trim() == "Suricata-Main" {
return Ok(pid);
}
Suggestion importance[1-10]: 6
__
Why: The PR removed the old comm == "Suricata-Main" verification, and the new PID-file approach could theoretically match an unrelated process via PID reuse or a stale file, so restoring the /proc/{pid}/comm check is an accurate and meaningful robustness improvement. Impact is moderate since delete_pid_file() and the short retry window make mismatches unlikely in practice.
Low
Gate Unix-specific startup commands for Windows
These Unix-specific sudo rm and --pidfile operations run before the cfg!(target_os = "windows") check, so on Windows the code would panic with a confusing sudo failure instead of hitting the intended todo!(). Guard these calls so they only execute on non-Windows targets.
Why: Correct observation: delete_pid_file() (which invokes sudo rm) runs before the cfg!(target_os = "windows") check, so Windows would panic with a confusing sudo error instead of reaching the intended todo!(). The fix is accurate, though impact is limited since Windows support is unimplemented anyway.
Low
Fail fast if Suricata exits during startup wait
If Suricata crashes during the 120-second startup wait, this loop keeps invoking suricatasc until the full timeout elapses, delaying the failure. Pass the spawned child into wait_on_suricata_start and use try_wait() to detect early exit and fail fast with the actual exit status.
if output.success() {
return Ok(pid)
+ }+ if let Some(status) = child.try_wait().expect("Unable to get Suricata status.") {+ return Err(format!("Suricata exited during startup with status: {status}."));
}
thread::sleep(Duration::from_millis(1000));
}
Err("Suricata could not start.".into())
Suggestion importance[1-10]: 5
__
Why: The concern is valid: if Suricata fails immediately, the loop still polls suricatasc for the full 120 seconds before reporting failure, and checking the spawned child via try_wait() would enable early failure detection. However, the improved_code references child without showing the required signature change to wait_on_suricata_start, and child is the sudo wrapper rather than Suricata itself, slightly weakening the guarantee.
Low
Make PID file wait timeout configurable
The hardcoded 20-second window for Suricata to write its PID file may be too short on systems with large rule sets or heavy startup load, causing a spurious "Suricata process not found" failure. Make this timeout configurable (e.g., derived from preconf_time or a constant with a larger value) instead of a magic number.
- for _ in 0..20 {+ let deadline = std::time::Instant::now() + Duration::from_secs(SURICATA_PIDFILE_TIMEOUT_SECS);+ while std::time::Instant::now() < deadline {
if let Ok(content) = fs::read_to_string(PIDFILE) {
Suggestion importance[1-10]: 3
__
Why: The suggestion is technically valid but speculative: 20 seconds for Suricata to write its PID file is usually sufficient, and the subsequent wait_on_suricata_start already provides a separate 120-second window for full startup. This is a minor maintainability/style improvement with marginal impact.
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-name scan with pidfile-based PID detection
Wait for Suricata readiness via
suricatascsocket pollingAdd
socketconfig option and-sCLI flagDelete stale pidfile before launching Suricata
Diagram Walkthrough
File Walkthrough
suricata.rs
Detect Suricata startup via pidfile and socketsrc/suricata.rs
PIDFILEconstant and pass--pidfileto Suricata commanddelete_pid_file()to remove stale pidfile before startupcheck_process_name_for_suricata_main()withget_suricata_pid()reading the pidfile and verifying
/proc/wait_on_suricata_start()pollingsuricatasc -c uptimeon thesocket; kill Suricata and panic on failure
argument.rs
Add CLI option for Suricata socket pathsrc/argument.rs
-s/--path_to_socketCLI option to the Suricata command foroverriding the Unix socket path
yaml.rs
Add socket path to Suriconf configurationsrc/yaml.rs
socket: PathBuffield toSuriconfstructfind_socket()parser for thesocketYAML keyREADME.md
Document socket configuration optionREADME.md
socketconfiguration option in the config tablesuriconf.yaml
Add default socket path to config filesrc/suriconf.yaml
socket: /var/run/suricata/suricata-command.socketentry