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 config value is set to /var/run/suricata.pid, which is the PID file, not the Suricata Unix command socket (typically /var/run/suricata/suricata-command.socket). suricatasc will try to connect to a non-socket file and fail, so wait_on_suricata_start will report "Suricata could not start." even when Suricata is running, causing the process to be killed and the run to panic. This affects every user relying on the config default rather than the -s CLI flag.
wait_on_suricata_start is called immediately after spawning Suricata, but the child's stderr/stdout pipes are not read until after this wait returns (up to ~20 seconds given the two 10-iteration, 1-second-sleep loops). Suricata can emit a large amount of startup output (e.g., rule loading warnings); once the OS pipe buffer fills, the child blocks on writing and never becomes ready, so the readiness check itself can hang the process it is waiting for.
Suricata itself is spawned via sudo -n (non-interactive), but the suricatasc check in wait_on_suricata_start calls sudo without -n. If sudo requires a password in the target environment, .status() will block indefinitely waiting for terminal input instead of failing fast, leaving the readiness loop stuck. Use sudo -n for consistency.
let output = Command::new("sudo").arg("suricatasc").arg("-c").arg("uptime").arg(socket).status().map_err(|e| format!("Unable to execute Suricata socket control tool: {e}"))?;
The PID file location is hardcoded to /var/run/suricata.pid while the socket path is configurable. Since both are passed to/used by the same Suricata instance, a custom socket deployment (e.g., a different run directory) will still force the PID file to the fixed path, and delete_pid_file will remove or fail on that fixed location. Consider making the PID file path configurable alongside the socket, or deriving it from the same setting.
The socket option points to the PID file path (/var/run/suricata.pid) instead of a Unix socket file such as /var/run/suricata/suricata.sock. With this value, suricatasc will try to talk to a PID file and startup detection will always fail. Point it at Suricata's actual Unix socket path.
Why: The socket value /var/run/suricata.pid is the PID file path, not a Unix socket path, so suricatasc in wait_on_suricata_start will never successfully connect, making the startup detection always fail. This is a real configuration bug that breaks the PR's core mechanism.
Medium
Pass socket via --socket flag
suricatasc does not accept the socket path as a positional argument; it must be passed via the --socket flag. As written, the command will fail to connect to the intended socket regardless of whether Suricata is up. Pass the path with --socket.
Why: suricatasc expects the socket path via the --socket flag, not as a positional argument, so passing it positionally would cause the command to fail or target the wrong socket even when Suricata is running. The fix is correct and directly affects the success of the startup wait logic.
Medium
Configure Suricata's Unix socket path
Suricata is never told to create its Unix socket at the configured suriconf.socket path, so it will use its default socket location and suricatasc will look in the wrong place. Add a --unix-socket argument (and corresponding unix-command enable) to the Suricata command line using the configured path.
Why: The concern is legitimate: Suricata is never told to create its Unix socket at the configured suriconf.socket path in the constructed command line, so suricatasc may target a wrong location. However, Suricata's socket location may already be configured in its own yaml (referenced by suriconf.suri_configuration), so the issue is somewhat speculative.
Low
General
Verify pid belongs to Suricata
The pid-file existence check does not guarantee the process it references is actually Suricata: a leftover/stale PID file recreated by any process could match, and /proc/{pid} existing only proves some process with that PID is alive. Consider verifying the process name (e.g., that the comm is suricata) before accepting the PID, to avoid operating on an unrelated process.
fn get_suricata_pid() -> Result<i32, String> {
for _ in 0..10 {
- ...- thread::sleep(Duration::from_millis(1000));+ if let Ok(content) = fs::read_to_string(PIDFILE) {+ if let Ok(pid) = content.trim().parse::<i32>() {+ if let Ok(stat) = fs::read_to_string(format!("/proc/{}/comm", pid)) {+ if stat.trim() == "suricata" {+ return Ok(pid);+ }+ }+ }+ }+ thread::sleep(Duration::from_millis(1000));+ }+ Err("Suricata process not found.".into())
}
-Err("Suricata process not found.".into())
Suggestion importance[1-10]: 3
__
Why: The stale-PID-file concern is largely mitigated since delete_pid_file() is called before spawning Suricata, and the PR intentionally moved away from process-name matching. This is a reasonable defensive hardening but only a marginal improvement with a small race-window benefit.
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
Verify readiness via Unix socket
suricatascAdd CLI and config support for socket path
Clean up stale PID files before execution
Diagram Walkthrough
File Walkthrough
argument.rs
Add socket path CLI argumentsrc/argument.rs
path_to_socketargument toCommands::Suricatayaml.rs
Extend Suriconf with socket configurationsrc/yaml.rs
socketfield toSuriconfstructfind_socketparsing methodsuricata.rs
Refactor Suricata startup detection logicsrc/suricata.rs
wait_on_suricata_startusing PID and socketcheck_process_name_for_suricata_mainlogicdelete_pid_fileandset_pid_filehelpersexecute_suricatato verify startup reliabilitysuriconf.yaml
Configure default socket pathsrc/suriconf.yaml
socketpath configuration/var/run/suricata.pid