[libvirt] [PATCH 7/9] phyp: Fix several UUID table related problems
Daniel Veillard
veillard at redhat.com
Fri Nov 6 10:45:45 UTC 2009
On Fri, Nov 06, 2009 at 04:28:05AM +0100, Matthias Bolte wrote:
> - 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
> ---
> src/phyp/phyp_driver.c | 19 ++++++++++++-------
> 1 files changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
> index 1529c24..43430a9 100644
> --- a/src/phyp/phyp_driver.c
> +++ b/src/phyp/phyp_driver.c
> @@ -1735,7 +1735,7 @@ phypUUIDTable_ReadFile(virConnectPtr conn)
> int fd = -1;
> char local_file[] = "./uuid_table";
> int rc = 0;
> - char buffer[1024];
> + int id;
>
> if ((fd = open(local_file, O_RDONLY)) == -1) {
> VIR_WARN("%s", "Unable to write information to local file.");
> @@ -1746,13 +1746,13 @@ phypUUIDTable_ReadFile(virConnectPtr conn)
> if (VIR_ALLOC_N(uuid_table->lpars, uuid_table->nlpars) >= 0) {
> 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 (VIR_ALLOC(uuid_table->lpars[i]) < 0) {
> virReportOOMError(conn);
> goto err;
> }
> - uuid_table->lpars[i]->id = (*buffer);
> + uuid_table->lpars[i]->id = id;
> } else {
> VIR_WARN("%s",
> "Unable to read from information to local file.");
> @@ -1790,7 +1790,7 @@ phypUUIDTable_WriteFile(virConnectPtr conn)
>
> for (i = 0; i < uuid_table->nlpars; i++) {
> 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)) {
> VIR_ERROR("%s", "Unable to write information to local file.");
> goto err;
Oops I missed that one :-)
> @@ -1944,8 +1944,13 @@ phypUUIDTable_Push(virConnectPtr conn)
> do {
> nread = fread(buffer, 1, sizeof(buffer), fd);
> if (nread <= 0) {
> - /* end of file */
> - break;
> + if (feof(fd)) {
> + /* end of file */
> + break;
> + } else {
> + VIR_ERROR("Failed to read from '%s'", local_file);
> + goto err;
> + }
> }
> ptr = buffer;
> sent = 0;
> @@ -1955,7 +1960,7 @@ phypUUIDTable_Push(virConnectPtr conn)
> rc = libssh2_channel_write(channel, ptr, nread);
> if (LIBSSH2_ERROR_EAGAIN == rc) { /* must loop around */
> continue;
> - } else {
> + } else if (rc > 0) {
> /* rc indicates how many bytes were written this time */
> sent += rc;
> }
ACK !
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel at veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
More information about the libvir-list
mailing list