Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes

cmn_SysInfo Class Reference
[Common, basic classes, functions and types]

#include <cmn_sysinfo.h>

List of all members.

Public Member Functions

 cmn_SysInfo ()
 Gathers all of the system info that we need.
virtual ~cmn_SysInfo ()
virtual void cmn_SetHostNames (string &a_hostname, string &a_servername)
void RefreshPid ()

Static Public Member Functions

static void Read_IP_FQDN (const char *a_hostname, string &a_ip, string &a_fqdn)
 Reads IP and FQDN host name based on argument a_hostname.

Public Attributes

int m_pid
 current process' PID
string m_strpid
 prepared for debug log format " 123456.\0"
string m_userName
 User name.
string m_effUserName
 Effective user name.
string m_codeset
 Locale code set.
string m_hostName
 Hostname as used by IVD.
string m_shortHostName
 Short hostname as used by IVD.
string m_ip
 IP number as used by IVD.
string m_officialShortHostName
 Official short hostname of the computer.
string m_officialHostName
 Official hostname of the computer.
string m_officialIP
 IP number of the official hostname.
string m_serverHost
 Server host (MIF+PM).
string m_masterHost
 Master server host (Naming Service + RM).
string m_osName
 name of the operating system
string m_osRelease
 current release of operating system
string m_osVersion
 current version of this release
string m_machine
 name of hardware type

Private Member Functions

void GetSystemData (void)
 get the actual system data
void ParseServices ()

Private Attributes

 log_CLASSID_m

Detailed Description

Definition at line 35 of file cmn_sysinfo.h.


Constructor & Destructor Documentation

cmn_SysInfo::cmn_SysInfo (  ) 

Gathers all of the system info that we need.

Definition at line 65 of file cmn_SysInfo_LNX.cpp.

References cmn_StrLowerCase(), GetSystemData(), IVD_COUT_LOG_m, log_FUNC_m, m_hostName, m_ip, m_masterHost, m_officialHostName, m_officialIP, m_officialShortHostName, m_serverHost, m_shortHostName, ParseServices(), Read_IP_FQDN(), and RefreshPid().

{
    log_FUNC_m(cmn_SysInfo);
    IVD_COUT_LOG_m(" cmn_SysInfo::cmn_SysInfo() ")

    RefreshPid();
    GetSystemData();


    ParseServices();

    // If the hostname is overridden by the services.cfg file,
    // then IVD will use that, otherwise it will use the official
    // hostname.
    if (m_hostName.length() > 0) {
    // TODO: Convert long to short if necessary. From aliases?
        m_shortHostName = m_hostName;

        Read_IP_FQDN(m_shortHostName.c_str(), m_ip, m_hostName);
    }
    else {
        m_shortHostName = m_officialShortHostName;
        m_hostName      = m_officialHostName;
        m_ip            = m_officialIP;
    }

    if (m_serverHost.length() == 0) {
        m_serverHost = m_hostName;
    };
    if (m_masterHost.length() == 0) {
        m_masterHost = m_serverHost;
    };

    // Transform hostnames to lower case
    cmn_StrLowerCase(m_shortHostName);
    cmn_StrLowerCase(m_serverHost);
    cmn_StrLowerCase(m_masterHost);
}

Here is the call graph for this function:

cmn_SysInfo::~cmn_SysInfo (  )  [virtual]

Definition at line 104 of file cmn_SysInfo_LNX.cpp.

References IVD_COUT_LOG_m.

                          {
    IVD_COUT_LOG_m(" cmn_SysInfo::~cmn_SysInfo() ")
    //Empty
}


Member Function Documentation

void cmn_SysInfo::cmn_SetHostNames ( string &  a_hostname,
string &  a_servername 
) [virtual]

Definition at line 110 of file cmn_SysInfo_LNX.cpp.

References cmn_StrLowerCase(), IVD_COUT_LOG_m, log_FUNC_m, m_hostName, m_ip, m_masterHost, m_officialHostName, m_officialIP, m_officialShortHostName, m_serverHost, m_shortHostName, and Read_IP_FQDN().

{
    log_FUNC_m(SetHostNames);
    IVD_COUT_LOG_m("cmn_SysInfo::SetHostNames("
                    << a_hostname << ","
                    << a_servername << ") ")

    // overide the host names if neccesary
    if (a_hostname.length() > 0){
        m_hostName = a_hostname;
    }

    if (a_servername.length() > 0){
        m_serverHost = a_servername;
    }

    if (m_hostName.length() > 0) {
    // TODO: Convert long to short if necessary. From aliases?
        m_shortHostName = m_hostName;

        Read_IP_FQDN(m_shortHostName.c_str(), m_ip, m_hostName);
    }
    else {
        m_shortHostName = m_officialShortHostName;
        m_hostName      = m_officialHostName;
        m_ip            = m_officialIP;
    }

    if (m_serverHost.length() == 0) {
        m_serverHost = m_hostName;
    };
    if (m_masterHost.length() == 0) {
        m_masterHost = m_serverHost;
    };

    // Transform hostnames to lower case
    cmn_StrLowerCase(m_shortHostName);
    cmn_StrLowerCase(m_serverHost);
    cmn_StrLowerCase(m_masterHost);
}

Here is the call graph for this function:

void cmn_SysInfo::GetSystemData ( void   )  [private]

get the actual system data

Definition at line 248 of file cmn_SysInfo_LNX.cpp.

References errno, getpwuid(), cmn_UTF8Converter::InitCodeSet(), IVD_COUT_LOG_m, log_ERR_m, log_FUNC_m, log_WRN_m, m_codeset, m_effUserName, m_machine, m_officialHostName, m_officialIP, m_officialShortHostName, m_osName, m_osRelease, m_osVersion, m_userName, NULL, passwd::pw_name, and Read_IP_FQDN().

Referenced by cmn_SysInfo().

                                    {
    log_FUNC_m(GetSystemData);
    {
    IVD_COUT_LOG_m("   // User name ")
        // User name.
        struct passwd *pwd = getpwuid(getuid());
    IVD_COUT_LOG_m("   got pwd " << pwd)
        if (pwd != NULL) {
            m_userName  = string(pwd->pw_name);
        }
        else {
            log_WRN_m("Can't get user name. errno = " << errno);
        }
    }
    {
    IVD_COUT_LOG_m("   // Effective user name ")
        // Effective user name
        struct passwd *pwd = getpwuid(geteuid());
        if (pwd != NULL) {
            m_effUserName  = string(pwd->pw_name);
        }
        else {
            log_WRN_m("Can't get effective user name. errno = " << errno);
        }
    }

    m_codeset = cmn_UTF8Converter::InitCodeSet();

    struct utsname hostinfo;

    int result = uname(&hostinfo);
    if (result < 0) {
        log_ERR_m(
            "uname() failed. Error: " << strerror(errno)
        );
    } else {

        m_osName    = hostinfo.sysname;     // name of the operating system
        m_osRelease = hostinfo.release;     // current release of operating system
        m_osVersion = hostinfo.version;     // current version of this release
        m_machine   = hostinfo.machine;     // name of hardware type

        // Official hostname of the computer
        m_officialShortHostName = hostinfo.nodename;
        Read_IP_FQDN(
        m_officialShortHostName.c_str(), m_officialIP, m_officialHostName);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cmn_SysInfo::ParseServices (  )  [private]

Definition at line 298 of file cmn_SysInfo_LNX.cpp.

References c_hostname(), cmn_Global::dirs, ivd_Directories::etc, g_cmn, IVD_COUT_LOG_m, ivd_MAX_HOSTNAME_SIZE, m_hostName, m_masterHost, and m_serverHost.

Referenced by cmn_SysInfo().

                                {
    IVD_COUT_LOG_m(" cmn_SysInfo::ParseServices() ")

    // Reading IVD server host name from file
    cmn_Path servicesFN = g_cmn.dirs.etc + "services.cfg";

    // Parse contents
    static const string c_hostname("hostname");
    static const string c_server("server");
    static const string c_masterServer("masterserver");
    ifstream            istr(servicesFN.c_str());

    // Did open succeed?
    if (!istr) {
        return;
    }

    char var[ivd_MAX_HOSTNAME_SIZE+1], val[ivd_MAX_HOSTNAME_SIZE+1], eq;

    //
    // Content of the file services.cfg is in the form:
    // hostname = client.host.name
    // server = server.host.name
    // masterserver = masterserver.host.name
    //
    while (!istr.fail()) {
        istr >> setw(sizeof(var)) >> var >> eq >> val;

        if (!istr.fail()) {
            if (eq == '=') {
                if (c_hostname.compare(var) == 0) {
                    m_hostName.assign(val);
                }
                else if (c_server.compare(var) == 0) {
                    m_serverHost.assign(val);
                }
                else if (c_masterServer.compare(var) == 0) {
                    m_masterHost.assign(val);
                }
            };
        };
    }; // while
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cmn_SysInfo::Read_IP_FQDN ( const char *  a_hostname,
string &  a_ip,
string &  a_fqdn 
) [static]

Reads IP and FQDN host name based on argument a_hostname.

Definition at line 170 of file cmn_SysInfo_LNX.cpp.

References cmn_StrLowerCase(), errno, IVD_COUT_LOG_m, log_ERR_m, log_FUNC_m, log_WRN_m, and NULL.

Referenced by cmn_SetHostNames(), cmn_SysInfo(), GetSystemData(), and mif_ResolveHostToFQDN().

                                                                                   {
    IVD_COUT_LOG_m(" cmn_SysInfo::Read_IP_FQDN")

    log_FUNC_m(Read_IP_FQDN);

    struct hostent *host(NULL);
    host = gethostbyname(a_hostname);
    if (host == NULL) {
#if TGT_OS_linux
        log_ERR_m(
            "gethostbyname(" << a_hostname << ") failed. " <<
            "Error: " << hstrerror(h_errno) );
#elif TGT_OS_hpux
        log_ERR_m(
            "gethostbyname(" << a_hostname << ") failed. " <<
            "Error: " << strerror(h_errno) );
#endif
        return;
    }

    if (host->h_name == NULL) {
        log_WRN_m(
            "Misconfigured DNS on host:" << a_hostname <<
            " Official name (hostent::h_name) is NULL." );
        a_fqdn.clear();
    }
    else {
        // Official (canonical) name of the host. Should contain FQDN!
        a_fqdn = string(host->h_name);
        if (a_fqdn.find('.') == string::npos) {
            log_WRN_m(
                "Misconfigured DNS on host:" << a_hostname <<
                " Official name (hostent::h_name) should contain FQDN." );
        }
        cmn_StrLowerCase(a_fqdn);
    }

    const string localhost_c("127.0.0.1");
    a_ip = localhost_c;
    for (int i = 0; host->h_addr_list[i] != NULL; i++) {

        // struct hostent contains multiple IPs.
        // We scan until non-localhost (127.0.0.1) is reached.
        char ip[30];
        const char *ipresult = inet_ntop(
            host->h_addrtype,
            host->h_addr_list[i],
            ip, 30);
        if (ipresult == NULL) {
            log_ERR_m(
                "inet_ntop() failed. Error: " <<
                strerror(errno) );
            break;
        }
        if (localhost_c.compare(ip) == 0) {
            // Skip localhost if there are other IPs.
            // Note that localhost is used
            // if it is the only IP that the machine has.
            continue;
        }
        a_ip = string(ip);     // IP number
        break;
    }

    if (a_fqdn.empty()) {
        a_fqdn = a_ip;
    }

    if (a_ip == localhost_c) {
    /* See bug 9247
        log_WRN_m(
            "This machine (" << a_fqdn << ") " <<
            "has only localhost IP." );
        */
    };
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cmn_SysInfo::RefreshPid (  ) 

Definition at line 154 of file cmn_SysInfo_LNX.cpp.

References IVD_COUT_LOG_m, m_pid, and m_strpid.

Referenced by cmn_DaemonInit(), cmn_SysInfo(), and main().

                             {
    IVD_COUT_LOG_m(" cmn_SysInfo::RefreshPid")

    m_pid       = getpid();
    // set pid in debug log format
    {
        ostringstream dbgFormatted;
        dbgFormatted
            << std::setw(6) << std::setfill('0')
            << m_pid;
        m_strpid = dbgFormatted.str();
    };
    IVD_COUT_LOG_m(" cmn_SysInfo::RefreshPid End()")
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 104 of file cmn_sysinfo.h.

Locale code set.

Definition at line 55 of file cmn_sysinfo.h.

Referenced by GetSystemData(), cfg_CliBase::LocaleToUTF8Argv(), and log_Debugger::On().

Effective user name.

Definition at line 51 of file cmn_sysinfo.h.

Referenced by cmn_Global::cmn_Global(), GetSystemData(), IsFileOffline(), and log_Debugger::On().

IP number as used by IVD.

Definition at line 66 of file cmn_sysinfo.h.

Referenced by cmn_SetHostNames(), cmn_SysInfo(), log_EventLogger::GetHeader(), ut_Group::Header(), and log_Debugger::On().

name of hardware type

Definition at line 95 of file cmn_sysinfo.h.

Referenced by log_EventLogger::GetHeader(), GetSystemData(), ut_Group::Header(), and log_Debugger::On().

Master server host (Naming Service + RM).

Definition at line 81 of file cmn_sysinfo.h.

Referenced by cmn_SetHostNames(), cmn_SysInfo(), ipc_Corba::Init(), log_Debugger::On(), and ParseServices().

Official hostname of the computer.

Definition at line 72 of file cmn_sysinfo.h.

Referenced by cmn_SetHostNames(), cmn_SysInfo(), log_EventLogger::GetHeader(), GetSystemData(), and log_Debugger::On().

IP number of the official hostname.

Definition at line 75 of file cmn_sysinfo.h.

Referenced by cmn_SetHostNames(), cmn_SysInfo(), log_EventLogger::GetHeader(), GetSystemData(), and log_Debugger::On().

Official short hostname of the computer.

Definition at line 69 of file cmn_sysinfo.h.

Referenced by cmn_SetHostNames(), cmn_SysInfo(), and GetSystemData().

name of the operating system

Definition at line 86 of file cmn_sysinfo.h.

Referenced by log_EventLogger::GetHeader(), GetSystemData(), ut_Group::Header(), and log_Debugger::On().

current release of operating system

Definition at line 89 of file cmn_sysinfo.h.

Referenced by log_EventLogger::GetHeader(), GetSystemData(), i_Component_i::GetVersion(), ut_Group::Header(), and log_Debugger::On().

current version of this release

Definition at line 92 of file cmn_sysinfo.h.

Referenced by log_EventLogger::GetHeader(), GetSystemData(), i_Component_i::GetVersion(), ut_Group::Header(), and log_Debugger::On().

Short hostname as used by IVD.

Definition at line 63 of file cmn_sysinfo.h.

Referenced by cmn_SetHostNames(), cmn_SysInfo(), RunOmniNames(), and log_EventLogger::Write().

prepared for debug log format " 123456.\0"

Definition at line 46 of file cmn_sysinfo.h.

Referenced by RefreshPid(), log_Debugger::SetFileName(), log_EventLogger::Write(), and log_Debugger::WriteHeader().


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