summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Safranek <jsafrane@redhat.com>2013-05-16 11:03:30 +0200
committerJan Safranek <jsafrane@redhat.com>2013-05-16 11:03:30 +0200
commit9b425590619409663e200f9d3683ce06e282bfc2 (patch)
tree71dece26f9fd8115a52531258977f08fc9fa56e8
parent0d2ff2523333f4b93154a46d70e1c8143ac789e7 (diff)
parentdac1795235eef3868a35b5b571b8f6b0f0e140af (diff)
downloadopenlmi-providers-9b425590619409663e200f9d3683ce06e282bfc2.tar.gz
openlmi-providers-9b425590619409663e200f9d3683ce06e282bfc2.tar.xz
openlmi-providers-9b425590619409663e200f9d3683ce06e282bfc2.zip
Merge branch 'master' of ssh://git.fedorahosted.org/git/openlmi-providers
-rw-r--r--cmake/modules/FindOpenLMI.cmake14
-rw-r--r--cmake/modules/OpenLMIMacros.cmake84
-rw-r--r--src/openlmi.c16
-rw-r--r--src/openlmi.h10
4 files changed, 99 insertions, 25 deletions
diff --git a/cmake/modules/FindOpenLMI.cmake b/cmake/modules/FindOpenLMI.cmake
index d4338ca..3a83f32 100644
--- a/cmake/modules/FindOpenLMI.cmake
+++ b/cmake/modules/FindOpenLMI.cmake
@@ -6,6 +6,20 @@ find_path(OPENLMI_INCLUDE_DIR
PATHS /usr /usr/local
)
+find_file(OPENLMI_QUALIFIERS_MOF
+ NAMES 05_LMI_Qualifiers.mof
+ HINTS $ENV{OPENLMI_MOF_DIR}
+ PATH_SUFFIXES share/openlmi-providers
+ PATHS /usr /usr/local
+)
+
+find_file(OPENLMI_JOBS_MOF
+ NAMES 30_LMI_Jobs.mof
+ HINTS $ENV{OPENLMI_MOF_DIR}
+ PATH_SUFFIXES share/openlmi-providers
+ PATHS /usr /usr/local
+)
+
find_library(OPENLMICOMMON_LIBRARY
NAMES openlmicommon
HINTS $ENV{OPENLMI_LIB_DIR}
diff --git a/cmake/modules/OpenLMIMacros.cmake b/cmake/modules/OpenLMIMacros.cmake
index ca63d0d..30bdb69 100644
--- a/cmake/modules/OpenLMIMacros.cmake
+++ b/cmake/modules/OpenLMIMacros.cmake
@@ -1,31 +1,70 @@
-# This macro takes name of the MOF for one provider and header files using
-# konkretcmpi. It also generates provider skeleton if it doesn't exist.
+# This macro takes names of the MOFs for one provider and creates the
+# headerfiles using konkretcmpi. It also generates provider skeleton
+# if it doesn't exist.
#
-# @param[in] MOF name of the MOF file (should be in mof/ directory of the project root)
-# @param[out] CIM_PROVIDERS list of sources of the provider generated from the MOF
-# @param[out] CIM_HEADERS list of header file generated from the MOF
+# @param[in] MOFS filenames of the MOF files which will be used to generate
+# or a list with multiple MOF files, where relative paths mean mof/ directory
+# of the project root (Note: list is semi-colon separated, enclosed in quotes)
+# @param[out] CIM_PROVIDERS list of sources of the provider generated from the MOFS
+# @param[out] CIM_HEADERS list of header files generated from the MOFS
+# @param[in] the rest of the argument are mof files that should be included
+# in konkret header generation but are not scanned for classes
#
-macro(konkretcmpi_generate MOF CIM_PROVIDERS CIM_HEADERS)
- # Check if MOF exists
- set(MOF_FILE ${CMAKE_SOURCE_DIR}/mof/${MOF})
- message(STATUS "Using mof ${MOF} ${MOF_FILE}")
- if (NOT EXISTS ${MOF_FILE})
- message(FATAL_ERROR "MOF file ${MOF} not found")
- endif (NOT EXISTS ${MOF_FILE})
-
- # Read CIM classes out of MOF file
- file(READ ${MOF_FILE} MOF_CONTENT)
- string(REGEX MATCHALL "class [A-Za-z0-9_]+" CIM_CLASSESX ${MOF_CONTENT})
+macro(konkretcmpi_generate MOFS CIM_PROVIDERS CIM_HEADERS)
+ # Create list of MOF files for konkret generator and
+ # list of classes defined in the MOF files
+ set(KONKRET_MOF_FILES "")
set(CIM_CLASSES "")
- foreach(CLASSX ${CIM_CLASSESX})
- string(REPLACE "class " "" CLASS ${CLASSX})
- set(CIM_CLASSES ${CIM_CLASSES} ${CLASS})
- endforeach(CLASSX ${CIM_CLASSESX})
+
+ # Add includes first (needs to be parsed before others)
+ foreach(MOF ${ARGN})
+ # Check if path is absolute, make it absolute if not
+ if (IS_ABSOLUTE ${MOF})
+ set(MOF_FILE ${MOF})
+ else (IS_ABSOLUTE ${MOF})
+ set(MOF_FILE ${CMAKE_SOURCE_DIR}/mof/${MOF})
+ endif (IS_ABSOLUTE ${MOF})
+
+ # Check if MOF file exists
+ if (NOT EXISTS ${MOF_FILE})
+ message(FATAL_ERROR "MOF file ${MOF} not found")
+ endif (NOT EXISTS ${MOF_FILE})
+
+ message(STATUS "Using mof ${MOF} ${MOF_FILE}")
+ set(KONKRET_MOF_FILES ${KONKRET_MOF_FILES} -m ${MOF_FILE})
+ endforeach(MOF ${ARGN})
+
+ # Read the MOFs with class definition
+ foreach(MOF ${MOFS})
+ # Check if path is absolute, make it absolute if not
+ if (IS_ABSOLUTE ${MOF})
+ set(MOF_FILE ${MOF})
+ else (IS_ABSOLUTE ${MOF})
+ set(MOF_FILE ${CMAKE_SOURCE_DIR}/mof/${MOF})
+ endif (IS_ABSOLUTE ${MOF})
+
+ # Check if MOF file exists
+ if (NOT EXISTS ${MOF_FILE})
+ message(FATAL_ERROR "MOF file ${MOF} not found")
+ endif (NOT EXISTS ${MOF_FILE})
+
+ message(STATUS "Using mof ${MOF} ${MOF_FILE}")
+ set(KONKRET_MOF_FILES ${KONKRET_MOF_FILES} -m ${MOF_FILE})
+
+ # Read CIM classes out of MOF files
+ file(READ ${MOF_FILE} MOF_CONTENT)
+ string(REGEX MATCHALL "class [A-Za-z0-9_]+" CIM_CLASSESX ${MOF_CONTENT})
+ foreach(CLASSX ${CIM_CLASSESX})
+ string(REPLACE "class " "" CLASS ${CLASSX})
+ set(CIM_CLASSES ${CIM_CLASSES} ${CLASS})
+ endforeach(CLASSX ${CIM_CLASSESX})
+ endforeach(MOF in LISTS MOFS)
+
list(LENGTH CIM_CLASSES LEN)
if (${LEN} EQUAL 0)
- message(FATAL_ERROR "No class found in the MOF file ${MOF_FILE}")
+ message(FATAL_ERROR "No class found in the MOF files ${MOFS}")
else (${LEN} EQUAL 0)
# Get headers and sources names from the list of CIM classes
set(HEADERS "")
@@ -51,8 +90,7 @@ macro(konkretcmpi_generate MOF CIM_PROVIDERS CIM_HEADERS)
# Generate headers for CIM classes
set(ENV{KONKRET_SCHEMA_DIR} "/usr/share/mof/cim-current")
execute_process(COMMAND ${KONKRETCMPI_KONKRET}
- #-m /usr/share/sblim-cmpi-base/Linux_Base.mof
- -m ${MOF_FILE}
+ ${KONKRET_MOF_FILES}
${GENERATE_PROVIDERS}
${CIM_CLASSES}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
diff --git a/src/openlmi.c b/src/openlmi.c
index 786bdd2..c6d808e 100644
--- a/src/openlmi.c
+++ b/src/openlmi.c
@@ -34,11 +34,19 @@ static int _log_level = _LMI_DEBUG_DEBUG;
static const CMPIBroker *_cb = NULL;
static char *_log_id = NULL;
+/** Gets Fully Quantified Domain Name of the system
+ * @return FQDN (must be freed by the caller)
+ */
static char *getFQDN(void)
{
struct utsname uts;
- if ((uname(&uts) > 0) && (uts.nodename != NULL)) {
- return strdup(uts.nodename);
+ if ((uname(&uts) > 0) && (strlen(uts.nodename) > 0)) {
+ char *nodename;
+ if ((nodename = strdup(uts.nodename)) == NULL) {
+ lmi_error("Memory allocation failed");
+ return NULL;
+ }
+ return nodename;
}
char hostname[256];
hostname[255] = '\0';
@@ -59,6 +67,10 @@ static char *getFQDN(void)
if (p->ai_canonname && strstr(p->ai_canonname, "localhost") == NULL) {
char *dn = strdup(p->ai_canonname);
freeaddrinfo(info);
+ if (dn == NULL) {
+ lmi_error("Memory allocation failed");
+ return NULL;
+ }
return dn;
}
}
diff --git a/src/openlmi.h b/src/openlmi.h
index 9b27d07..6ab4158 100644
--- a/src/openlmi.h
+++ b/src/openlmi.h
@@ -65,6 +65,16 @@ int lmi_log_level(void);
*/
void lmi_set_log_level(int level);
+/**
+ * Add an instance \p w to the result \p cr.
+ *
+ * @param cr CMPIResult where should be the instance added
+ * @param w instance to add
+ * @retval true if succeeds
+ * @retval false if addition fails
+ */
+#define LMI_ReturnInstance(cr, w) KOkay(__KReturnInstance((cr), &(w).__base))
+
enum {
_LMI_DEBUG_NONE=0, _LMI_DEBUG_ERROR, _LMI_DEBUG_WARN,
_LMI_DEBUG_INFO, _LMI_DEBUG_DEBUG