Expand description
Common functionality shared between netpulse binaries.
This module provides shared utilities used by both the netpulse reader and netpulsed daemon binaries, including:
- Privilege checks
- Logging setup
- PID file management
- Process management
- User interaction
§Exits
Some functions in this module exit when a condition is not met, printing an error then.
§Logging
Logging can be configured via the NETPULSE_LOG_LEVEL
environment variable.
Valid levels are: TRACE, DEBUG, INFO, WARN, ERROR
§Examples
use netpulse::common;
// Check for root privileges
common::root_guard();
// Initialize logging
common::init_logging(tracing::Level::INFO);
// Check if daemon is running
if let Some(pid) = common::getpid_running() {
println!("Daemon running with PID: {}", pid);
}
Constants§
- Environment variable name for configuring log level
Functions§
- Prompts the user for confirmation with a custom message. Returns true if the user confirms, false otherwise.
- Executes a command and handles errors and output.
- Reads the daemon’s PID from its PID file.
- Checks if the netpulse daemon is currently running.
- Initializes the logging system with the specified level.
- Checks if a process with the given PID exists.
- Displays program usage information and exits.
- Ensures the program is running with root privileges.
- Sets up a custom panic handler for user-friendly error reporting.