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§
- ENV_
LOG_ LEVEL - Environment variable name for configuring log level
Functions§
- confirm
- Prompts the user for confirmation with a custom message. Returns true if the user confirms, false otherwise.
- exec_
cmd_ for_ user - Executes a command and handles errors and output.
- getpid_
running - Get the pid of the running netpulsed daemon
- init_
logging - Initializes the logging system with the specified level.
- print_
usage - Displays program usage information and exits.
- root_
guard - Ensures the program is running with root privileges.
- setup_
panic_ handler - Sets up a custom panic handler for user-friendly error reporting.