mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 02:51:16 +00:00
cleaning up integer string parsing
* src/openvz_conf.c src/openvz_driver.c: patch from Evgeniy Sokolov cleaning up integer string parsing. Daniel
This commit is contained in:
parent
f92e0898d3
commit
7e73b8b61a
@ -1,3 +1,8 @@
|
|||||||
|
Mon Jul 21 15:31:52 CEST 2008 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
|
* src/openvz_conf.c src/openvz_driver.c: patch from Evgeniy Sokolov
|
||||||
|
cleaning up integer string parsing.
|
||||||
|
|
||||||
Mon Jul 21 11:47:08 CEST 2008 Daniel Veillard <veillard@redhat.com>
|
Mon Jul 21 11:47:08 CEST 2008 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* src/xen_unified.c: fix a leak in xenUnifiedOpen
|
* src/xen_unified.c: fix a leak in xenUnifiedOpen
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
#include "buf.h"
|
#include "buf.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static char *openvzLocateConfDir(void);
|
static char *openvzLocateConfDir(void);
|
||||||
static struct openvz_vm_def *openvzParseXML(virConnectPtr conn, xmlDocPtr xml);
|
static struct openvz_vm_def *openvzParseXML(virConnectPtr conn, xmlDocPtr xml);
|
||||||
@ -127,17 +128,11 @@ struct openvz_vm
|
|||||||
int
|
int
|
||||||
strtoI(const char *str)
|
strtoI(const char *str)
|
||||||
{
|
{
|
||||||
int base = 10;
|
|
||||||
char *endptr;
|
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
val = (int) strtol(str, &endptr, base);
|
if (virStrToLong_i(str, NULL, 10, &val) < 0)
|
||||||
|
return 0 ;
|
||||||
|
|
||||||
/* Check for various possible errors */
|
|
||||||
if ((endptr == str) /* "No digits were found" */
|
|
||||||
||((*endptr != '\0')
|
|
||||||
&& (*endptr != ' ')) /*"Name contain characters other than integers" */ )
|
|
||||||
return 0;
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,7 +449,7 @@ openvzDomainCreateLinux(virConnectPtr conn, const char *xml,
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
sscanf(vmdef->name, "%d", &vm->vpsid);
|
vm->vpsid = strtoI(vmdef->name);
|
||||||
vm->status = VIR_DOMAIN_RUNNING;
|
vm->status = VIR_DOMAIN_RUNNING;
|
||||||
ovz_driver.num_inactive--;
|
ovz_driver.num_inactive--;
|
||||||
ovz_driver.num_active++;
|
ovz_driver.num_active++;
|
||||||
@ -487,7 +487,7 @@ openvzDomainCreate(virDomainPtr dom)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sscanf(vm->vmdef->name, "%d", &vm->vpsid);
|
vm->vpsid = strtoI(vm->vmdef->name);
|
||||||
vm->status = VIR_DOMAIN_RUNNING;
|
vm->status = VIR_DOMAIN_RUNNING;
|
||||||
ovz_driver.num_inactive --;
|
ovz_driver.num_inactive --;
|
||||||
ovz_driver.num_active ++;
|
ovz_driver.num_active ++;
|
||||||
@ -648,6 +648,7 @@ static int openvzListDomains(virConnectPtr conn, int *ids, int nids) {
|
|||||||
int veid, pid, outfd, errfd;
|
int veid, pid, outfd, errfd;
|
||||||
int ret;
|
int ret;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
char *endptr;
|
||||||
const char *cmd[] = {VZLIST, "-ovpsid", "-H" , NULL};
|
const char *cmd[] = {VZLIST, "-ovpsid", "-H" , NULL};
|
||||||
|
|
||||||
ret = virExec(conn, (char **)cmd, &pid, -1, &outfd, &errfd);
|
ret = virExec(conn, (char **)cmd, &pid, -1, &outfd, &errfd);
|
||||||
@ -660,7 +661,11 @@ static int openvzListDomains(virConnectPtr conn, int *ids, int nids) {
|
|||||||
while(got < nids){
|
while(got < nids){
|
||||||
ret = openvz_readline(outfd, buf, 32);
|
ret = openvz_readline(outfd, buf, 32);
|
||||||
if(!ret) break;
|
if(!ret) break;
|
||||||
sscanf(buf, "%d", &veid);
|
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
|
||||||
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Could not parse VPS ID %s"), buf);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ids[got] = veid;
|
ids[got] = veid;
|
||||||
got ++;
|
got ++;
|
||||||
}
|
}
|
||||||
@ -679,6 +684,7 @@ static int openvzListDefinedDomains(virConnectPtr conn,
|
|||||||
int veid, pid, outfd, errfd, ret;
|
int veid, pid, outfd, errfd, ret;
|
||||||
char vpsname[OPENVZ_NAME_MAX];
|
char vpsname[OPENVZ_NAME_MAX];
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
char *endptr;
|
||||||
const char *cmd[] = {VZLIST, "-ovpsid", "-H", "-S", NULL};
|
const char *cmd[] = {VZLIST, "-ovpsid", "-H", "-S", NULL};
|
||||||
|
|
||||||
/* the -S options lists only stopped domains */
|
/* the -S options lists only stopped domains */
|
||||||
@ -692,7 +698,11 @@ static int openvzListDefinedDomains(virConnectPtr conn,
|
|||||||
while(got < nnames){
|
while(got < nnames){
|
||||||
ret = openvz_readline(outfd, buf, 32);
|
ret = openvz_readline(outfd, buf, 32);
|
||||||
if(!ret) break;
|
if(!ret) break;
|
||||||
sscanf(buf, "%d\n", &veid);
|
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
|
||||||
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Could not parse VPS ID %s"), buf);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
sprintf(vpsname, "%d", veid);
|
sprintf(vpsname, "%d", veid);
|
||||||
names[got] = strdup(vpsname);
|
names[got] = strdup(vpsname);
|
||||||
got ++;
|
got ++;
|
||||||
|
Loading…
Reference in New Issue
Block a user