Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Attributes | Static Private Attributes
Arc::Daemon Class Reference

#include <daemon.h>

Collaboration diagram for Arc::Daemon:
Collaboration graph

List of all members.

Public Member Functions

 Daemon ()
 Daemon (const std::string &pid_file_, const std::string &log_file_)
 ~Daemon ()

Private Attributes

const std::string pid_file

Static Private Attributes

static Logger logger

Detailed Description

Definition at line 9 of file daemon.h.

Constructor & Destructor Documentation

Arc::Daemon::Daemon ( ) [inline]

Definition at line 11 of file daemon.h.

Daemon::Daemon ( const std::string &  pid_file_,
const std::string &  log_file_ 

Definition at line 31 of file daemon.cpp.

                                                                    : pid_file(pid_file)
    pid_t pid = fork();
    switch(pid) {
        case -1: // parent fork error
            logger.msg(ERROR, "Daemonization fork failed: %s", strerror(errno));
        case 0: // child
            /* clear inherited umasks */
             * Become a session leader: setsid must succeed because child is
             * guaranteed not to be a process group leader (it belongs to the
             * process group of the parent.)
             * The goal is not to have a controlling terminal.
             * As we now don't have a controlling terminal we will not receive
             * tty-related signals - no need to ignore them.
            /* redirect standard input to /dev/null */
            if (std::freopen("/dev/null", "r", stdin) == NULL) {
            /* forward stdout and stderr to log file */
            if (std::freopen(log_file_.c_str(), "a", stdout) == NULL) {
            if (std::freopen(log_file_.c_str(), "a", stderr) == NULL) {
            /* write pid to pid file */
            std::fstream pf(pid_file.c_str(), std::fstream::out);
            pf << pid;
            /* succesful exit from parent */

Here is the call graph for this function:

Definition at line 72 of file daemon.cpp.

    // Remove pid file
    Daemon::logger.msg(INFO, "Shutdown daemon");

Here is the call graph for this function:

Member Data Documentation

Logger Daemon::logger [static, private]

Definition at line 16 of file daemon.h.

const std::string Arc::Daemon::pid_file [private]

Definition at line 15 of file daemon.h.

The documentation for this class was generated from the following files: