# HG changeset patch
# User kaitlin(a)elm3b43.beaverton.ibm.com
# Date 1224552270 25200
# Node ID 70f7f862b11c456e9c77d0b6729bdadb086dba44
# Parent 63aa217c697828d29e5e04d546227a32d75ff9c3
(#3) Have get_console_sap_by_name() use Name attribute to determine session
Updates from 2 to 3:
-Check malloc() and strdup() returns
-Remove unneeded NULL initialization
Updates from 1 to 2:
-Removed function that parses the Name attribute
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 63aa217c6978 -r 70f7f862b11c src/Virt_KVMRedirectionSAP.c
--- a/src/Virt_KVMRedirectionSAP.c Mon Oct 20 18:24:30 2008 -0700
+++ b/src/Virt_KVMRedirectionSAP.c Mon Oct 20 18:24:30 2008 -0700
@@ -343,7 +343,7 @@
CMPIStatus get_console_sap_by_name(const CMPIBroker *broker,
const CMPIObjectPath *ref,
- const char *name,
+ const char *sys,
CMPIInstance **_inst)
{
virConnectPtr conn;
@@ -351,6 +351,10 @@
CMPIStatus s = {CMPI_RC_OK, NULL};
CMPIInstance *inst = NULL;
struct domain *dominfo = NULL;
+ struct vnc_port *port = NULL;
+ const char *name = NULL;
+ int lport;
+ int rport;
conn = connect_by_classname(broker, CLASSNAME(ref), &s);
if (conn == NULL) {
@@ -360,12 +364,12 @@
goto out;
}
- dom = virDomainLookupByName(conn, name);
+ dom = virDomainLookupByName(conn, sys);
if (dom == NULL) {
cu_statusf(broker, &s,
CMPI_RC_ERR_NOT_FOUND,
"No such instance (%s)",
- name);
+ sys);
goto out;
}
@@ -373,9 +377,43 @@
cu_statusf(broker, &s,
CMPI_RC_ERR_FAILED,
"No console device for this guest");
+ goto out;
}
- inst = get_console_sap(_BROKER, ref, conn, dominfo, &s);
+ if (cu_get_str_path(ref, "Name", &name) != CMPI_RC_OK) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance (System)");
+ goto out;
+ }
+
+ if (sscanf(name, "%d:%d", &lport, &rport) != 2) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to guest's console port");
+ goto out;
+ }
+
+ port = malloc(sizeof(struct vnc_port));
+ if (port == NULL) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to allocate guest port struct");
+ goto out;
+ }
+
+ port->name = strdup(dominfo->name);
+ if (port->name == NULL) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to allocate string");
+ goto out;
+ }
+
+ port->port = lport;
+ port->remote_port = rport;
+
+ inst = get_console_sap(_BROKER, ref, conn, port, &s);
virDomainFree(dom);
@@ -386,6 +424,8 @@
out:
virConnectClose(conn);
+ free(port->name);
+ free(port);
return s;
}
@@ -398,10 +438,10 @@
CMPIInstance *inst = NULL;
const char *sys = NULL;
- if (cu_get_str_path(reference, "System", &sys) != CMPI_RC_OK) {
+ if (cu_get_str_path(reference, "SystemName", &sys) != CMPI_RC_OK)
{
cu_statusf(broker, &s,
CMPI_RC_ERR_NOT_FOUND,
- "No such instance (System)");
+ "No such instance (SystemName)");
goto out;
}