diff options
author | Vitezslav Crhonek <vcrhonek@redhat.com> | 2014-04-08 12:31:36 +0200 |
---|---|---|
committer | Vitezslav Crhonek <vcrhonek@redhat.com> | 2014-04-08 12:31:36 +0200 |
commit | 5f780e8c3e4de8866af4a71e22b956533ffca9ca (patch) | |
tree | 47ea4d9acd8fb18e0535d3928f2fbeb965620bbd /src/service | |
parent | 0a787ccd00a0de14940c347a368c2bee3b60c6f9 (diff) | |
download | openlmi-providers-5f780e8c3e4de8866af4a71e22b956533ffca9ca.tar.gz openlmi-providers-5f780e8c3e4de8866af4a71e22b956533ffca9ca.tar.xz openlmi-providers-5f780e8c3e4de8866af4a71e22b956533ffca9ca.zip |
Service (non d-bus): Use mkstemp instead of mktemp and minor updates
Diffstat (limited to 'src/service')
-rw-r--r-- | src/service/90_LMI_Service_Profile.mof.skel | 22 | ||||
-rw-r--r-- | src/service/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/service/cmpiLMI_Service-cimprovagt | 21 | ||||
-rw-r--r-- | src/service/util/serviceutil.c | 35 | ||||
-rw-r--r-- | src/service/util/serviceutil.h | 1 |
5 files changed, 71 insertions, 16 deletions
diff --git a/src/service/90_LMI_Service_Profile.mof.skel b/src/service/90_LMI_Service_Profile.mof.skel new file mode 100644 index 0000000..ff34bd5 --- /dev/null +++ b/src/service/90_LMI_Service_Profile.mof.skel @@ -0,0 +1,22 @@ +instance of PG_ProviderProfileCapabilities +{ + CapabilityID = "@CLASS@"; + + ProviderModuleName = "cmpiLMI_Service"; + + ProviderName = "@CLASS@"; + + RegisteredProfile = 0; + + OtherRegisteredProfile = "OpenLMI-Service"; + OtherProfileOrganization = "OpenLMI"; + + ProfileVersion = "@VERSION@"; + + RegisteredSubProfiles = {}; + + ConformingElements = { + "@CLASS@" + }; +}; + diff --git a/src/service/CMakeLists.txt b/src/service/CMakeLists.txt index 34d766e..11ac5c8 100644 --- a/src/service/CMakeLists.txt +++ b/src/service/CMakeLists.txt @@ -2,6 +2,7 @@ set(PROVIDER_NAME Service) set(LIBRARY_NAME cmpiLMI_${PROVIDER_NAME}) set(MOF 60_LMI_Service.mof) +set(CIMPROVAGT_SCRIPT cmpiLMI_${PROVIDER_NAME}-cimprovagt) set(provider_SRCS util/serviceutil.c @@ -10,6 +11,7 @@ set(provider_SRCS konkretcmpi_generate(${MOF} CIM_PROVIDERS CIM_HEADERS + CIM_CLASSES ) add_library(${LIBRARY_NAME} SHARED @@ -24,6 +26,10 @@ target_link_libraries(${LIBRARY_NAME} openlmicommon ${KONKRETCMPI_LIBRARIES}) # Create registration file cim_registration(${PROVIDER_NAME} ${LIBRARY_NAME} ${MOF} share/openlmi-providers) -install(PROGRAMS util/servicedisc.sh util/serviceutil.sh DESTINATION libexec) +set(TARGET_MOF "${CMAKE_BINARY_DIR}/mof/90_LMI_Service_Profile.mof") +profile_mof_generate("90_LMI_Service_Profile.mof.skel" "${TARGET_MOF}" "LMI_Service") +install(PROGRAMS util/servicedisc.sh util/serviceutil.sh DESTINATION libexec) +install(PROGRAMS ${CIMPROVAGT_SCRIPT} DESTINATION libexec/pegasus) install(TARGETS ${LIBRARY_NAME} DESTINATION lib${LIB_SUFFIX}/cmpi) +install(FILES ${TARGET_MOF} DESTINATION share/openlmi-providers/) diff --git a/src/service/cmpiLMI_Service-cimprovagt b/src/service/cmpiLMI_Service-cimprovagt new file mode 100644 index 0000000..f6c8842 --- /dev/null +++ b/src/service/cmpiLMI_Service-cimprovagt @@ -0,0 +1,21 @@ +#!/bin/sh +# +# Copyright (C) 2013 Red Hat, Inc. All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Authors: Jan Synacek <jsynacek@redhat.com> + +/usr/libexec/pegasus/cimprovagt "$@" diff --git a/src/service/util/serviceutil.c b/src/service/util/serviceutil.c index ef95497..e2a041e 100644 --- a/src/service/util/serviceutil.c +++ b/src/service/util/serviceutil.c @@ -205,22 +205,27 @@ Service_Operation(const char *service, const char *method, char *result, int res { int res = 0; char cmdbuffer[OPERATION_BUFSIZE]; - FILE *fcmdout = NULL; - char *cmdout = strdup("/tmp/Service_OperationXXXXXX"); - cmdout = mktemp(cmdout); + const char *const proc_path = "/proc/self/fd/"; + char template[] = "/tmp/Service_OperationXXXXXX"; - snprintf(cmdbuffer, OPERATION_BUFSIZE, "%s %s %s > %s", suscript, method, service, cmdout); - if (system(cmdbuffer) == 0) - { - /* we got some output? */ - if ((fcmdout = fopen(cmdout, "r")) == NULL) - { - result = fgets(result, resultlen, fcmdout); - fclose(fcmdout); - res = 0; - } + int tfd = mkstemp(template); + if (tfd == -1) { + return -1; } - unlink(cmdout); - free(cmdout); + unlink(template); + + const int cmd_size = snprintf(NULL, 0, "%s%ul", proc_path, tfd); + char cmd[cmd_size]; + snprintf(cmd, cmd_size, "%s%ul", proc_path, tfd); + + snprintf(cmdbuffer, OPERATION_BUFSIZE, "%s %s %s > %s", suscript, method, service, cmd); + if (system(cmdbuffer) != 0) { + return -1; + } + + /* we got some output? */ + read(tfd, result, resultlen); + close(tfd); + res = 0; return res; } diff --git a/src/service/util/serviceutil.h b/src/service/util/serviceutil.h index 3519ddf..d0b6663 100644 --- a/src/service/util/serviceutil.h +++ b/src/service/util/serviceutil.h @@ -23,6 +23,7 @@ #define SERVICEUTIL_H #include <stdio.h> +#include "openlmi.h" #define ARRAY_SIZE(name) (sizeof(name) / sizeof(name[0])) |