提交 64a4c60e 编写于 作者: M Matthias Bolte

phyp: Fix several UUID table related problems

- Make reading ID from file working for IDs > 127
- Fix inverse error check for writing ID to file
- Use feof() to distinguish EOF from real error of fread()
- Don't interpret libssh2 error codes as number of bytes
上级 cdf7a40d
...@@ -1735,7 +1735,7 @@ phypUUIDTable_ReadFile(virConnectPtr conn) ...@@ -1735,7 +1735,7 @@ phypUUIDTable_ReadFile(virConnectPtr conn)
int fd = -1; int fd = -1;
char local_file[] = "./uuid_table"; char local_file[] = "./uuid_table";
int rc = 0; int rc = 0;
char buffer[1024]; int id;
if ((fd = open(local_file, O_RDONLY)) == -1) { if ((fd = open(local_file, O_RDONLY)) == -1) {
VIR_WARN("%s", "Unable to write information to local file."); VIR_WARN("%s", "Unable to write information to local file.");
...@@ -1746,13 +1746,13 @@ phypUUIDTable_ReadFile(virConnectPtr conn) ...@@ -1746,13 +1746,13 @@ phypUUIDTable_ReadFile(virConnectPtr conn)
if (VIR_ALLOC_N(uuid_table->lpars, uuid_table->nlpars) >= 0) { if (VIR_ALLOC_N(uuid_table->lpars, uuid_table->nlpars) >= 0) {
for (i = 0; i < uuid_table->nlpars; i++) { for (i = 0; i < uuid_table->nlpars; i++) {
rc = read(fd, buffer, sizeof(int)); rc = read(fd, &id, sizeof(int));
if (rc == sizeof(int)) { if (rc == sizeof(int)) {
if (VIR_ALLOC(uuid_table->lpars[i]) < 0) { if (VIR_ALLOC(uuid_table->lpars[i]) < 0) {
virReportOOMError(conn); virReportOOMError(conn);
goto err; goto err;
} }
uuid_table->lpars[i]->id = (*buffer); uuid_table->lpars[i]->id = id;
} else { } else {
VIR_WARN("%s", VIR_WARN("%s",
"Unable to read from information to local file."); "Unable to read from information to local file.");
...@@ -1790,7 +1790,7 @@ phypUUIDTable_WriteFile(virConnectPtr conn) ...@@ -1790,7 +1790,7 @@ phypUUIDTable_WriteFile(virConnectPtr conn)
for (i = 0; i < uuid_table->nlpars; i++) { for (i = 0; i < uuid_table->nlpars; i++) {
if (safewrite(fd, &uuid_table->lpars[i]->id, if (safewrite(fd, &uuid_table->lpars[i]->id,
sizeof(uuid_table->lpars[i]->id)) == sizeof(uuid_table->lpars[i]->id)) !=
sizeof(uuid_table->lpars[i]->id)) { sizeof(uuid_table->lpars[i]->id)) {
VIR_ERROR("%s", "Unable to write information to local file."); VIR_ERROR("%s", "Unable to write information to local file.");
goto err; goto err;
...@@ -1944,8 +1944,13 @@ phypUUIDTable_Push(virConnectPtr conn) ...@@ -1944,8 +1944,13 @@ phypUUIDTable_Push(virConnectPtr conn)
do { do {
nread = fread(buffer, 1, sizeof(buffer), fd); nread = fread(buffer, 1, sizeof(buffer), fd);
if (nread <= 0) { if (nread <= 0) {
/* end of file */ if (feof(fd)) {
break; /* end of file */
break;
} else {
VIR_ERROR("Failed to read from '%s'", local_file);
goto err;
}
} }
ptr = buffer; ptr = buffer;
sent = 0; sent = 0;
...@@ -1955,7 +1960,7 @@ phypUUIDTable_Push(virConnectPtr conn) ...@@ -1955,7 +1960,7 @@ phypUUIDTable_Push(virConnectPtr conn)
rc = libssh2_channel_write(channel, ptr, nread); rc = libssh2_channel_write(channel, ptr, nread);
if (LIBSSH2_ERROR_EAGAIN == rc) { /* must loop around */ if (LIBSSH2_ERROR_EAGAIN == rc) { /* must loop around */
continue; continue;
} else { } else if (rc > 0) {
/* rc indicates how many bytes were written this time */ /* rc indicates how many bytes were written this time */
sent += rc; sent += rc;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册