Re: PATCH: 9/16: main internal storage driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Daniel P. Berrange" <berrange@xxxxxxxxxx> wrote:
...
> +int virStoragePoolObjSaveDef(virConnectPtr conn,
> +                             virStorageDriverStatePtr driver,
> +                             virStoragePoolObjPtr pool,
> +                             virStoragePoolDefPtr def) {
> +    char *xml;
> +    int fd = -1, ret = -1;
> +    int towrite;

slightly better to use ssize_t.
see below.

...
> +    if ((fd = open(pool->configFile,
> +                   O_WRONLY | O_CREAT | O_TRUNC,
> +                   S_IRUSR | S_IWUSR )) < 0) {
> +        virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
> +                              "cannot create config file %s: %s",
> +                              pool->configFile, strerror(errno));
> +        goto cleanup;
> +    }
> +
> +    towrite = strlen(xml);

Here, you'd expect towrite to be of type size_t.
But in comparing with write's return value, you want ssize_t.
No big deal in any case, because we won't be generating 2^31-byte-long
XML strings.

> +    if (write(fd, xml, towrite) != towrite) {

write should always be used in a loop,
since it can succeed and write less than requested.

Here, it's fine to use fopen/fwrite/fclose instead.

> +        virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
> +                              "cannot write config file %s: %s",
> +                              pool->configFile, strerror(errno));

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]