summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-07-02 16:30:23 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-07-07 11:26:15 +0100
commitcef7946133cef08b94814de9a1581b7c3702a3e0 (patch)
tree1d0e758881212b8ed3f4be918a102ab02e6b64e8
parent3fb00aad0e5209d0f1e027cca5faa68fa4da69d5 (diff)
downloadlibguestfs-cef7946133cef08b94814de9a1581b7c3702a3e0.tar.gz
libguestfs-cef7946133cef08b94814de9a1581b7c3702a3e0.tar.xz
libguestfs-cef7946133cef08b94814de9a1581b7c3702a3e0.zip
daemon: Code tidy up in devsparts.
No functional change. (cherry picked from commit cb24ceedd8a8ef7da71cfcce6db10669de47685c)
-rw-r--r--daemon/devsparts.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/daemon/devsparts.c b/daemon/devsparts.c
index b5300c50..0b5c99ed 100644
--- a/daemon/devsparts.c
+++ b/daemon/devsparts.c
@@ -40,9 +40,11 @@ foreach_block_device (block_dev_func_t func)
{
char **r = NULL;
int size = 0, alloc = 0;
-
DIR *dir;
int err = 0;
+ struct dirent *d;
+ char dev_path[256];
+ int fd;
dir = opendir ("/sys/block");
if (!dir) {
@@ -50,16 +52,15 @@ foreach_block_device (block_dev_func_t func)
return NULL;
}
- while(1) {
+ for (;;) {
errno = 0;
- struct dirent *d = readdir(dir);
- if(NULL == d) break;
+ d = readdir(dir);
+ if (!d) break;
if (STREQLEN (d->d_name, "sd", 2) ||
STREQLEN (d->d_name, "hd", 2) ||
STREQLEN (d->d_name, "vd", 2) ||
STREQLEN (d->d_name, "sr", 2)) {
- char dev_path[256];
snprintf (dev_path, sizeof dev_path, "/dev/%s", d->d_name);
/* Ignore the root device. */
@@ -70,7 +71,7 @@ foreach_block_device (block_dev_func_t func)
* CD-ROM device even though we didn't request it. Try to
* detect this by seeing if the device contains media.
*/
- int fd = open (dev_path, O_RDONLY);
+ fd = open (dev_path, O_RDONLY);
if (fd == -1) {
perror (dev_path);
continue;
@@ -78,7 +79,7 @@ foreach_block_device (block_dev_func_t func)
close (fd);
/* Call the map function for this device */
- if((*func)(d->d_name, &r, &size, &alloc) != 0) {
+ if ((*func)(d->d_name, &r, &size, &alloc) != 0) {
err = 1;
break;
}
@@ -86,7 +87,7 @@ foreach_block_device (block_dev_func_t func)
}
/* Check readdir didn't fail */
- if(0 != errno) {
+ if (errno != 0) {
reply_with_perror ("readdir: /sys/block");
free_stringslen(r, size);
closedir (dir);