RFC: vmware registration
Jim Meyering
jim at meyering.net
Thu May 26 09:53:23 UTC 2011
Pete Zaitcev wrote:
> - does not update lease properly
> - is not endian-clean
Wow. That's a big chunk of code.
Thanks, Pete.
I've included a patch below that makes it build when configured like this:
./configure --enable-gcc-warnings
For reference, here are the diagnostics I saw at first:
make[2]: Entering directory `/h/j/w/co/repo'
CC dc_vmware_image-dc-vmware-image.o
dc-vmware-image.c:54:1: error: packed attribute is unnecessary for 'MetaDataMarker' [-Werror=packed]
dc-vmware-image.c: In function 'api_dbcb':
dc-vmware-image.c:287:7: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:290:7: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:293:7: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c: In function 'poke_svcroot':
dc-vmware-image.c:544:7: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:545:8: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c: In function 'poke_Login':
dc-vmware-image.c:639:7: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:640:8: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:633:35: error: variable 'ns_xsd' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:633:27: error: variable 'ns_xsi' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:633:19: error: variable 'ns_enc' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c: In function 'poke_Logout':
dc-vmware-image.c:769:7: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:770:8: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:763:35: error: variable 'ns_xsd' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:763:27: error: variable 'ns_xsi' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:763:19: error: variable 'ns_enc' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c: In function 'v_retr_prop':
dc-vmware-image.c:896:7: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:897:8: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:888:35: error: variable 'ns_xsd' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:888:27: error: variable 'ns_xsi' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:888:19: error: variable 'ns_enc' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c: In function 'v_find_by_name':
dc-vmware-image.c:1062:7: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:1063:8: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:1056:35: error: variable 'ns_xsd' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:1056:27: error: variable 'ns_xsi' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:1056:19: error: variable 'ns_enc' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c: In function 'v_create_import_spec':
dc-vmware-image.c:1255:7: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:1256:8: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:1249:35: error: variable 'ns_xsd' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:1249:27: error: variable 'ns_xsi' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:1249:19: error: variable 'ns_enc' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c: In function 'v_import_vapp':
dc-vmware-image.c:1452:7: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:1453:8: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:1441:35: error: variable 'ns_xsd' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:1441:27: error: variable 'ns_xsi' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:1441:19: error: variable 'ns_enc' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c: In function 'v_lease_progress':
dc-vmware-image.c:2085:7: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:2086:8: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:2079:35: error: variable 'ns_xsd' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:2079:27: error: variable 'ns_xsi' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:2079:19: error: variable 'ns_enc' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c: In function 'v_lease_complete':
dc-vmware-image.c:2197:7: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:2198:8: error: assignment discards 'const' qualifier from pointer target type [-Werror]
dc-vmware-image.c:2191:35: error: variable 'ns_xsd' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:2191:27: error: variable 'ns_xsi' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c:2191:19: error: variable 'ns_enc' set but not used [-Werror=unused-but-set-variable]
dc-vmware-image.c: In function 'convert':
dc-vmware-image.c:2652:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
dc-vmware-image.c:2679:12: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
dc-vmware-image.c:2726:16: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
dc-vmware-image.c: In function 'run_upload':
dc-vmware-image.c:2403:8: error: ignoring return value of 'write', declared with attribute warn_unused_result [-Werror=unused-result]
cc1: all warnings being treated as errors
With this patch, everything compiles warning-free:
>From 434ef66c6692be10b09d7e9e7b3cc55eedc64b23 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Thu, 26 May 2011 11:49:53 +0200
Subject: [PATCH] fix build errors when configured with --enable-gcc-warnings
---
dc-vmware-image.c | 119 ++++++++++++----------------------------------------
1 files changed, 28 insertions(+), 91 deletions(-)
diff --git a/dc-vmware-image.c b/dc-vmware-image.c
index 90d7a18..ebde84d 100644
--- a/dc-vmware-image.c
+++ b/dc-vmware-image.c
@@ -51,7 +51,7 @@ struct MetaDataMarker {
uint32_t type;
unsigned char pad[496];
unsigned char metadata[0];
-} __attribute__((__packed__));
+};
#define MARKER_EOS 0
#define MARKER_GT 1
@@ -278,7 +278,7 @@ static int api_dbcb(CURL *curl, curl_infotype type, char *text, size_t size,
void *arg)
{
enum { IN_TEXT, IN_EOL } state;
- char *tag;
+ const char *tag;
const char *s, *line;
char *p;
@@ -534,7 +534,7 @@ static struct v__ServiceContent *poke_svcroot(struct config *cfg,
CURL *curl = ses->curl;
struct api_buf apib, apob;
struct v__ServiceContent *sc;
- char *proc, *reply;
+ const char *proc, *reply;
xmlDocPtr doc;
xmlNode *etroot;
xmlNode *et;
@@ -626,11 +626,11 @@ static void poke_Login(struct config *cfg, struct session *ses,
xmlNode *thisnode;
xmlChar *thisval;
struct api_buf apib, apob;
- char *proc, *reply;
+ const char *proc, *reply;
xmlChar *buf;
int len;
xmlDoc *reqdoc;
- xmlNsPtr ns_env, ns_enc, ns_xsi, ns_xsd, ns_v;
+ xmlNsPtr ns_env, ns_v;
xmlNode *etroot, *etbody, *etproc;
xmlDoc *respdoc;
xmlNode *et;
@@ -651,14 +651,6 @@ static void poke_Login(struct config *cfg, struct session *ses,
ns_env = xmlNewNs(etroot,
BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/",
BAD_CAST "SOAP-ENV");
- ns_enc = xmlNewNs(etroot,
- BAD_CAST "http://schemas.xmlsoap.org/soap/encoding/",
- BAD_CAST "SOAP-ENC");
- ns_xsi = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
- BAD_CAST "xsi");
- ns_xsd = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema", BAD_CAST "xsd");
ns_v = xmlNewNs(etroot, BAD_CAST "urn:vim25", BAD_CAST "v");
xmlSetNs(etroot, ns_env);
xmlDocSetRootElement(reqdoc, etroot);
@@ -756,11 +748,11 @@ static void poke_Logout(struct config *cfg, struct session *ses,
xmlNode *thisnode;
xmlChar *thisval;
struct api_buf apib, apob;
- char *proc, *reply;
+ const char *proc, *reply;
xmlChar *buf;
int len;
xmlDoc *reqdoc;
- xmlNsPtr ns_env, ns_enc, ns_xsi, ns_xsd, ns_v;
+ xmlNsPtr ns_env, ns_v;
xmlNode *etroot, *etbody, *etlogout;
xmlDoc *respdoc;
xmlNode *et;
@@ -781,14 +773,6 @@ static void poke_Logout(struct config *cfg, struct session *ses,
ns_env = xmlNewNs(etroot,
BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/",
BAD_CAST "SOAP-ENV");
- ns_enc = xmlNewNs(etroot,
- BAD_CAST "http://schemas.xmlsoap.org/soap/encoding/",
- BAD_CAST "SOAP-ENC");
- ns_xsi = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
- BAD_CAST "xsi");
- ns_xsd = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema", BAD_CAST "xsd");
ns_v = xmlNewNs(etroot, BAD_CAST "urn:vim25", BAD_CAST "v");
xmlSetNs(etroot, ns_env);
@@ -880,12 +864,12 @@ static struct v_prop *v_retr_prop(struct config *cfg,
xmlNode *thisnode;
xmlChar *thisval;
struct api_buf apib, apob;
- char *proc, *reply;
+ const char *proc, *reply;
xmlChar *buf;
int len;
struct v_prop *ret;
xmlDoc *reqdoc;
- xmlNsPtr ns_env, ns_enc, ns_xsi, ns_xsd, ns_v;
+ xmlNsPtr ns_env, ns_v;
xmlNode *etroot, *etbody, *etproc;
xmlNode *etprop, *etobj, *etspec;
xmlDoc *respdoc;
@@ -908,14 +892,6 @@ static struct v_prop *v_retr_prop(struct config *cfg,
ns_env = xmlNewNs(etroot,
BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/",
BAD_CAST "SOAP-ENV");
- ns_enc = xmlNewNs(etroot,
- BAD_CAST "http://schemas.xmlsoap.org/soap/encoding/",
- BAD_CAST "SOAP-ENC");
- ns_xsi = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
- BAD_CAST "xsi");
- ns_xsd = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema", BAD_CAST "xsd");
ns_v = xmlNewNs(etroot, BAD_CAST "urn:vim25", BAD_CAST "v");
xmlSetNs(etroot, ns_env);
xmlDocSetRootElement(reqdoc, etroot);
@@ -1047,13 +1023,13 @@ static struct v__ManagedObjectReference *v_find_by_name(struct config *cfg,
xmlNode *thisnode;
xmlChar *thisval;
struct api_buf apib, apob;
- char *proc, *reply;
+ const char *proc, *reply;
xmlChar *buf;
int len;
xmlNode *retval;
struct v__ManagedObjectReference *ret;
xmlDoc *reqdoc;
- xmlNsPtr ns_env, ns_enc, ns_xsi, ns_xsd, ns_v;
+ xmlNsPtr ns_env, ns_v;
xmlNode *etroot, *etbody, *etproc;
xmlDoc *respdoc;
xmlNode *et;
@@ -1074,14 +1050,6 @@ static struct v__ManagedObjectReference *v_find_by_name(struct config *cfg,
ns_env = xmlNewNs(etroot,
BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/",
BAD_CAST "SOAP-ENV");
- ns_enc = xmlNewNs(etroot,
- BAD_CAST "http://schemas.xmlsoap.org/soap/encoding/",
- BAD_CAST "SOAP-ENC");
- ns_xsi = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
- BAD_CAST "xsi");
- ns_xsd = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema", BAD_CAST "xsd");
ns_v = xmlNewNs(etroot, BAD_CAST "urn:vim25", BAD_CAST "v");
xmlSetNs(etroot, ns_env);
xmlDocSetRootElement(reqdoc, etroot);
@@ -1241,12 +1209,12 @@ static struct v__OvfCreateImportSpecResult *v_create_import_spec(
xmlNode *thisnode;
xmlChar *thisval;
struct api_buf apib, apob;
- char *proc, *reply;
+ const char *proc, *reply;
xmlChar *buf;
int len;
struct v__OvfCreateImportSpecResult *ret;
xmlDoc *reqdoc;
- xmlNsPtr ns_env, ns_enc, ns_xsi, ns_xsd, ns_v;
+ xmlNsPtr ns_env, ns_v;
xmlNode *etroot, *etbody, *etproc, *etcisp, *etnetmap;
xmlDoc *respdoc;
xmlNode *et;
@@ -1267,14 +1235,6 @@ static struct v__OvfCreateImportSpecResult *v_create_import_spec(
ns_env = xmlNewNs(etroot,
BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/",
BAD_CAST "SOAP-ENV");
- ns_enc = xmlNewNs(etroot,
- BAD_CAST "http://schemas.xmlsoap.org/soap/encoding/",
- BAD_CAST "SOAP-ENC");
- ns_xsi = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
- BAD_CAST "xsi");
- ns_xsd = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema", BAD_CAST "xsd");
ns_v = xmlNewNs(etroot, BAD_CAST "urn:vim25", BAD_CAST "v");
xmlSetNs(etroot, ns_env);
xmlDocSetRootElement(reqdoc, etroot);
@@ -1432,13 +1392,13 @@ static struct v_lease *v_import_vapp(struct config *cfg, struct session *ses,
{
CURL *curl = ses->curl;
struct api_buf apib, apob;
- char *proc, *reply;
+ const char *proc, *reply;
xmlChar *buf;
int len;
struct v_lease *ret;
xmlChar *rettype, *retval;
xmlDoc *reqdoc;
- xmlNsPtr ns_env, ns_enc, ns_xsi, ns_xsd, ns_v;
+ xmlNsPtr ns_env, ns_v;
xmlNode *etroot, *etbody, *etproc, *etspec;
xmlDoc *respdoc;
xmlNode *et;
@@ -1457,14 +1417,6 @@ static struct v_lease *v_import_vapp(struct config *cfg, struct session *ses,
ns_env = xmlNewNs(etroot,
BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/",
BAD_CAST "SOAP-ENV");
- ns_enc = xmlNewNs(etroot,
- BAD_CAST "http://schemas.xmlsoap.org/soap/encoding/",
- BAD_CAST "SOAP-ENC");
- ns_xsi = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
- BAD_CAST "xsi");
- ns_xsd = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema", BAD_CAST "xsd");
ns_v = xmlNewNs(etroot, BAD_CAST "urn:vim25", BAD_CAST "v");
xmlSetNs(etroot, ns_env);
xmlDocSetRootElement(reqdoc, etroot);
@@ -2072,11 +2024,11 @@ static void v_lease_progress(struct config *cfg, struct session *ses,
CURL *curl = ses->curl;
char buf100[100];
struct api_buf apib, apob;
- char *proc, *reply;
+ const char *proc, *reply;
xmlChar *buf;
int len;
xmlDoc *reqdoc;
- xmlNsPtr ns_env, ns_enc, ns_xsi, ns_xsd, ns_v;
+ xmlNsPtr ns_env, ns_v;
xmlNode *etroot, *etbody, *etproc;
xmlDoc *respdoc;
xmlNode *et;
@@ -2090,14 +2042,6 @@ static void v_lease_progress(struct config *cfg, struct session *ses,
ns_env = xmlNewNs(etroot,
BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/",
BAD_CAST "SOAP-ENV");
- ns_enc = xmlNewNs(etroot,
- BAD_CAST "http://schemas.xmlsoap.org/soap/encoding/",
- BAD_CAST "SOAP-ENC");
- ns_xsi = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
- BAD_CAST "xsi");
- ns_xsd = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema", BAD_CAST "xsd");
ns_v = xmlNewNs(etroot, BAD_CAST "urn:vim25", BAD_CAST "v");
xmlSetNs(etroot, ns_env);
xmlDocSetRootElement(reqdoc, etroot);
@@ -2184,11 +2128,11 @@ static void v_lease_complete(struct config *cfg, struct session *ses,
{
CURL *curl = ses->curl;
struct api_buf apib, apob;
- char *proc, *reply;
+ const char *proc, *reply;
xmlChar *buf;
int len;
xmlDoc *reqdoc;
- xmlNsPtr ns_env, ns_enc, ns_xsi, ns_xsd, ns_v;
+ xmlNsPtr ns_env, ns_v;
xmlNode *etroot, *etbody, *etproc;
xmlDoc *respdoc;
xmlNode *et;
@@ -2202,14 +2146,6 @@ static void v_lease_complete(struct config *cfg, struct session *ses,
ns_env = xmlNewNs(etroot,
BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/",
BAD_CAST "SOAP-ENV");
- ns_enc = xmlNewNs(etroot,
- BAD_CAST "http://schemas.xmlsoap.org/soap/encoding/",
- BAD_CAST "SOAP-ENC");
- ns_xsi = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
- BAD_CAST "xsi");
- ns_xsd = xmlNewNs(etroot,
- BAD_CAST "http://www.w3.org/2001/XMLSchema", BAD_CAST "xsd");
ns_v = xmlNewNs(etroot, BAD_CAST "urn:vim25", BAD_CAST "v");
xmlSetNs(etroot, ns_env);
xmlDocSetRootElement(reqdoc, etroot);
@@ -2400,8 +2336,9 @@ static void run_upload(struct config *cfg, struct session *ses,
if (uploader == 0) {
v_upload(cfg, ses, 0, url, tfd);
status = 3;
- write(pipe_up_report[1], &status, 1);
- exit(0);
+ int err = (write(pipe_up_report[1], &status, 1) == 1
+ ? EXIT_SUCCESS : EXIT_FAILURE);
+ exit(err);
}
close(pipe_up_report[1]);
@@ -2503,13 +2440,13 @@ static void convert(const char *fname, off_t vol_size, int vfd)
struct GrainMarker *gm;
struct MetaDataMarker gtmarker, gdmarker, eosmarker, footmarker;
unsigned int *currentGrainTable, *grainDirectory;
- int cgx, gdx;
+ unsigned long cgx, gdx;
unsigned long inputSectorPointer, outputSectorPointer;
unsigned char *inChunk;
unsigned char *obuf;
size_t cbufsz;
unsigned long chunklen;
- int i;
+ unsigned int i;
ssize_t rrc, wrc;
int rc;
@@ -2651,7 +2588,7 @@ static void convert(const char *fname, off_t vol_size, int vfd)
if (gdx >= grainDirectoryEntries) {
/* Should never happen, see the calculations above. */
- fprintf(stderr, TAG ": GD overflow (%d)\n", gdx);
+ fprintf(stderr, TAG ": GD overflow (%lu)\n", gdx);
exit(EXIT_FAILURE);
}
@@ -2676,7 +2613,7 @@ static void convert(const char *fname, off_t vol_size, int vfd)
wrc = write(vfd, obuf, chunklen);
if (wrc < 0)
goto err_write;
- if (wrc < chunklen)
+ if ((size_t) wrc < chunklen)
goto err_short;
outputSectorPointer += wrc / 512;
}
@@ -2721,12 +2658,12 @@ static void convert(const char *fname, off_t vol_size, int vfd)
goto err_write;
outputSectorPointer += 1;
- printf("Grain directory length (%d)\n", gdx);
+ printf("Grain directory length (%lu)\n", gdx);
printf("Grain directory: ");
for (i = 0; i < grainDirectoryEntries; i++) {
if (i)
printf(", ");
- printf("%d", grainDirectory[i]);
+ printf("%u", grainDirectory[i]);
}
printf("]\n");
--
1.7.5.2.660.g9f46c
More information about the iwhd-devel
mailing list