ref: refs/heads/master
commit 4b1f82cc1d3bb1ff99a10404e610beeb42dcecbf
Author: Michael Calmer
Date: Thu Jul 23 14:19:48 2009 +0200
call the installHelper from provider
---
helper/installHelper.cc | 16 +++
helper/installHelper.h | 6 +
helper/test.cc | 2 +
src/CMakeLists.txt | 2 +-
src/SUSE_SoftwareInstallationJobProvider.cc | 36 ++++++-
src/SUSE_SoftwareInstallationServiceProvider.cc | 139 +++++++++++++++++++++++
6 files changed, 197 insertions(+), 4 deletions(-)
diff --git a/helper/installHelper.cc b/helper/installHelper.cc
index 955fb6a..c490cdb 100644
--- a/helper/installHelper.cc
+++ b/helper/installHelper.cc
@@ -52,6 +52,22 @@ try {
USR << *in << endl;
}
+ for(int i = 0; i < 10; ++i)
+ {
+ ShmAccess<Comm> comm( shm(), "Comm" );
+
+ comm->percent = i*10;
+ comm->status = 4;
+ sleep(1);
+ }
+
+ {
+ ShmAccess<Comm> comm( shm(), "Comm" );
+
+ comm->percent = 100;
+ comm->status = 7;
+ }
+
MIL << "Done" << endl;
///////////////////////////////////////////////////////////////////
diff --git a/helper/installHelper.h b/helper/installHelper.h
index c5bb49b..9ec78bd 100644
--- a/helper/installHelper.h
+++ b/helper/installHelper.h
@@ -11,6 +11,12 @@
#define STR_SIZE 256
#define MAX_ANSWERS 10
+/*
+JobState
+Values {"New", "Starting", "Running", "Suspended", "Shutting Down", "Completed", "Terminated", "Killed", "Exception", "Service", "Query Pending", "DMTF Reserved", "Vendor Reserved"}
+ValueMap {"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13..32767", "32768..65535"}
+*/
+
namespace cmpizypp
{
/**
diff --git a/helper/test.cc b/helper/test.cc
index 36445d4..12b8ad6 100644
--- a/helper/test.cc
+++ b/helper/test.cc
@@ -20,10 +20,12 @@ using namespace cmpizypp;
using std::endl;
+/*
void shmDebug()
{
ExternalProgram( "ls -l /dev/shm" ) >> MIL;
}
+*/
namespace cmpizypp
{
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fb0dcdf..964826a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,7 +2,7 @@
# SOURCES #
####################################################################
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../helper)
ADD_DEFINITIONS(-DLOCALEDIR="${CMAKE_INSTALL_PREFIX}/share/locale" -DTEXTDOMAIN="cmpi-zypp" )
diff --git a/src/SUSE_SoftwareInstallationJobProvider.cc b/src/SUSE_SoftwareInstallationJobProvider.cc
index 2159312..9845ac7 100644
--- a/src/SUSE_SoftwareInstallationJobProvider.cc
+++ b/src/SUSE_SoftwareInstallationJobProvider.cc
@@ -12,11 +12,13 @@
#include
#include
+#include "installHelper.h"
#include "SUSE_zypp.h"
#include "SUSE_Common.h"
#include "SUSE_SoftwareInstallationJobProvider.h"
using namespace zypp;
+using namespace boost::interprocess;
using std::endl;
namespace cmpizypp
@@ -88,14 +90,42 @@ CmpiStatus SUSE_SoftwareInstallationJobProviderClass::getInstance( const CmpiCon
CmpiObjectPath op( cop.getNameSpace(), _ClassName );
CmpiInstance ci( op );
+ const char* iid = cop.getKey("InstanceID");
+ std::string instanceid = iid;
+
+ if ( ! str::hasPrefix( instanceid, "SUSE:" ) )
+ {
+ return CmpiStatus(CMPI_RC_ERR_FAILED, "Invalid InstanceID");
+ }
+ std::string pid = instanceid.substr( instanceid.find( ":" )+1);
+
+ uint16_t status = 0;
+ uint16_t percent = 0;
+ uint16_t error = 0;
+
+ {
+ managed_shared_memory managed_shm( open_only, SHM_NAME );
+ ShmAccess<Comm> comm( managed_shm, "Comm" );
+
+ if( pid != str::numstring(comm->pid) )
+ {
+ return CmpiStatus(CMPI_RC_ERR_FAILED, "Invalid InstanceID. No such process.");
+ }
+
+ status = comm->status;
+ percent = comm->percent;
+ error = comm->error;
+ }
+
const char * keys[] = { "InstanceID" };
ci.setPropertyFilter( properties, keys );
- ci.setProperty( "InstanceID", "SUSE:__dummy__" );
+ ci.setProperty( "InstanceID", iid );
ci.setProperty( "Name", "Zypp Software Installation Job");
- ci.setProperty( "JobState", 4 ); //Running
- ci.setProperty( "PercentComplete", 12);
+ ci.setProperty( "JobState", CMPIUint16(status) );
+ ci.setProperty( "PercentComplete", CMPIUint16(percent) );
+ ci.setProperty( "ErrorCode", CMPIUint16(error) );
ci.setProperty( "TimeBeforeRemoval", CmpiDateTime() );
/*
ci.setProperty( "", "");
diff --git a/src/SUSE_SoftwareInstallationServiceProvider.cc b/src/SUSE_SoftwareInstallationServiceProvider.cc
index d7864e7..06a0fbe 100644
--- a/src/SUSE_SoftwareInstallationServiceProvider.cc
+++ b/src/SUSE_SoftwareInstallationServiceProvider.cc
@@ -1,5 +1,8 @@
+#include
+#include
#include <iostream>
+#include <fstream>
#include
#include
@@ -10,12 +13,17 @@
#include
#include
+#include
+#include
+#include
+#include "installHelper.h"
#include "SUSE_zypp.h"
#include "SUSE_Common.h"
#include "SUSE_SoftwareInstallationServiceProvider.h"
using namespace zypp;
+using namespace boost::interprocess;
using std::endl;
namespace cmpizypp
@@ -154,7 +162,138 @@ CmpiStatus SUSE_SoftwareInstallationServiceProviderClass::installFromSoftwareIde
CmpiStatus st(CMPI_RC_ERR_NOT_SUPPORTED);
_CMPIZYPP_TRACE(1,("--- %s CMPI installFromSoftwareIdentity() called.",_ClassName));
+ CmpiArray installOptions;
+ CmpiArray installOptionValues;
+ CmpiObjectPath source(ref.getNameSpace(), "");
+ CmpiObjectPath target(ref.getNameSpace(), "");
+ CmpiObjectPath collection(ref.getNameSpace(), "");
+ const char *siID = "";
+ try
+ {
+ installOptions = static_cast<CmpiArray>(in.getArg("InstallOptions"));
+ }
+ catch(CmpiStatus rc)
+ {
+ _CMPIZYPP_TRACE(1,("--- %s CMPI installFromSoftwareIdentity() failed : %s no InstallOptions", _ClassName, rc.msg()));
+ /*
+ CmpiStatus rc( CMPI_RC_ERR_FAILED, "Missing parameter." );
+ return rc;
+ */
+ }
+ try
+ {
+ installOptionValues = static_cast<CmpiArray>(in.getArg("InstallOptionValues"));
+ }
+ catch(CmpiStatus rc)
+ {
+ _CMPIZYPP_TRACE(1,("--- %s CMPI installFromSoftwareIdentity() failed : %s no InstallOptionValues", _ClassName, rc.msg()));
+ /*
+ CmpiStatus rc( CMPI_RC_ERR_FAILED, "Missing parameter." );
+ return rc;
+ */
+ }
+ try
+ {
+ source = in.getArg("Source");
+ siID = source.getKey("InstanceID");
+ }
+ catch(CmpiStatus rc)
+ {
+ _CMPIZYPP_TRACE(1,("--- %s CMPI installFromSoftwareIdentity() failed : %s no Source", _ClassName, rc.msg()));
+ rslt.returnData( CmpiData(CMPIUint32(2)) ); // Error
+ rslt.returnDone();
+ st = CmpiStatus ( CMPI_RC_OK );
+ return st;
+ }
+ try
+ {
+ target = in.getArg("Target");
+ }
+ catch(CmpiStatus rc)
+ {
+ _CMPIZYPP_TRACE(1,("--- %s CMPI installFromSoftwareIdentity() failed : %s no Target", _ClassName, rc.msg()));
+ rslt.returnData( CmpiData(CMPIUint32(2)) ); // Error
+ rslt.returnDone();
+ st = CmpiStatus ( CMPI_RC_OK );
+ return st;
+ }
+ try
+ {
+ collection = in.getArg("Collection");
+ }
+ catch(CmpiStatus rc)
+ {
+ // we do not support collection
+ }
+
+ if(target.getKeyCount() > 0 && collection.getKeyCount() > 0)
+ {
+ rslt.returnData( CmpiData(CMPIUint32(2)) ); // Error
+ rslt.returnDone();
+ st = CmpiStatus ( CMPI_RC_OK );
+ _CMPIZYPP_TRACE(1,("--- %s CMPI installFromSoftwareIdentity() exited. Unclear to which target should be installed to.",_ClassName));
+ return st;
+ }
+
+ CmpiObjectPath csop = get_this_computersystem(*broker, ctx, target);
+
+ const char *selfccn = csop.getKey("CreationClassName");
+ const char *selfn = csop.getKey("Name");
+
+ const char *tccn = target.getKey("CreationClassName");
+ const char *tn = target.getKey("Name");
+
+ if( tccn == NULL || tn == NULL || selfccn == NULL || selfn == NULL ||
+ ::strcmp(tccn, selfccn) != 0 || ::strcmp(tn, selfn) != 0)
+ {
+ rslt.returnData( CmpiData(CMPIUint32(2)) ); // Error
+ rslt.returnDone();
+ st = CmpiStatus ( CMPI_RC_OK );
+ _CMPIZYPP_TRACE(1,("--- %s CMPI installFromSoftwareIdentity() exited. Unable to install on this target.",_ClassName));
+ return st;
+ }
+
+ // write task list
+ std::string path( zypp::filesystem::TmpFile().path().asString() );
+ std::ofstream o( path.c_str() );
+ o << siID << endl;
+ o.close();
+
+ shared_memory_object::remove(SHM_NAME);
+
+ _CMPIZYPP_TRACE(1,("Creating shared memory"));
+ ::mode_t mask = ::umask( 0077 );
+ managed_shared_memory managed_shm( create_only, SHM_NAME, 65536 );
+ ::umask( mask );
+
+ if ( ! managed_shm.construct<Comm>("Comm")() )
+ {
+ _CMPIZYPP_TRACE(1,("Out of shmem constructing Comm"));
+ throw std::string( "Out of shmem constructing Comm" );
+ }
+
+ ShmAccess<Comm> comm( managed_shm, "Comm" ); // blocks the helper
+
+ strncpy( comm->dataStr, path.c_str(), STR_SIZE );
+
+ _CMPIZYPP_TRACE(1,("fork and execute installHelper"));
+ ExternalProgram helper( "/usr/lib/cmpi-zypp/installHelper" );
+
+ _CMPIZYPP_TRACE(1,("installHelper started (%d)", helper.getpid() ));
+
+ comm->pid = helper.getpid();
+ comm.release(); // go...
+
+ CmpiObjectPath jobOP(target.getNameSpace(), "SUSE_SoftwareInstallationJob");
+ jobOP.setKey("InstanceID", str::form("SUSE:%d", helper.getpid()).c_str());
+ CmpiInstance job( broker->getInstance( ctx, jobOP, NULL ) ); // source instance
+
+ out.setArg("Job", CmpiData(job.getObjectPath()));
+
+ rslt.returnData( CmpiData(CMPIUint32(4096)) ); //Job Started
+ rslt.returnDone();
+ st = CmpiStatus ( CMPI_RC_OK );
_CMPIZYPP_TRACE(1,("--- %s CMPI installFromSoftwareIdentity() exited.",_ClassName));
return st;
}
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org