* src/internal.h src/xend_internal.c: a better fix from Shigeki Sakamoto

and raising errors on memory shortage.
Daniel
This commit is contained in:
Daniel Veillard 2007-04-24 13:44:16 +00:00
parent b371d037b2
commit c847530f97
3 changed files with 34 additions and 16 deletions

View File

@ -1,3 +1,8 @@
Tue Apr 24 15:43:04 CEST 2007 Daniel Veillard <veillard@redhat.com>
* src/internal.h src/xend_internal.c: a better fix from Shigeki Sakamoto
and raising errors on memory shortage.
Mon Apr 23 09:38:16 CEST 2007 Daniel Veillard <veillard@redhat.com> Mon Apr 23 09:38:16 CEST 2007 Daniel Veillard <veillard@redhat.com>
* src/internal.h src/xend_internal.c src/xml.c: applied 2 bug fixes * src/internal.h src/xend_internal.c src/xml.c: applied 2 bug fixes

View File

@ -105,11 +105,6 @@ extern "C" {
*/ */
#define VIR_CONNECT_RO 1 #define VIR_CONNECT_RO 1
/**
* buffer size for definition file
*/
#define VIR_XML_STRING_BUFLEN (1024 + PATH_MAX * 16 + FILENAME_MAX * 16)
/** /**
* _virConnect: * _virConnect:
* *

View File

@ -587,24 +587,35 @@ static int
xend_op_ext2(virConnectPtr xend, const char *path, char *error, xend_op_ext2(virConnectPtr xend, const char *path, char *error,
size_t n_error, const char *key, va_list ap) size_t n_error, const char *key, va_list ap)
{ {
char ops[VIR_XML_STRING_BUFLEN];
const char *k = key, *v; const char *k = key, *v;
int offset = 0; virBuffer buf;
int ret;
buf.content = malloc(1000);
if (buf.content == NULL) {
virXendError(xend, VIR_ERR_NO_MEMORY, _("allocate new buffer"));
return -1;
}
buf.size = 1000;
buf.use = 0;
while (k) { while (k) {
v = va_arg(ap, const char *); v = va_arg(ap, const char *);
offset += snprintf(ops + offset, sizeof(ops) - offset, "%s", k); virBufferVSprintf(&buf, "%s", k);
offset += snprintf(ops + offset, sizeof(ops) - offset, "%s", "="); virBufferVSprintf(&buf, "%s", "=");
offset += snprintf(ops + offset, sizeof(ops) - offset, "%s", v); virBufferVSprintf(&buf, "%s", v);
k = va_arg(ap, const char *); k = va_arg(ap, const char *);
if (k) if (k)
offset += snprintf(ops + offset, virBufferVSprintf(&buf, "%s", "&");
sizeof(ops) - offset, "%s", "&");
} }
return http2unix(xend, xend_post(xend, path, ops, error, n_error)); ret = http2unix(xend, xend_post(xend, path, buf.content, error, n_error));
if (buf.content != NULL)
free(buf.content);
return ret;
} }
@ -797,8 +808,10 @@ urlencode(const char *string)
char *ptr = buffer; char *ptr = buffer;
size_t i; size_t i;
if (buffer == NULL) if (buffer == NULL) {
virXendError(NULL, VIR_ERR_NO_MEMORY, _("allocate new buffer"));
return (NULL); return (NULL);
}
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
switch (string[i]) { switch (string[i]) {
case ' ': case ' ':
@ -2184,13 +2197,18 @@ int
xenDaemonDomainSave(virDomainPtr domain, const char *filename) xenDaemonDomainSave(virDomainPtr domain, const char *filename)
{ {
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) || if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
(filename == NULL)) { (filename == NULL) || (domain->id < 0)) {
virXendError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG, virXendError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
__FUNCTION__); __FUNCTION__);
return(-1); return(-1);
} }
if (domain->id < 0)
/* We can't save the state of Domain-0, that would mean stopping it too */
if (domain->id == 0) {
return(-1); return(-1);
}
return xend_op(domain->conn, domain->name, "op", "save", "file", filename, NULL); return xend_op(domain->conn, domain->name, "op", "save", "file", filename, NULL);
} }