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
[legend]

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));
            exit(1);
        case 0: // child
            /* clear inherited umasks */
            ::umask(0);
            /*
             * 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.
             */
            setsid();
            /* redirect standard input to /dev/null */
            if (std::freopen("/dev/null", "r", stdin) == NULL) {
                fclose(stdin);
            }
            /* forward stdout and stderr to log file */
            if (std::freopen(log_file_.c_str(), "a", stdout) == NULL) {
                fclose(stdout);
            }
            if (std::freopen(log_file_.c_str(), "a", stderr) == NULL) {
                fclose(stderr);
            }
            break;
        default:
            /* write pid to pid file */
            std::fstream pf(pid_file.c_str(), std::fstream::out);
            pf << pid;
            pf.close();
            /* succesful exit from parent */
            _exit(0);
    }
}

Here is the call graph for this function:

Definition at line 72 of file daemon.cpp.

                {
    // Remove pid file
    unlink(pid_file.c_str());
    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: