50constexpr int MAXIMUM_FILE_DESC = 256;
52void close_nonstandard_fd(
const int fd)
noexcept
54 if (fd > STDERR_FILENO)
58void dup2_or_throw(
const int null_fd,
const int target_fd,
const char *name)
60 if (dup2(null_fd, target_fd) == target_fd)
63 close_nonstandard_fd(null_fd);
71void redirect_standard_fds()
73 const int null_fd = open(
"/dev/null", O_RDWR);
77 dup2_or_throw(null_fd, STDIN_FILENO,
"stdin");
78 dup2_or_throw(null_fd, STDOUT_FILENO,
"stdout");
79 dup2_or_throw(null_fd, STDERR_FILENO,
"stderr");
82 close_nonstandard_fd(null_fd);
87void daemonize(
const char *program_name,
int facility)
91 <<
"Program name cannot be null or empty";
104 Signal signalHandler(SIGHUP, SIG_IGN);
120 for (
int i = 0; i < MAXIMUM_FILE_DESC; i++)
124 redirect_standard_fds();
127 openlog(program_name, LOG_PID | LOG_NDELAY, facility);
130 #ifdef ALEPH_DAEMONIZED_FLAG
Exception handling system with formatted messages for Aleph-w.
#define ah_runtime_error()
Throws std::runtime_error unconditionally.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
POSIX signal handling utilities with RAII semantics.
void daemonize(const char *program_name, int facility)
Converts the calling process into a Unix daemon.
Functionality for daemonizing a process.
RAII wrapper for POSIX signal handler registration.
bool daemonized
Flag indicating if the process is running as a daemon.