summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRadek Novacek <rnovacek@redhat.com>2012-07-27 09:35:03 +0200
committerRadek Novacek <rnovacek@redhat.com>2012-07-27 09:35:03 +0200
commit171113535983029ab395341c8f8f3c92f320ea1a (patch)
tree2e7f2f064d29804666465166c114aa7f7845e134
parent99b6e54a64d962d226679ca290117f114eaf8245 (diff)
downloadopenlmi-providers-171113535983029ab395341c8f8f3c92f320ea1a.tar.gz
openlmi-providers-171113535983029ab395341c8f8f3c92f320ea1a.tar.xz
openlmi-providers-171113535983029ab395341c8f8f3c92f320ea1a.zip
Unify logging through all providers
Needs to be ported to sfcb/pegasus standard logging, using stderr for now.
-rw-r--r--src/CMakeLists.txt5
-rw-r--r--src/fan/Linux_Fan.c13
-rw-r--r--src/globals.c79
-rw-r--r--src/globals.h18
-rw-r--r--src/power/CMakeLists.txt4
-rw-r--r--src/power/Linux_AssociatedPowerManagementServiceProvider.c28
-rw-r--r--src/power/Linux_ConcreteJobProvider.c3
-rw-r--r--src/power/Linux_HostedServiceProvider.c1
-rw-r--r--src/power/Linux_PowerManagementServiceProvider.c12
-rw-r--r--src/power/globals.c24
-rw-r--r--src/power/globals.h7
-rw-r--r--src/power/trace.c29
-rw-r--r--src/power/trace.h4
-rw-r--r--src/service/CMakeLists.txt2
-rw-r--r--src/service/util/serviceutil.h6
15 files changed, 111 insertions, 124 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 156d7d1..b794abc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,3 +1,8 @@
+include_directories(.)
+
+add_library(curacommon SHARED
+ globals.c
+)
add_subdirectory(fan)
add_subdirectory(power)
diff --git a/src/fan/Linux_Fan.c b/src/fan/Linux_Fan.c
index 738920b..9826ba2 100644
--- a/src/fan/Linux_Fan.c
+++ b/src/fan/Linux_Fan.c
@@ -14,10 +14,6 @@
* along with cmpiLinux_FanProvider. If not, see
* <http://www.gnu.org/licenses/>.
*/
-#ifndef _XOPEN_SOURCE
- //this is for strdup
- #define _XOPEN_SOURCE 500
-#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -28,6 +24,7 @@
#include <sensors/error.h>
#include "Linux_Fan.h"
+#include "globals.h"
#define MAX_CHIP_NAME_LENGTH 200
@@ -108,13 +105,13 @@ static cim_fan_error_t reload_config_file(char const * fp) {
if (fp) {
if (!(config_file = fopen(fp, "r"))) {
- fprintf(stderr, "Cound not open config file \"%s\": %s\n",
+ error("Cound not open config file \"%s\": %s\n",
fp, strerror(errno));
}
}
err = sensors_init(config_file);
if (err) {
- fprintf(stderr, "sensors_init: %s\n", sensors_strerror(err));
+ error("sensors_init: %s\n", sensors_strerror(err));
if (config_file) fclose(config_file);
}else {
if (config_file) fclose(config_file);
@@ -245,7 +242,7 @@ static struct cim_fan * _load_fan_data( sensors_chip_name const *chip
if ((f = calloc(1, sizeof(struct cim_fan)))) {
if (!(chip_name = sprintf_chip_name(chip))) {
- fprintf(stderr, "could not get chip name\n");
+ error("could not get chip name\n");
goto lab_err_free_fan;
}
if (!(f->chip_name = strdup(chip_name))) {
@@ -254,7 +251,7 @@ static struct cim_fan * _load_fan_data( sensors_chip_name const *chip
}
f->sys_path = chip->path;
if (!(f->name = sensors_get_label(chip, feature))) {
- fprintf(stderr, "could not get fan name for chip: %s\n",
+ error("could not get fan name for chip: %s\n",
f->chip_name);
goto lab_err_chip_name;
}
diff --git a/src/globals.c b/src/globals.c
new file mode 100644
index 0000000..dea404a
--- /dev/null
+++ b/src/globals.c
@@ -0,0 +1,79 @@
+
+#include "globals.h"
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <sys/utsname.h>
+#include <string.h>
+#include <netdb.h>
+#include <stdio.h>
+
+static char *_fqdn = NULL;
+static int _log_level = DEBUG;
+
+char *getFQDN(void)
+{
+ struct utsname uts;
+ if ((uname(&uts) > 0) && (uts.nodename != NULL)) {
+ return strdup(uts.nodename);
+ }
+ char hostname[256];
+ hostname[255] = '\0';
+ if (gethostname(hostname, 255) == -1) {
+ // FIXME: what to do, if we can't use gethostname?
+ return NULL;
+ }
+
+ struct addrinfo hints;
+ struct addrinfo *info = NULL, *p;
+ memset(&hints, 0, sizeof hints);
+ hints.ai_family = AF_UNSPEC; // either IPV4 or IPV6
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_CANONNAME;
+
+ if (getaddrinfo(hostname, "http", &hints, &info) == 0) {
+ for (p = info; p != NULL; p = p->ai_next) {
+ if (p->ai_canonname && strstr(p->ai_canonname, "localhost") == NULL) {
+ char *dn = strdup(p->ai_canonname);
+ freeaddrinfo(info);
+ return dn;
+ }
+ }
+ }
+ if (info != NULL) {
+ freeaddrinfo(info);
+ }
+ return strdup(hostname);
+}
+
+const char *get_system_name()
+{
+ if (_fqdn == NULL) {
+ _fqdn = getFQDN();
+ }
+ return _fqdn;
+}
+
+const char *get_system_creationg_class_name()
+{
+ return "Linux_ComputerSystem";
+}
+
+void _debug(int level, const char *file, int line, const char *format, ...)
+{
+ if (level > _log_level) {
+ return;
+ }
+ FILE *trace_file = stderr;
+ const char *lvl[] = { "NONE", "ERROR", "WARNING", "DEBUG" };
+ // TODO: use logger from sfcbd and pegasus
+ fprintf(trace_file, "[%s] %s:%d\t", lvl[level], file, line);
+
+ va_list args;
+ va_start(args, format);
+ vfprintf(stderr, format, args);
+ va_end(args);
+
+ fprintf(stderr, "\n");
+}
diff --git a/src/globals.h b/src/globals.h
new file mode 100644
index 0000000..4f56413
--- /dev/null
+++ b/src/globals.h
@@ -0,0 +1,18 @@
+
+#ifndef GLOBALS_H
+#define GLOBALS_H
+
+const char *get_system_name();
+
+const char *get_system_creationg_class_name();
+
+int log_level(void);
+void set_log_level(int level);
+
+enum { NONE=0, ERROR, WARN, DEBUG };
+void _debug(int level, const char *file, int line, const char *format, ...);
+#define debug(...) _debug(DEBUG, __FILE__, __LINE__, __VA_ARGS__)
+#define warn(...) _debug(WARN, __FILE__, __LINE__, __VA_ARGS__)
+#define error(...) _debug(ERROR, __FILE__, __LINE__, __VA_ARGS__)
+
+#endif \ No newline at end of file
diff --git a/src/power/CMakeLists.txt b/src/power/CMakeLists.txt
index 4c06beb..606c1f3 100644
--- a/src/power/CMakeLists.txt
+++ b/src/power/CMakeLists.txt
@@ -5,8 +5,6 @@ set(MOF Linux_PowerManagement.mof)
set(provider_SRCS
power.c
- trace.c
- globals.c
)
konkretcmpi_generate(${MOF}
@@ -22,7 +20,7 @@ add_library(${LIBRARY_NAME} SHARED
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMPI_INCLUDE_DIR} ${GLIB_INCLUDE_DIRS})
-target_link_libraries(${LIBRARY_NAME} ${KONKRETCMPI_LIBRARIES} ${GLIB_LIBRARIES})
+target_link_libraries(${LIBRARY_NAME} curacommon ${KONKRETCMPI_LIBRARIES} ${GLIB_LIBRARIES})
# Check if we have upower and link it
pkg_check_modules(UPOWER upower-glib)
diff --git a/src/power/Linux_AssociatedPowerManagementServiceProvider.c b/src/power/Linux_AssociatedPowerManagementServiceProvider.c
index 7d61d83..75be7d2 100644
--- a/src/power/Linux_AssociatedPowerManagementServiceProvider.c
+++ b/src/power/Linux_AssociatedPowerManagementServiceProvider.c
@@ -5,7 +5,6 @@
#include "power.h"
-#include "trace.h"
#include "globals.h"
static const CMPIBroker* _cb;
@@ -25,11 +24,8 @@ static CMPIStatus Linux_AssociatedPowerManagementServiceCleanup(
const CMPIContext* cc,
CMPIBoolean term)
{
- TRACE(1, "Linux_AssociatedPowerManagementServiceCleanup\n");
-
power_unref(mi->hdl);
mi->hdl = NULL;
-
CMReturn(CMPI_RC_OK);
}
@@ -39,8 +35,6 @@ static CMPIStatus Linux_AssociatedPowerManagementServiceEnumInstanceNames(
const CMPIResult* cr,
const CMPIObjectPath* cop)
{
- TRACE(1, "Linux_AssociatedPowerManagementServiceEnumInstanceNames\n");
-
return KDefaultEnumerateInstanceNames(
_cb, mi, cc, cr, cop);
}
@@ -52,8 +46,6 @@ static CMPIStatus Linux_AssociatedPowerManagementServiceEnumInstances(
const CMPIObjectPath* cop,
const char** properties)
{
- TRACE(1, "Linux_AssociatedPowerManagementServiceEnumInstances\n");
-
const char *ns = KNameSpace(cop);
Linux_AssociatedPowerManagementService w;
@@ -95,8 +87,6 @@ static CMPIStatus Linux_AssociatedPowerManagementServiceGetInstance(
const CMPIObjectPath* cop,
const char** properties)
{
- TRACE(1, "Linux_AssociatedPowerManagementServiceGetInstance\n");
-
return KDefaultGetInstance(
_cb, mi, cc, cr, cop, properties);
}
@@ -164,12 +154,6 @@ static CMPIStatus Linux_AssociatedPowerManagementServiceAssociators(
const char* resultRole,
const char** properties)
{
- TRACE(1, "Linux_AssociatedPowerManagementServiceAssociators\n"
- "\tassocClass: %s\n"
- "\tresultClass: %s\n"
- "\trole: %s\n"
- "\tresultRole: %s\n", assocClass, resultClass, role, resultRole);
-
if (!assocClass) {
assocClass = "Linux_AssociatedPowerManagementService";
}
@@ -198,12 +182,6 @@ static CMPIStatus Linux_AssociatedPowerManagementServiceAssociatorNames(
const char* role,
const char* resultRole)
{
- TRACE(1, "Linux_AssociatedPowerManagementServiceAssociatorNames\n"
- "\tassocClass: %s\n"
- "\tresultClass: %s\n"
- "\trole: %s\n"
- "\tresultRole: %s\n", assocClass, resultClass, role, resultRole);
-
if (!assocClass) {
assocClass = "Linux_AssociatedPowerManagementService";
}
@@ -230,10 +208,6 @@ static CMPIStatus Linux_AssociatedPowerManagementServiceReferences(
const char* role,
const char** properties)
{
- TRACE(1, "Linux_AssociatedPowerManagementServiceReferences\n"
- "\tassocClass: %s\n"
- "\trole: %s\n", assocClass, role);
-
if (!assocClass) {
assocClass = "Linux_AssociatedPowerManagementService";
}
@@ -258,8 +232,6 @@ static CMPIStatus Linux_AssociatedPowerManagementServiceReferenceNames(
const char* assocClass,
const char* role)
{
- TRACE(1, "Linux_AssociatedPowerManagementServiceReferenceNames(assocClass: %s, role: %s)\n", assocClass, role);
-
if (!assocClass) {
assocClass = "Linux_AssociatedPowerManagementService";
}
diff --git a/src/power/Linux_ConcreteJobProvider.c b/src/power/Linux_ConcreteJobProvider.c
index 361d045..96176fa 100644
--- a/src/power/Linux_ConcreteJobProvider.c
+++ b/src/power/Linux_ConcreteJobProvider.c
@@ -1,11 +1,11 @@
#include <konkret/konkret.h>
#include <stdint.h>
#include "Linux_ConcreteJob.h"
+#include "globals.h"
static const CMPIBroker* _cb = NULL;
#include "power.h"
-#include "trace.h"
static void Linux_ConcreteJobInitializeInstance(CMPIInstanceMI *mi)
{
@@ -50,7 +50,6 @@ static CMPIStatus Linux_ConcreteJobEnumInstances(
CMPIStatus status;
const char *ns = KNameSpace(cop);
- TRACE(1, "Linux_ConcreteJobEnumInstances");
PowerStateChangeJob *powerStateChangeJob;
GList *plist = power_get_jobs(mi->hdl);
diff --git a/src/power/Linux_HostedServiceProvider.c b/src/power/Linux_HostedServiceProvider.c
index 4f6c7ac..cbfd55d 100644
--- a/src/power/Linux_HostedServiceProvider.c
+++ b/src/power/Linux_HostedServiceProvider.c
@@ -5,7 +5,6 @@
#include "Linux_ComputerSystem.h"
#include "globals.h"
-#include "trace.h"
static const CMPIBroker* _cb;
diff --git a/src/power/Linux_PowerManagementServiceProvider.c b/src/power/Linux_PowerManagementServiceProvider.c
index 8ce3f6c..ca328a9 100644
--- a/src/power/Linux_PowerManagementServiceProvider.c
+++ b/src/power/Linux_PowerManagementServiceProvider.c
@@ -3,7 +3,6 @@
#include "power.h"
#include "globals.h"
-#include "trace.h"
static const CMPIBroker* _cb = NULL;
@@ -23,11 +22,8 @@ static CMPIStatus Linux_PowerManagementServiceCleanup(
const CMPIContext* cc,
CMPIBoolean term)
{
- TRACE(1, "Linux_PowerManagementServiceCleanup\n");
-
power_unref(mi->hdl);
mi->hdl = NULL;
-
CMReturn(CMPI_RC_OK);
}
@@ -37,8 +33,6 @@ static CMPIStatus Linux_PowerManagementServiceEnumInstanceNames(
const CMPIResult* cr,
const CMPIObjectPath* cop)
{
- TRACE(1, "Linux_PowerManagementServiceEnumInstanceNames\n");
-
return KDefaultEnumerateInstanceNames(
_cb, mi, cc, cr, cop);
}
@@ -50,8 +44,6 @@ static CMPIStatus Linux_PowerManagementServiceEnumInstances(
const CMPIObjectPath* cop,
const char** properties)
{
- TRACE(1, "Linux_PowerManagementServiceEnumInstances\n");
-
Linux_PowerManagementService w;
Linux_PowerManagementService_Init(&w, _cb, KNameSpace(cop));
@@ -244,7 +236,6 @@ KUint32 Linux_PowerManagementService_RequestPowerStateChange(
const KDateTime* TimeoutPeriod,
CMPIStatus* status)
{
- TRACE(1, "Linux_PowerManagementService_RequestPowerStateChange\n");
KUint32 result = KUINT32_INIT;
if (Time->exists && Time->null && TimeoutPeriod->exists && TimeoutPeriod->null) {
@@ -260,8 +251,7 @@ KUint32 Linux_PowerManagementService_RequestPowerStateChange(
// Time argument is not handled because we don't support powering on systems
if (!PowerState->exists || PowerState->null) {
- TRACE(1, "wrong PowerState\n");
- KSetStatus(status, ERR_INVALID_PARAMETER);
+ KSetStatus2(_cb, status, ERR_INVALID_PARAMETER, "PowerState argument is missing");
return result;
}
power_request_power_state(mi->hdl, PowerState->value);
diff --git a/src/power/globals.c b/src/power/globals.c
deleted file mode 100644
index 2ba5075..0000000
--- a/src/power/globals.c
+++ /dev/null
@@ -1,24 +0,0 @@
-
-#include "globals.h"
-
-#define _XOPEN_SOURCE 500
-
-#include <stdlib.h>
-#include <unistd.h>
-#include "trace.h"
-
-static char *_hostname = NULL;
-
-const char *get_system_name()
-{
- if (_hostname == NULL) {
- _hostname = malloc(256 * sizeof(char));
- if (gethostname(_hostname, 255) == -1) {
- TRACE(4, "get_hostname(): gethostname returned -1");
- free(_hostname);
- _hostname = NULL;
- }
- }
- // TODO: try to get full qualified hostname
- return _hostname;
-}
diff --git a/src/power/globals.h b/src/power/globals.h
deleted file mode 100644
index adec07e..0000000
--- a/src/power/globals.h
+++ /dev/null
@@ -1,7 +0,0 @@
-
-#ifndef GLOBALS_H
-#define GLOBALS_H
-
-const char *get_system_name();
-
-#endif \ No newline at end of file
diff --git a/src/power/trace.c b/src/power/trace.c
deleted file mode 100644
index 1f23a6a..0000000
--- a/src/power/trace.c
+++ /dev/null
@@ -1,29 +0,0 @@
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-
-static FILE *_trace_file = NULL;
-
-void _trace(int level, const char *file, int line, const char *format, ...)
-{
- // TODO; level
- if (_trace_file == NULL) {
- char *filename = getenv("SBLIM_TRACE_FILE");
- if (filename != NULL) {
- _trace_file = fopen(filename, "a");
- if (_trace_file == NULL) {
- _trace_file = stderr;
- }
- } else {
- _trace_file = stderr;
- }
- }
-
- va_list args;
- va_start(args, format);
- fprintf(_trace_file, "%s:%d\t", file, line);
- vfprintf(_trace_file, format, args);
- fprintf(_trace_file, "\n");
- va_end(args);
-}
diff --git a/src/power/trace.h b/src/power/trace.h
deleted file mode 100644
index 65118d4..0000000
--- a/src/power/trace.h
+++ /dev/null
@@ -1,4 +0,0 @@
-
-#define TRACE(level, ...) _trace(level, __FILE__, __LINE__, __VA_ARGS__)
-
-void _trace(int level, const char *file, int line, const char *format, ...);
diff --git a/src/service/CMakeLists.txt b/src/service/CMakeLists.txt
index e2a41ca..631e0c8 100644
--- a/src/service/CMakeLists.txt
+++ b/src/service/CMakeLists.txt
@@ -20,7 +20,7 @@ add_library(${LIBRARY_NAME} SHARED
)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMPI_INCLUDE_DIR})
-target_link_libraries(${LIBRARY_NAME} ${KONKRETCMPI_LIBRARIES})
+target_link_libraries(${LIBRARY_NAME} curacommon ${KONKRETCMPI_LIBRARIES})
# Create registration file
cim_registration(${PROVIDER_NAME} ${LIBRARY_NAME} ${MOF})
diff --git a/src/service/util/serviceutil.h b/src/service/util/serviceutil.h
index 74f4786..dd8adea 100644
--- a/src/service/util/serviceutil.h
+++ b/src/service/util/serviceutil.h
@@ -28,12 +28,6 @@
#include <stdio.h>
-#ifdef DEBUG
-#define service_debug(fd, args...) fprintf(fd, args)
-#else
-#define service_debug(a, b...)
-#endif
-
#define ARRAY_SIZE(name) (sizeof(name) / sizeof(name[0]))
enum ServiceEnabledDefault { ENABLED = 2, DISABLED = 3, NOT_APPICABLE = 5};