Back to index

im-sdk  12.3.91
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
IMDaemon Class Reference

#include <IMUtil.hh>

Collaboration diagram for IMDaemon:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void setup (const char *todir)

Static Public Member Functions

static IMDaemonget_instance ()
static void cleanup ()

Private Member Functions

void closefd ()
bool discard_parent ()
bool daemonize ()
 IMDaemon ()

Private Attributes

bool already_finished

Static Private Attributes

static IMDaemonpimdaemon = NULL

Detailed Description

Definition at line 205 of file IMUtil.hh.


Constructor & Destructor Documentation

IMDaemon::IMDaemon ( ) [private]

Definition at line 939 of file IMUtil.cpp.

{
    already_finished = false;
}

Here is the caller graph for this function:


Member Function Documentation

void IMDaemon::cleanup ( ) [static]

Definition at line 953 of file IMUtil.cpp.

{
    if (pimdaemon) delete pimdaemon;
}

Here is the caller graph for this function:

void IMDaemon::closefd ( ) [private]

Definition at line 959 of file IMUtil.cpp.

{
    int fd;
#ifdef HAVE_SYSCONF
    int fdmax = sysconf(_SC_OPEN_MAX);
#else
    int fdmax = 3;
#endif
    for (fd = 0; fd < fdmax; fd++) {
       close(fd);
    }

#ifndef WIN32
    // 0 : discard stdout
    open("/dev/null", O_RDWR);
    // 1 : discard stdin
    dup(0);
    // 2 : discard stderr
    dup(0);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool IMDaemon::daemonize ( ) [private]

Definition at line 998 of file IMUtil.cpp.

{
    if (!discard_parent()) return false;
#ifdef HAVE_SETSID
    if (setsid() < 0)
       return false;
#endif
    if (!discard_parent()) return false;

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool IMDaemon::discard_parent ( ) [private]

Definition at line 982 of file IMUtil.cpp.

{
#ifdef HAVE_FORK
    pid_t pid = fork();
    if (pid != 0) {
       if (pid == -1) {
           return false;
       } else {
           _exit(0);
       }
    }
#endif
    return true;
}

Here is the caller graph for this function:

Definition at line 945 of file IMUtil.cpp.

{
    if (pimdaemon) return pimdaemon;
    pimdaemon = new IMDaemon();
    return pimdaemon;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void IMDaemon::setup ( const char *  todir)

Definition at line 1011 of file IMUtil.cpp.

{
    if (!already_finished) {
       if (!daemonize()) {
           LOG_ERROR("Fail to make a daemon.");
       }
       closefd();
    }
    if (todir) {
       chdir(todir);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 207 of file IMUtil.hh.

IMDaemon * IMDaemon::pimdaemon = NULL [static, private]

Definition at line 208 of file IMUtil.hh.


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