diff --git a/ChangeLog b/ChangeLog index d71f38b540c1c3b0f1a1b021fe8b3cd662f0b4e5..2ebf0ac6ea016df432af1ca9e1522493d7d626fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat Sep 29 14:05:41 EST 2007 Daniel P. Berrange + + * src/sexpr.h, src/sexpr.c, src/virsh.c, src/xend_internal.c: + Remove use of anonymous union members in sexpr code. + * src/internal.h: Solaris portability fix (Mark Johnson) + Fri Sep 28 16:41:41 EST 2007 Daniel P. Berrange * src/qemu_conf.c: Fix crash processing multiple tags diff --git a/src/internal.h b/src/internal.h index 2181afe3deec07e2ec37aacc404b6e82a0a043e8..dadb25bcdb43e402c4b8559dd828d54ceb578620 100644 --- a/src/internal.h +++ b/src/internal.h @@ -26,11 +26,6 @@ extern "C" { #define N_(str) dgettext(GETTEXT_PACKAGE, (str)) #define gettext_noop(str) (str) -#ifdef __GNUC__ -#ifdef HAVE_ANSIDECL_H -#include -#endif - /* String equality tests, suggested by Jim Meyering. */ #define STREQ(a,b) (strcmp((a),(b)) == 0) #define STRCASEEQ(a,b) (strcasecmp((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 +#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 index f88de95a45d1f272d102e404e6c51dad70d02367..ed7910e4e7087ac2102a96e326fc7c0b6f6d0219 100644 --- 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 len) 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); + ret->u.value = strdup(str); } - if (ret->value == NULL) { + if (ret->u.value == NULL) { return NULL; } @@ -157,8 +157,8 @@ sexpr_cons(struct sexpr *car, struct sexpr *cdr) 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 @@ static void 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 *buffer, size_t n_buffer) 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 *buffer, size_t n_buffer) 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 * end) 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 * end) 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 char *node) ptr = buffer; token = strsep(&ptr, "/"); - if (sexpr->kind != SEXPR_CONS || sexpr->car->kind != SEXPR_VALUE) { + if (sexpr->kind != SEXPR_CONS || sexpr->u.s.car->kind != SEXPR_VALUE) { return NULL; } - if (strcmp(sexpr->car->value, token) != 0) { + if (strcmp(sexpr->u.s.car->u.value, token) != 0) { return NULL; } @@ -440,16 +440,16 @@ sexpr_lookup(struct sexpr *sexpr, const char *node) 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 char *node) return NULL; } - if (sexpr->kind != SEXPR_CONS || sexpr->cdr->kind != SEXPR_CONS) + if (sexpr->kind != SEXPR_CONS || sexpr->u.s.cdr->kind != SEXPR_CONS) return NULL; - return sexpr->cdr; + return sexpr->u.s.cdr; } /** @@ -484,7 +484,7 @@ sexpr_node(struct sexpr *sexpr, const char *node) { 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 index 89c9205093f2b05afe05984a67e7ab7e2176f113..ecd9f4bdf1560c5abcff7307d0c8815edff9b340 100644 --- 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 index 585cc35d027530f311c3961ce90827cba12f8431..0e47da8f109fee8695041c7a7b2bed507dc1a875 100644 --- a/src/virsh.c +++ b/src/virsh.c @@ -4338,9 +4338,9 @@ vshDomainStateToString(int state) case VIR_DOMAIN_CRASHED: return gettext_noop("crashed"); default: - return gettext_noop("no state"); /* = dom0 state */ + ;/*FALLTHROUGH*/ } - return NULL; + return gettext_noop("no state"); /* = dom0 state */ } static const char * @@ -4354,9 +4354,9 @@ vshDomainVcpuStateToString(int state) case VIR_VCPU_RUNNING: return gettext_noop("running"); default: - return gettext_noop("no state"); + ;/*FALLTHROUGH*/ } - return NULL; + return gettext_noop("no state"); } static int @@ -4868,7 +4868,7 @@ vshParseArgv(vshControl * ctl, int argc, char **argv) } 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 index a1892a7fb5cede0264be884cd36f578494c2e83a..d8a0da378058e787ba0422337fa32712a492c078 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -190,9 +190,9 @@ virXendErrorInt(virConnectPtr conn, virErrorNumber error, int val) #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) \ @@ -662,23 +662,22 @@ xend_node_op(virConnectPtr xend, const char *path, const char *key, ...) * 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 */ /** @@ -961,11 +960,11 @@ xenDaemonListDomainsOld(virConnectPtr xend) 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++; } @@ -977,13 +976,13 @@ xenDaemonListDomainsOld(virConnectPtr xend) 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++; } @@ -1462,8 +1461,8 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersi if ((tmp != NULL) && (tmp[0] != 0)) virBufferVSprintf(&buf, " %s\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.... */ @@ -1702,8 +1701,8 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersi /* 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) { @@ -2903,11 +2902,11 @@ xenDaemonListDomains(virConnectPtr conn, int *ids, int maxids) 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) @@ -2941,8 +2940,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++; @@ -3110,11 +3109,11 @@ xenDaemonDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo, 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; @@ -3131,14 +3130,14 @@ xenDaemonDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo, * 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); } @@ -3660,8 +3659,8 @@ xenDaemonNumOfDefinedDomains(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++; @@ -3690,12 +3689,12 @@ int xenDaemonListDefinedDomains(virConnectPtr conn, char **const names, int maxn 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; }