Matthew Booth
2009-Aug-06 13:40 UTC
[Libguestfs] [PATCH] Fix errno check in readdir in devsparts.c
--- daemon/devsparts.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/daemon/devsparts.c b/daemon/devsparts.c index b89682c..e9c5e8f 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -40,7 +40,6 @@ foreach_block_device (block_dev_func_t func) int size = 0, alloc = 0; DIR *dir; - struct dirent *d; int err = 0; dir = opendir ("/sys/block"); @@ -49,8 +48,11 @@ foreach_block_device (block_dev_func_t func) return NULL; } - errno = 0; - while ((d = readdir (dir)) != NULL) { + while(1) { + errno = 0; + struct dirent *d = readdir(dir); + if(NULL == d) break; + if (strncmp (d->d_name, "sd", 2) == 0 || strncmp (d->d_name, "hd", 2) == 0 || strncmp (d->d_name, "vd", 2) == 0 || -- 1.6.2.5
Richard W.M. Jones
2009-Aug-06 13:45 UTC
[Libguestfs] [PATCH] Fix errno check in readdir in devsparts.c
On Thu, Aug 06, 2009 at 02:40:52PM +0100, Matthew Booth wrote:> --- > daemon/devsparts.c | 8 +++++--- > 1 files changed, 5 insertions(+), 3 deletions(-) > > diff --git a/daemon/devsparts.c b/daemon/devsparts.c > index b89682c..e9c5e8f 100644 > --- a/daemon/devsparts.c > +++ b/daemon/devsparts.c > @@ -40,7 +40,6 @@ foreach_block_device (block_dev_func_t func) > int size = 0, alloc = 0; > > DIR *dir; > - struct dirent *d; > int err = 0; > > dir = opendir ("/sys/block"); > @@ -49,8 +48,11 @@ foreach_block_device (block_dev_func_t func) > return NULL; > } > > - errno = 0; > - while ((d = readdir (dir)) != NULL) { > + while(1) { > + errno = 0; > + struct dirent *d = readdir(dir); > + if(NULL == d) break; > + > if (strncmp (d->d_name, "sd", 2) == 0 || > strncmp (d->d_name, "hd", 2) == 0 || > strncmp (d->d_name, "vd", 2) == 0 || > -- > 1.6.2.5ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
Reasonably Related Threads
- [PATCH] daemon: Remove use of fixed-size stack buffers.
- [PATCH 1/2] daemon: Fix part-to-dev when the partition name includes p<N>.
- [PATCH] Recognise cd-rom devices in devsparts.c
- [PATCH 2/2] daemon: Return MD partitions in guestfs_list_partitions (RHBZ#1414510).
- [PATCH 1/2] daemon: free the string on stringsbuf add failure