]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fri Jun 22 12:40:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
authorRichard W.M. Jones <rjones@redhat.com>
Fri, 22 Jun 2007 11:42:22 +0000 (11:42 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Fri, 22 Jun 2007 11:42:22 +0000 (11:42 +0000)
* src/internal.h: Added STREQ and STRCASEEQ macros for clearer
  equality testing of strings.
* src/xen_internal.c: Fix handling of the scheduler parameters
  field string so that the field doesn't contain garbage
  after the string.

ChangeLog
src/internal.h
src/xen_internal.c

index 30311f2890db1850919cbf7bbab19a97bd453ee2..ca38f9763bf65b8a462db6057622c071d0ed96af 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Fri Jun 22 12:40:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
+
+       * src/internal.h: Added STREQ and STRCASEEQ macros for clearer
+         equality testing of strings.
+       * src/xen_internal.c: Fix handling of the scheduler parameters
+         field string so that the field doesn't contain garbage
+         after the string.
+
 Fri Jun 22 12:14:40 CEST 2007 Daniel Veillard <veillard@redhat.com>
 
        * qemud/driver.c: apply patch from Jim Meyering to handle realloc
index 20bf251a5ee3f5173511c58f0b30b2dcea06c970..51f5349d7820a563bd9734395e9a7227ac7ecf98 100644 (file)
@@ -31,6 +31,10 @@ extern "C" {
 #include <ansidecl.h>
 #endif
 
+/* String equality tests, suggested by Jim Meyering. */
+#define STREQ(a,b) (strcmp((a),(b)) == 0)
+#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
+
 /**
  * ATTRIBUTE_UNUSED:
  *
index f6649cc36e7255b62a479b4e85b83582e2dce362..36c1374cf9156dc0fe99c9b076f61da3ef8bd0f8 100644 (file)
@@ -1053,6 +1053,9 @@ xenHypervisorGetSchedulerType(virDomainPtr domain, int *nparams)
     return schedulertype;
 }
 
+static const char *str_weight = "weight";
+static const char *str_cap = "cap";
+
 /**
  * xenHypervisorGetSchedulerParameters:
  * @domain: pointer to the Xen Hypervisor block
@@ -1071,8 +1074,6 @@ xenHypervisorGetSchedulerParameters(virDomainPtr domain,
                                 virSchedParameterPtr params, int *nparams)
 {
     xenUnifiedPrivatePtr priv;
-    char str_weight[] ="weight";
-    char str_cap[]    ="cap";
 
     if ((domain == NULL) || (domain->conn == NULL)) {
         virXenErrorFunc(VIR_ERR_INTERNAL_ERROR, __FUNCTION__,
@@ -1126,11 +1127,13 @@ xenHypervisorGetSchedulerParameters(virDomainPtr domain,
                if (ret < 0)
                    return(-1);
 
-               strncpy(params[0].field, str_weight, strlen(str_weight));
+               strncpy (params[0].field, str_weight, VIR_DOMAIN_SCHED_FIELD_LENGTH);
+        params[0].field[VIR_DOMAIN_SCHED_FIELD_LENGTH-1] = '\0';
                params[0].type = VIR_DOMAIN_SCHED_FIELD_UINT;
                params[0].value.ui = op_dom.u.getschedinfo.u.credit.weight;
 
-               strncpy(params[1].field, str_cap, strlen(str_cap));
+               strncpy (params[1].field, str_cap, VIR_DOMAIN_SCHED_FIELD_LENGTH);
+        params[1].field[VIR_DOMAIN_SCHED_FIELD_LENGTH-1] = '\0';
                params[1].type = VIR_DOMAIN_SCHED_FIELD_UINT;
                params[1].value.ui = op_dom.u.getschedinfo.u.credit.cap;
 
@@ -1161,8 +1164,6 @@ xenHypervisorSetSchedulerParameters(virDomainPtr domain,
 {
     int i;
     xenUnifiedPrivatePtr priv;
-    char str_weight[] ="weight";
-    char str_cap[]    ="cap";
 
     if ((domain == NULL) || (domain->conn == NULL)) {
         virXenErrorFunc (VIR_ERR_INTERNAL_ERROR, __FUNCTION__,
@@ -1220,18 +1221,18 @@ xenHypervisorSetSchedulerParameters(virDomainPtr domain,
             op_dom.u.getschedinfo.cmd = XEN_DOMCTL_SCHEDOP_putinfo;
 
             /*
-            * credit scheduler parameters 
-             * following values do not change the parameters 
+             * credit scheduler parameters
+             * following values do not change the parameters
              */
             op_dom.u.getschedinfo.u.credit.weight = 0;
             op_dom.u.getschedinfo.u.credit.cap    = (uint16_t)~0U;
 
             for (i = 0; i < nparams; i++) {
-                if (!strncmp(params[i].field,str_weight,strlen(str_weight)) &&
+                if (STREQ (params[i].field, str_weight) &&
                     params[i].type == VIR_DOMAIN_SCHED_FIELD_UINT) {
                     op_dom.u.getschedinfo.u.credit.weight = params[i].value.ui;
                    weight_set = 1;
-               } else if (!strncmp(params[i].field,str_cap,strlen(str_cap)) &&
+               } else if (STREQ (params[i].field, str_cap) &&
                     params[i].type == VIR_DOMAIN_SCHED_FIELD_UINT) {
                     op_dom.u.getschedinfo.u.credit.cap = params[i].value.ui;
                    cap_set = 1;