[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] parse container id in separate function



There were several places with parsing container id from code.
Separate function is used now.
Index: src/openvz_conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/openvz_conf.c,v
retrieving revision 1.29
diff -u -p -r1.29 openvz_conf.c
--- src/openvz_conf.c	11 Jul 2008 08:56:16 -0000	1.29
+++ src/openvz_conf.c	18 Jul 2008 13:21:07 -0000
@@ -134,9 +134,7 @@ strtoI(const char *str)
     val = (int) strtol(str, &endptr, base);
 
     /* Check for various possible errors */
-    if ((endptr == str)         /* "No digits were found" */
-        ||((*endptr != '\0')
-            && (*endptr != ' ')) /*"Name contain characters other than integers" */ )
+    if (endptr == str)         /* "No digits were found" */
         return 0;
     return val;
 }
Index: src/openvz_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/openvz_driver.c,v
retrieving revision 1.31
diff -u -p -r1.31 openvz_driver.c
--- src/openvz_driver.c	16 Jul 2008 20:42:38 -0000	1.31
+++ src/openvz_driver.c	18 Jul 2008 13:21:07 -0000
@@ -437,7 +437,7 @@ openvzDomainCreateLinux(virConnectPtr co
         goto exit;
     }
 
-    sscanf(vmdef->name, "%d", &vm->vpsid);
+    vm->vpsid = strtoI(vmdef->name);
     vm->status = VIR_DOMAIN_RUNNING;
     ovz_driver.num_inactive--;
     ovz_driver.num_active++;
@@ -475,7 +475,7 @@ openvzDomainCreate(virDomainPtr dom)
         return -1;
     }
 
-    sscanf(vm->vmdef->name, "%d", &vm->vpsid);
+    vm->vpsid = strtoI(vm->vmdef->name);
     vm->status = VIR_DOMAIN_RUNNING;
     ovz_driver.num_inactive --;
     ovz_driver.num_active ++;
@@ -648,7 +648,7 @@ static int openvzListDomains(virConnectP
     while(got < nids){
         ret = openvz_readline(outfd, buf, 32);
         if(!ret) break;
-        sscanf(buf, "%d", &veid);
+        veid = strtoI(buf);
         ids[got] = veid;
         got ++;
     }
@@ -680,7 +680,7 @@ static int openvzListDefinedDomains(virC
     while(got < nnames){
         ret = openvz_readline(outfd, buf, 32);
         if(!ret) break;
-        sscanf(buf, "%d\n", &veid);
+        veid = strtoI(buf);
         sprintf(vpsname, "%d", veid);
         names[got] = strdup(vpsname);
         got ++;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]