I've cleaned up the patch from the previous comments...
Sorry I'm off the original thread, switched over to mutt
and am waiting for fetchmail to catch up with gmail..
tested on today's CVS bits on a FC7 dom0
(LD_PRELOAD=src/.libs/libvirt.so src/.libs/virsh)
Thanks,
MRJ
---
fixes to compile with Sun's CC
diff --git a/src/internal.h b/src/internal.h
--- a/src/internal.h
+++ b/src/internal.h
@@ -25,11 +25,6 @@ extern "C" {
#define _(str) dgettext(GETTEXT_PACKAGE, (str))
#define N_(str) dgettext(GETTEXT_PACKAGE, (str))
#define gettext_noop(str) (str)
-
-#ifdef __GNUC__
-#ifdef HAVE_ANSIDECL_H
-#include <ansidecl.h>
-#endif
/* String equality tests, suggested by Jim Meyering. */
#define STREQ(a,b) (strcmp((a),(b)) == 0)
@@ -39,6 +34,15 @@ extern "C" {
#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
+#ifndef __GNUC__
+#define __FUNCTION__ __func__
+#endif
+
+#ifdef __GNUC__
+#ifdef HAVE_ANSIDECL_H
+#include <ansidecl.h>
+#endif
+
/**
* ATTRIBUTE_UNUSED:
*
@@ -61,7 +65,7 @@ extern "C" {
#else
#define ATTRIBUTE_UNUSED
#define ATTRIBUTE_FORMAT(...)
-#endif
+#endif /* __GNUC__ */
/**
* TODO:
diff --git a/src/sexpr.c b/src/sexpr.c
--- a/src/sexpr.c
+++ b/src/sexpr.c
@@ -80,11 +80,11 @@ sexpr_free(struct sexpr *sexpr)
switch (sexpr->kind) {
case SEXPR_CONS:
- sexpr_free(sexpr->car);
- sexpr_free(sexpr->cdr);
+ sexpr_free(sexpr->u.s.car);
+ sexpr_free(sexpr->u.s.cdr);
break;
case SEXPR_VALUE:
- free(sexpr->value);
+ free(sexpr->u.value);
break;
case SEXPR_NIL:
break;
@@ -127,12 +127,12 @@ sexpr_string(const char *str, ssize_t le
return ret;
ret->kind = SEXPR_VALUE;
if (len > 0) {
- ret->value = strndup(str, len);
+ ret->u.value = strndup(str, len);
} else {
- ret->value = strdup(str);
- }
-
- if (ret->value == NULL) {
+ ret->u.value = strdup(str);
+ }
+
+ if (ret->u.value == NULL) {
return NULL;
}
@@ -157,8 +157,8 @@ sexpr_cons(struct sexpr *car, struct sex
if (ret == NULL)
return ret;
ret->kind = SEXPR_CONS;
- ret->car = car;
- ret->cdr = cdr;
+ ret->u.s.car = car;
+ ret->u.s.cdr = cdr;
return ret;
}
@@ -174,12 +174,12 @@ append(struct sexpr *lst, struct sexpr *
append(struct sexpr *lst, struct sexpr *value)
{
while (lst->kind != SEXPR_NIL) {
- lst = lst->cdr;
+ lst = lst->u.s.cdr;
}
lst->kind = SEXPR_CONS;
- lst->car = value;
- lst->cdr = sexpr_nil();
+ lst->u.s.car = value;
+ lst->u.s.cdr = sexpr_nil();
}
/**
@@ -228,18 +228,18 @@ sexpr2string(struct sexpr * sexpr, char
if (tmp == 0)
goto error;
ret += tmp;
- tmp = sexpr2string(sexpr->car, buffer + ret, n_buffer - ret);
+ tmp = sexpr2string(sexpr->u.s.car, buffer + ret, n_buffer - ret);
if (tmp == 0)
goto error;
ret += tmp;
- while (sexpr->cdr->kind != SEXPR_NIL) {
- sexpr = sexpr->cdr;
+ while (sexpr->u.s.cdr->kind != SEXPR_NIL) {
+ sexpr = sexpr->u.s.cdr;
tmp = snprintf(buffer + ret, n_buffer - ret, " ");
if (tmp == 0)
goto error;
ret += tmp;
tmp =
- sexpr2string(sexpr->car, buffer + ret, n_buffer - ret);
+ sexpr2string(sexpr->u.s.car, buffer + ret, n_buffer - ret);
if (tmp == 0)
goto error;
ret += tmp;
@@ -250,12 +250,12 @@ sexpr2string(struct sexpr * sexpr, char
ret += tmp;
break;
case SEXPR_VALUE:
- if (strchr(sexpr->value, ' '))
+ if (strchr(sexpr->u.value, ' '))
tmp = snprintf(buffer + ret, n_buffer - ret, "'%s'",
- sexpr->value);
+ sexpr->u.value);
else
tmp = snprintf(buffer + ret, n_buffer - ret, "%s",
- sexpr->value);
+ sexpr->u.value);
if (tmp == 0)
goto error;
ret += tmp;
@@ -346,8 +346,8 @@ _string2sexpr(const char *buffer, size_t
ptr++;
}
- ret->value = strndup(start, ptr - start);
- if (ret->value == NULL) {
+ ret->u.value = strndup(start, ptr - start);
+ if (ret->u.value == NULL) {
virSexprError(VIR_ERR_NO_MEMORY,
_("failed to copy a string"));
}
@@ -361,15 +361,15 @@ _string2sexpr(const char *buffer, size_t
ptr++;
}
- ret->value = strndup(start, ptr - start);
- if (ret->value == NULL) {
+ ret->u.value = strndup(start, ptr - start);
+ if (ret->u.value == NULL) {
virSexprError(VIR_ERR_NO_MEMORY,
_("failed to copy a string"));
}
}
ret->kind = SEXPR_VALUE;
- if (ret->value == NULL)
+ if (ret->u.value == NULL)
goto error;
}
@@ -426,11 +426,11 @@ sexpr_lookup(struct sexpr *sexpr, const
ptr = buffer;
token = strsep(&ptr, "/");
- if (sexpr->kind != SEXPR_CONS || sexpr->car->kind != SEXPR_VALUE) {
- return NULL;
- }
-
- if (strcmp(sexpr->car->value, token) != 0) {
+ if (sexpr->kind != SEXPR_CONS || sexpr->u.s.car->kind != SEXPR_VALUE) {
+ return NULL;
+ }
+
+ if (strcmp(sexpr->u.s.car->u.value, token) != 0) {
return NULL;
}
@@ -440,16 +440,16 @@ sexpr_lookup(struct sexpr *sexpr, const
if (token == NULL)
continue;
- sexpr = sexpr->cdr;
- for (i = sexpr; i->kind != SEXPR_NIL; i = i->cdr) {
+ sexpr = sexpr->u.s.cdr;
+ for (i = sexpr; i->kind != SEXPR_NIL; i = i->u.s.cdr) {
if (i->kind != SEXPR_CONS ||
- i->car->kind != SEXPR_CONS ||
- i->car->car->kind != SEXPR_VALUE) {
+ i->u.s.car->kind != SEXPR_CONS ||
+ i->u.s.car->u.s.car->kind != SEXPR_VALUE) {
continue;
}
- if (strcmp(i->car->car->value, token) == 0) {
- sexpr = i->car;
+ if (strcmp(i->u.s.car->u.s.car->u.value, token) == 0) {
+ sexpr = i->u.s.car;
break;
}
}
@@ -463,10 +463,10 @@ sexpr_lookup(struct sexpr *sexpr, const
return NULL;
}
- if (sexpr->kind != SEXPR_CONS || sexpr->cdr->kind != SEXPR_CONS)
- return NULL;
-
- return sexpr->cdr;
+ if (sexpr->kind != SEXPR_CONS || sexpr->u.s.cdr->kind != SEXPR_CONS)
+ return NULL;
+
+ return sexpr->u.s.cdr;
}
/**
@@ -484,7 +484,7 @@ sexpr_node(struct sexpr *sexpr, const ch
{
struct sexpr *n = sexpr_lookup(sexpr, node);
- return (n && n->car->kind == SEXPR_VALUE) ? n->car->value :
NULL;
+ return (n && n->u.s.car->kind == SEXPR_VALUE) ?
n->u.s.car->u.value : NULL;
}
/**
diff --git a/src/sexpr.h b/src/sexpr.h
--- a/src/sexpr.h
+++ b/src/sexpr.h
@@ -29,9 +29,9 @@ struct sexpr {
struct {
struct sexpr *car;
struct sexpr *cdr;
- };
+ } s;
char *value;
- };
+ } u;
};
/* conversion to/from strings */
diff --git a/src/virsh.c b/src/virsh.c
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -4295,9 +4295,9 @@ vshDomainStateToString(int state)
case VIR_DOMAIN_CRASHED:
return gettext_noop("crashed");
default:
- return gettext_noop("no state"); /* = dom0 state */
- }
- return NULL;
+ ;/*FALLTHROUGH*/
+ }
+ return gettext_noop("no state"); /* = dom0 state */
}
static const char *
@@ -4311,9 +4311,9 @@ vshDomainVcpuStateToString(int state)
case VIR_VCPU_RUNNING:
return gettext_noop("running");
default:
- return gettext_noop("no state");
- }
- return NULL;
+ ;/*FALLTHROUGH*/
+ }
+ return gettext_noop("no state");
}
static int
@@ -4825,7 +4825,7 @@ vshParseArgv(vshControl * ctl, int argc,
}
last = argv[i];
}
- end = end ? : argc;
+ end = end ? end : argc;
/* standard (non-command) options */
while ((arg = getopt_long(end, argv, "d:hqtc:vrl:", opt, &idx)) != -1)
{
diff --git a/src/xend_internal.c b/src/xend_internal.c
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -189,9 +189,9 @@ virXendErrorInt(virConnectPtr conn, virE
#define foreach(iterator, start) \
- for (_for_i = (start), *iterator = (start)->car; \
+ for (_for_i = (start), *iterator = (start)->u.s.car; \
_for_i->kind == SEXPR_CONS; \
- _for_i = _for_i->cdr, iterator = _for_i->car)
+ _for_i = _for_i->u.s.cdr, iterator = _for_i->u.s.car)
#define foreach_node(iterator, start, path) \
foreach(iterator, start) \
@@ -661,23 +661,22 @@ xend_node_op(virConnectPtr xend, const c
* Returns 0 in case of success, -1 in case of failure.
*/
static int
-xend_op_ext(virConnectPtr xend, const char *name, char *error,
- size_t n_error, const char *key, ...)
+xend_op(virConnectPtr xend, const char *name, const char *key, ...)
{
char buffer[1024];
+ char error[1024];
va_list ap;
int ret;
snprintf(buffer, sizeof(buffer), "/xend/domain/%s", name);
va_start(ap, key);
- ret = xend_op_ext2(xend, buffer, error, n_error, key, ap);
+ ret = xend_op_ext2(xend, buffer, error, sizeof(error), key, ap);
va_end(ap);
return ret;
}
-#define xend_op(xend, name, key, ...) ({char error[1024]; xend_op_ext(xend, name, error,
sizeof(error), key, __VA_ARGS__);})
#endif /* ! PROXY */
/**
@@ -960,11 +959,11 @@ xenDaemonListDomainsOld(virConnectPtr xe
if (root == NULL)
goto error;
- for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
- _for_i = _for_i->cdr, node = _for_i->car) {
+ for (_for_i = root, node = root->u.s.car; _for_i->kind == SEXPR_CONS;
+ _for_i = _for_i->u.s.cdr, node = _for_i->u.s.car) {
if (node->kind != SEXPR_VALUE)
continue;
- extra += strlen(node->value) + 1;
+ extra += strlen(node->u.value) + 1;
count++;
}
@@ -976,13 +975,13 @@ xenDaemonListDomainsOld(virConnectPtr xe
ptr += sizeof(char *) * (count + 1);
i = 0;
- for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
- _for_i = _for_i->cdr, node = _for_i->car) {
+ for (_for_i = root, node = root->u.s.car; _for_i->kind == SEXPR_CONS;
+ _for_i = _for_i->u.s.cdr, node = _for_i->u.s.car) {
if (node->kind != SEXPR_VALUE)
continue;
ret[i] = ptr;
- strcpy(ptr, node->value);
- ptr += strlen(node->value) + 1;
+ strcpy(ptr, node->u.value);
+ ptr += strlen(node->u.value) + 1;
i++;
}
@@ -1461,8 +1460,8 @@ xend_parse_sexp_desc(virConnectPtr conn,
if ((tmp != NULL) && (tmp[0] != 0))
virBufferVSprintf(&buf, "
<emulator>%s</emulator>\n", tmp);
- for (cur = root; cur->kind == SEXPR_CONS; cur = cur->cdr) {
- node = cur->car;
+ for (cur = root; cur->kind == SEXPR_CONS; cur = cur->u.s.cdr) {
+ node = cur->u.s.car;
/* Normally disks are in a (device (vbd ...)) block
but blktap disks ended up in a differently named
(device (tap ....)) block.... */
@@ -1701,8 +1700,8 @@ xend_parse_sexp_desc(virConnectPtr conn,
/* in case of HVM we have devices emulation */
if (hvm) {
- for (cur = sexpr_lookup(root, "domain/image/hvm"); cur &&
cur->kind == SEXPR_CONS; cur = cur->cdr) {
- node = cur->car;
+ for (cur = sexpr_lookup(root, "domain/image/hvm"); cur &&
cur->kind == SEXPR_CONS; cur = cur->u.s.cdr) {
+ node = cur->u.s.car;
if (sexpr_lookup(node, "usbdevice")) {
tmp = sexpr_node(node, "usbdevice");
if (tmp && *tmp) {
@@ -2677,11 +2676,11 @@ xenDaemonListDomains(virConnectPtr conn,
ret = 0;
- for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
- _for_i = _for_i->cdr, node = _for_i->car) {
+ for (_for_i = root, node = root->u.s.car; _for_i->kind == SEXPR_CONS;
+ _for_i = _for_i->u.s.cdr, node = _for_i->u.s.car) {
if (node->kind != SEXPR_VALUE)
continue;
- id = xenDaemonDomainLookupByName_ids(conn, node->value, NULL);
+ id = xenDaemonDomainLookupByName_ids(conn, node->u.value, NULL);
if (id >= 0)
ids[ret++] = (int) id;
if (ret >= maxids)
@@ -2715,8 +2714,8 @@ xenDaemonNumOfDomains(virConnectPtr conn
ret = 0;
- for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
- _for_i = _for_i->cdr, node = _for_i->car) {
+ for (_for_i = root, node = root->u.s.car; _for_i->kind == SEXPR_CONS;
+ _for_i = _for_i->u.s.cdr, node = _for_i->u.s.car) {
if (node->kind != SEXPR_VALUE)
continue;
ret++;
@@ -2884,11 +2883,11 @@ xenDaemonDomainGetVcpus(virDomainPtr dom
memset(cpumaps, 0, maxinfo * maplen);
/* scan the sexprs from "(vcpu (number x)...)" and get parameter values */
- for (s = root; s->kind == SEXPR_CONS; s = s->cdr) {
- if ((s->car->kind == SEXPR_CONS) &&
- (s->car->car->kind == SEXPR_VALUE) &&
- !strcmp(s->car->car->value, "vcpu")) {
- t = s->car;
+ for (s = root; s->kind == SEXPR_CONS; s = s->u.s.cdr) {
+ if ((s->u.s.car->kind == SEXPR_CONS) &&
+ (s->u.s.car->u.s.car->kind == SEXPR_VALUE) &&
+ !strcmp(s->u.s.car->u.s.car->u.value, "vcpu")) {
+ t = s->u.s.car;
vcpu = ipt->number = sexpr_int(t, "vcpu/number");
if ((oln = sexpr_int(t, "vcpu/online")) != 0) {
if (sexpr_int(t, "vcpu/running")) ipt->state =
VIR_VCPU_RUNNING;
@@ -2905,14 +2904,14 @@ xenDaemonDomainGetVcpus(virDomainPtr dom
* get sexpr from "(cpumap (x y z...))" and convert values
* to bitmap
*/
- for (t = t->cdr; t->kind == SEXPR_CONS; t = t->cdr)
- if ((t->car->kind == SEXPR_CONS) &&
- (t->car->car->kind == SEXPR_VALUE) &&
- !strcmp(t->car->car->value, "cpumap")
&&
- (t->car->cdr->kind == SEXPR_CONS)) {
- for (t = t->car->cdr->car; t->kind == SEXPR_CONS; t =
t->cdr)
- if (t->car->kind == SEXPR_VALUE) {
- cpu = strtol(t->car->value, NULL, 0);
+ for (t = t->u.s.cdr; t->kind == SEXPR_CONS; t = t->u.s.cdr)
+ if ((t->u.s.car->kind == SEXPR_CONS) &&
+ (t->u.s.car->u.s.car->kind == SEXPR_VALUE) &&
+ !strcmp(t->u.s.car->u.s.car->u.value,
"cpumap") &&
+ (t->u.s.car->u.s.cdr->kind == SEXPR_CONS)) {
+ for (t = t->u.s.car->u.s.cdr->u.s.car; t->kind ==
SEXPR_CONS; t = t->u.s.cdr)
+ if (t->u.s.car->kind == SEXPR_VALUE) {
+ cpu = strtol(t->u.s.car->u.value, NULL, 0);
if (cpu >= 0 && (VIR_CPU_MAPLEN(cpu+1) <=
maplen)) {
VIR_USE_CPU(cpumap, cpu);
}
@@ -3434,8 +3433,8 @@ xenDaemonNumOfDefinedDomains(virConnectP
ret = 0;
- for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
- _for_i = _for_i->cdr, node = _for_i->car) {
+ for (_for_i = root, node = root->u.s.car; _for_i->kind == SEXPR_CONS;
+ _for_i = _for_i->u.s.cdr, node = _for_i->u.s.car) {
if (node->kind != SEXPR_VALUE)
continue;
ret++;
@@ -3464,12 +3463,12 @@ int xenDaemonListDefinedDomains(virConne
ret = 0;
- for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
- _for_i = _for_i->cdr, node = _for_i->car) {
+ for (_for_i = root, node = root->u.s.car; _for_i->kind == SEXPR_CONS;
+ _for_i = _for_i->u.s.cdr, node = _for_i->u.s.car) {
if (node->kind != SEXPR_VALUE)
continue;
- names[ret++] = strdup(node->value);
+ names[ret++] = strdup(node->u.value);
if (ret >= maxnames)
break;
}