version 1.100, 2005/03/29 19:16:02
|
version 1.114, 2005/12/09 20:45:45
|
|
|
// Sushma Fernandes (sushma_fernandes@hp.com) | // Sushma Fernandes (sushma_fernandes@hp.com) |
// Nag Boranna (nagaraja_boranna@hp.com) | // Nag Boranna (nagaraja_boranna@hp.com) |
// Bapu Patil (bapu_patil@hp.com) | // Bapu Patil (bapu_patil@hp.com) |
// |
// Dave Rosckes (rosckes@us.ibm.com) |
// Modified By: Dave Rosckes (rosckes@us.ibm.com) |
|
// Amit K Arora (amita@in.ibm.com) for PEP101 | // Amit K Arora (amita@in.ibm.com) for PEP101 |
// David Dillard, VERITAS Software Corp. | // David Dillard, VERITAS Software Corp. |
// (david.dillard@veritas.com) | // (david.dillard@veritas.com) |
// Yi Zhou (yi.zhou@hp.com) | // Yi Zhou (yi.zhou@hp.com) |
|
// Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#3194 |
|
// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#ifdef PEGASUS_OS_HPUX | #ifdef PEGASUS_OS_HPUX |
# include <dl.h> | # include <dl.h> |
|
# include <dlfcn.h> |
#elif defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) | #elif defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) |
# include <dll.h> | # include <dll.h> |
#elif defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) | #elif defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) |
|
|
#endif | #endif |
| |
#ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM | #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM |
|
#define _OPEN_SYS_SOCK_IPV6 |
|
#include <sys/socket.h> |
#include <arpa/inet.h> | #include <arpa/inet.h> |
#include <__ftp.h> |
//#include <__ftp.h> |
|
#define _OPEN_SYS_EXT |
|
#include <sys/ps.h> |
#endif | #endif |
| |
#if defined(PEGASUS_USE_SYSLOGS) | #if defined(PEGASUS_USE_SYSLOGS) |
|
|
#include "System.h" | #include "System.h" |
#include <Pegasus/Common/Tracer.h> | #include <Pegasus/Common/Tracer.h> |
#include <Pegasus/Common/InternalException.h> | #include <Pegasus/Common/InternalException.h> |
|
#include <Pegasus/Common/IPC.h> |
#ifdef PEGASUS_ZOS_SECURITY | #ifdef PEGASUS_ZOS_SECURITY |
#include "DynamicLibraryzOS_inline.h" | #include "DynamicLibraryzOS_inline.h" |
#endif | #endif |
|
|
milliseconds = Uint32(tv.tv_usec) / 1000; | milliseconds = Uint32(tv.tv_usec) / 1000; |
} | } |
| |
|
void System::getCurrentTimeUsec(Uint32& seconds, Uint32& microseconds) |
|
{ |
|
timeval tv; |
|
gettimeofday(&tv, 0); |
|
seconds = Uint32(tv.tv_sec); |
|
microseconds = Uint32(tv.tv_usec); |
|
} |
|
|
String System::getCurrentASCIITime() | String System::getCurrentASCIITime() |
{ | { |
char str[50]; | char str[50]; |
|
|
Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2, | Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
"Attempting to load library %s", fileName); | "Attempting to load library %s", fileName); |
| |
#if defined(PEGASUS_OS_HPUX) |
#if defined(PEGASUS_OS_TRU64) |
void* handle; |
|
if (bindVerbose) |
|
{ |
|
handle = shl_load(fileName, |
|
BIND_IMMEDIATE | DYNAMIC_PATH | BIND_VERBOSE, 0L); |
|
} |
|
else |
|
{ |
|
handle = shl_load(fileName, BIND_IMMEDIATE | DYNAMIC_PATH, 0L); |
|
} |
|
Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
|
"After loading lib %s, error code is %d", fileName, |
|
(handle == (void *)0)?errno:0); |
|
|
|
PEG_METHOD_EXIT(); |
|
return DynamicLibraryHandle(handle); |
|
#elif defined(PEGASUS_OS_TRU64) |
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW)); | return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW)); |
#elif defined(PEGASUS_OS_ZOS) | #elif defined(PEGASUS_OS_ZOS) |
|
|
return DynamicLibraryHandle(OS400_LoadDynamicLibrary(fileName)); | return DynamicLibraryHandle(OS400_LoadDynamicLibrary(fileName)); |
#else | #else |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW)); |
return DynamicLibraryHandle(dlopen(fileName, RTLD_GLOBAL|RTLD_NOW)); |
#endif | #endif |
| |
} | } |
| |
void System::unloadDynamicLibrary(DynamicLibraryHandle libraryHandle) | void System::unloadDynamicLibrary(DynamicLibraryHandle libraryHandle) |
{ | { |
// ATTN: Should this method indicate success/failure? |
|
#if defined(PEGASUS_OS_LINUX) || defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_DARWIN) |
|
dlclose(libraryHandle); |
|
#endif |
|
|
|
#ifdef PEGASUS_OS_HPUX |
|
// Note: shl_unload will unload the library even if it has been loaded |
|
// multiple times. No reference count is kept. |
|
int ignored = shl_unload(reinterpret_cast<shl_t>(libraryHandle)); |
|
#endif |
|
|
|
#ifdef PEGASUS_OS_OS400 | #ifdef PEGASUS_OS_OS400 |
OS400_UnloadDynamicLibrary((int)libraryHandle); | OS400_UnloadDynamicLibrary((int)libraryHandle); |
#endif |
#elif defined(PEGASUS_OS_ZOS) |
|
|
#ifdef PEGASUS_OS_AIX |
|
dlclose(libraryHandle); |
|
#endif |
|
|
|
#ifdef PEGASUS_OS_ZOS |
|
dllfree(reinterpret_cast<dllhandle *> (libraryHandle)); | dllfree(reinterpret_cast<dllhandle *> (libraryHandle)); |
|
#else |
|
dlclose(libraryHandle); |
#endif | #endif |
} | } |
| |
String System::dynamicLoadError() { | String System::dynamicLoadError() { |
// ATTN: Is this safe in a multi-threaded process? Should this string | // ATTN: Is this safe in a multi-threaded process? Should this string |
// be returned from loadDynamicLibrary? | // be returned from loadDynamicLibrary? |
#ifdef PEGASUS_OS_HPUX |
#ifdef PEGASUS_OS_ZOS |
// If shl_load() returns NULL, errno is set to indicate the error |
|
return strerror(errno); |
|
#elif defined(PEGASUS_OS_ZOS) |
|
return String(); | return String(); |
#elif defined(PEGASUS_OS_OS400) | #elif defined(PEGASUS_OS_OS400) |
return String(OS400_DynamicLoadError()); | return String(OS400_DynamicLoadError()); |
|
|
DynamicLibraryHandle libraryHandle, | DynamicLibraryHandle libraryHandle, |
const char* symbolName) | const char* symbolName) |
{ | { |
#ifdef PEGASUS_OS_HPUX |
|
char* p = (char*)symbolName; |
|
void* proc = 0; |
|
| |
if (shl_findsym((shl_t*)&libraryHandle, symbolName, TYPE_UNDEFINED, |
#ifdef PEGASUS_OS_ZOS |
&proc) == 0) |
|
{ |
|
return DynamicSymbolHandle(proc); |
|
} |
|
|
|
if (shl_findsym((shl_t*)libraryHandle, |
|
(String("_") + symbolName).getCString(), |
|
TYPE_UNDEFINED, |
|
&proc) == 0) |
|
{ |
|
return DynamicSymbolHandle(proc); |
|
} |
|
|
|
return 0; |
|
|
|
#elif defined(PEGASUS_OS_ZOS) |
|
return DynamicSymbolHandle(dllqueryfn((dllhandle *)libraryHandle, | return DynamicSymbolHandle(dllqueryfn((dllhandle *)libraryHandle, |
(char*)symbolName)); | (char*)symbolName)); |
| |
|
|
| |
String System::getHostName() | String System::getHostName() |
{ | { |
static char hostname[PEGASUS_MAXHOSTNAMELEN]; |
static char hostname[PEGASUS_MAXHOSTNAMELEN + 1]; |
| |
if (!*hostname) | if (!*hostname) |
{ | { |
gethostname(hostname, sizeof(hostname)); | gethostname(hostname, sizeof(hostname)); |
|
hostname[sizeof(hostname)-1] = 0; |
#if defined(PEGASUS_OS_OS400) | #if defined(PEGASUS_OS_OS400) |
EtoA(hostname); | EtoA(hostname); |
#endif | #endif |
|
|
| |
String System::getFullyQualifiedHostName () | String System::getFullyQualifiedHostName () |
{ | { |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_AIX) || defined(PEGASUS_OS_LINUX) |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_AIX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_OS_OS400) |
char hostName [PEGASUS_MAXHOSTNAMELEN]; |
char hostName[PEGASUS_MAXHOSTNAMELEN + 1]; |
struct hostent *he; | struct hostent *he; |
String fqName; | String fqName; |
| |
if (gethostname (hostName, PEGASUS_MAXHOSTNAMELEN) != 0) |
if (gethostname(hostName, sizeof(hostName)) != 0) |
{ | { |
return String::EMPTY; | return String::EMPTY; |
} | } |
|
hostName[sizeof(hostName)-1] = 0; |
| |
if ((he = gethostbyname (hostName))) | if ((he = gethostbyname (hostName))) |
{ | { |
strcpy (hostName, he->h_name); |
strncpy(hostName, he->h_name, sizeof(hostName)-1); |
} | } |
| |
|
#if defined(PEGASUS_OS_OS400) |
|
EtoA(hostName); |
|
#endif |
|
|
fqName.assign (hostName); | fqName.assign (hostName); |
| |
return fqName; | return fqName; |
#elif defined(PEGASUS_OS_ZOS) | #elif defined(PEGASUS_OS_ZOS) |
char hostName [PEGASUS_MAXHOSTNAMELEN]; |
char hostName[PEGASUS_MAXHOSTNAMELEN + 1]; |
char *domainName; |
|
String fqName; | String fqName; |
|
struct addrinfo *resolv; |
|
struct addrinfo hint; |
|
struct hostent *he; |
// receive short name of the local host | // receive short name of the local host |
if (gethostname(hostName, PEGASUS_MAXHOSTNAMELEN) != 0) | if (gethostname(hostName, PEGASUS_MAXHOSTNAMELEN) != 0) |
{ | { |
return String::EMPTY; | return String::EMPTY; |
} | } |
// get domain name of the local host |
resolv = new struct addrinfo; |
domainName= __ipDomainName(); |
hint.ai_flags = AI_CANONNAME; |
if (domainName == 0) |
hint.ai_family = AF_UNSPEC; // any family |
|
hint.ai_socktype = 0; // any socket type |
|
hint.ai_protocol = 0; // any protocol |
|
int success = getaddrinfo(hostName, |
|
NULL, |
|
&hint, |
|
&resolv); |
|
if (success==0) |
|
{ |
|
// assign fully qualified hostname |
|
fqName.assign(resolv->ai_canonname); |
|
} else |
{ | { |
return String::EMPTY; |
if ((he = gethostbyname(hostName))) |
|
{ |
|
strcpy (hostName, he->h_name); |
} | } |
// build fully qualified hostname |
// assign hostName |
|
// if gethostbyname was successful assign that result |
|
// else assign unqualified hostname |
fqName.assign(hostName); | fqName.assign(hostName); |
fqName.append("."); |
} |
fqName.append(domainName); |
freeaddrinfo(resolv); |
|
delete resolv; |
| |
return fqName; | return fqName; |
#else | #else |
|
|
// property used in the instrumentation of the CIM_ComputerSystem class | // property used in the instrumentation of the CIM_ComputerSystem class |
// as determined by the provider for the CIM_ComputerSystem class | // as determined by the provider for the CIM_ComputerSystem class |
// | // |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) |
|
return "CIM_ComputerSystem"; | return "CIM_ComputerSystem"; |
#else |
|
// |
|
// ATTN: Implement this method to return the system creation class name |
|
// |
|
return String::EMPTY; |
|
#endif |
|
} | } |
| |
Uint32 System::lookupPort( | Uint32 System::lookupPort( |
|
|
struct servent_data buf; | struct servent_data buf; |
memset(&buf, 0x00, sizeof(struct servent_data)); | memset(&buf, 0x00, sizeof(struct servent_data)); |
| |
if ( (getservbyname_r((char*)serviceName, TCP, &serv_result, |
char srvnameEbcdic[256]; |
|
strcpy(srvnameEbcdic, serviceName); |
|
AtoE(srvnameEbcdic); |
|
|
|
char tcpEbcdic[64]; |
|
strcpy(tcpEbcdic, TCP); |
|
AtoE(tcpEbcdic); |
|
|
|
if ( (getservbyname_r(srvnameEbcdic, tcpEbcdic, &serv_result, |
&buf)) == 0 ) | &buf)) == 0 ) |
#else // PEGASUS_OS_SOLARIS | #else // PEGASUS_OS_SOLARIS |
if ( (serv = getservbyname(serviceName, TCP)) != NULL ) | if ( (serv = getservbyname(serviceName, TCP)) != NULL ) |
|
|
//Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, | //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, |
// errorMsg); | // errorMsg); |
} | } |
|
#elif defined(PEGASUS_OS_ZOS) |
|
char effective_username[9]; |
|
__getuserid(effective_username, 9); |
|
__etoa_l(effective_username,9); |
|
userName.assign(effective_username); |
|
return userName; |
#else | #else |
// | // |
// get the currently logged in user's UID. | // get the currently logged in user's UID. |
|
|
return false; | return false; |
} | } |
#else | #else |
if (stat(path, &st) != 0) |
if (lstat(path, &st) != 0) |
{ | { |
return false; | return false; |
} | } |
#endif | #endif |
| |
return (st.st_uid == geteuid()); |
return ((st.st_uid == geteuid()) && // Verify the file owner |
|
S_ISREG(st.st_mode) && // Verify it is a regular file |
|
(st.st_nlink == 1)); // Verify it is not a hard link |
} | } |
| |
void System::openlog(const String &ident) |
void System::syslog(const String& ident, Uint32 severity, const char* message) |
{ | { |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) |
char * ident_name = strdup(ident.getCString()); |
|
::openlog(ident_name, LOG_PID, LOG_DAEMON); |
|
| |
#endif |
// Since the openlog(), syslog(), and closelog() function calls must be |
|
// coordinated (see below), we need a thread control. |
| |
return; |
static Mutex logMutex; |
} |
|
|
AutoMutex loglock(logMutex); |
|
|
|
// Get a const char* representation of the identifier string. Note: The |
|
// character string passed to the openlog() function must persist until |
|
// closelog() is called. The syslog() method uses this pointer directly |
|
// rather than a copy of the string it refers to. |
| |
void System::syslog(Uint32 severity, const char *data) |
CString identCString = ident.getCString(); |
|
openlog(identCString, LOG_PID, LOG_DAEMON); |
|
|
|
// Map from the Logger log level to the system log level. |
|
|
|
Uint32 syslogLevel; |
|
if (severity & Logger::FATAL) |
|
{ |
|
syslogLevel = LOG_CRIT; |
|
} |
|
else if (severity & Logger::SEVERE) |
|
{ |
|
syslogLevel = LOG_ERR; |
|
} |
|
else if (severity & Logger::WARNING) |
|
{ |
|
syslogLevel = LOG_WARNING; |
|
} |
|
else if (severity & Logger::INFORMATION) |
|
{ |
|
syslogLevel = LOG_INFO; |
|
} |
|
else // if (severity & Logger::TRACE) |
{ | { |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) |
syslogLevel = LOG_DEBUG; |
|
} |
| |
// FUTURE-SF-P3-20020517 : Use the Syslog on HP-UX. Eventually only |
// Write the message to the system log. |
// certain messages will go to the Syslog and others to the |
|
// Pegasus Logger. |
|
Uint32 syslogLevel = LOG_DEBUG; |
|
| |
// Map the log levels. |
::syslog(syslogLevel, "%s", message); |
if (severity & Logger::TRACE) syslogLevel = LOG_DEBUG; |
|
if (severity & Logger::INFORMATION) syslogLevel = LOG_INFO; |
|
if (severity & Logger::WARNING) syslogLevel = LOG_WARNING; |
|
if (severity & Logger::SEVERE) syslogLevel = LOG_ERR; |
|
if (severity & Logger::FATAL) syslogLevel = LOG_CRIT; |
|
| |
::syslog(syslogLevel, "%s", data); |
closelog(); |
| |
#elif defined(PEGASUS_OS_OS400) | #elif defined(PEGASUS_OS_OS400) |
| |
std::string replacementData = data; |
std::string replacementData = message; |
// All messages will go to the joblog. In the future | // All messages will go to the joblog. In the future |
// some messages may go to other message queues yet | // some messages may go to other message queues yet |
// to be determined. | // to be determined. |
|
|
// turn into ycmMessage so we can put it in the job log | // turn into ycmMessage so we can put it in the job log |
#pragma convert(37) | #pragma convert(37) |
ycmMessage theMessage("CPIDF80", | ycmMessage theMessage("CPIDF80", |
data, |
message, |
strlen(data), |
strlen(message), |
"Logger", | "Logger", |
ycmCTLCIMID, | ycmCTLCIMID, |
TRUE); | TRUE); |
|
|
// turn into ycmMessage so we can put it in the job log | // turn into ycmMessage so we can put it in the job log |
#pragma convert(37) | #pragma convert(37) |
ycmMessage theMessage("CPDDF82", | ycmMessage theMessage("CPDDF82", |
data, |
message, |
strlen(data), |
strlen(message), |
"Logger", | "Logger", |
ycmCTLCIMID, | ycmCTLCIMID, |
TRUE); | TRUE); |
|
|
} | } |
| |
#endif | #endif |
|
|
return; |
|
} | } |
| |
void System::closelog() |
// System ID constants for Logger::put and Logger::trace |
|
#if defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) |
|
const String System::CIMSERVER = "qycmcimom"; // Server system ID |
|
#else |
|
const String System::CIMSERVER = "cimserver"; // Server system ID |
|
#endif |
|
|
|
|
|
|
|
|
|
// |
|
// System Initializater for AIX |
|
// |
|
#ifdef PEGASUS_OS_AIX |
|
#include <cstdlib> |
|
|
|
class SystemInitializer |
{ | { |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) |
|
| |
::closelog(); |
public: |
|
/** |
|
* |
|
* Default constructor. |
|
* |
|
*/ |
|
SystemInitializer(); |
|
}; |
|
|
| |
#endif |
|
| |
return; |
SystemInitializer::SystemInitializer() |
|
{ |
|
putenv("XPG_SUS_ENV=ON"); |
} | } |
| |
// System ID constants for Logger::put and Logger::trace |
static SystemInitializer initializer; |
#if defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) |
|
const String System::CIMSERVER = "qycmcimom"; // Server system ID |
|
#else |
|
const String System::CIMSERVER = "cimserver"; // Server system ID |
|
#endif | #endif |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |