[Libguestfs] [PATCH 3/9] daemon error handling: readdir code

Richard W.M. Jones rjones at redhat.com
Fri Nov 27 18:03:39 UTC 2009


-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v
-------------- next part --------------
>From af2847f7da0810f09912e9b77caab9c834ef7fa2 Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones at redhat.com>
Date: Fri, 27 Nov 2009 13:50:28 +0000
Subject: [PATCH 3/9] daemon error handling: readdir code

Where readdir sets errno = 0 to ensure correct error handling, we
replace this with a call to clear_error ().
---
 daemon/devsparts.c |    8 ++++----
 daemon/realpath.c  |    4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/daemon/devsparts.c b/daemon/devsparts.c
index 60e7aa8..6b20503 100644
--- a/daemon/devsparts.c
+++ b/daemon/devsparts.c
@@ -49,7 +49,7 @@ foreach_block_device (block_dev_func_t func)
   }
 
   while(1) {
-    errno = 0;
+    clear_error ();
     struct dirent *d = readdir(dir);
     if(NULL == d) break;
 
@@ -80,7 +80,7 @@ foreach_block_device (block_dev_func_t func)
   }
 
   /* Check readdir didn't fail */
-  if(0 != errno) {
+  if (0 != get_error ()) {
     reply_with_perror ("readdir: /sys/block");
     free_stringslen(r, size);
     return NULL;
@@ -150,7 +150,7 @@ add_partitions(const char *device,
   /* Look in /sys/block/<device>/ for entries starting with <device>
    * e.g. /sys/block/sda/sda1
    */
-  errno = 0;
+  clear_error ();
   struct dirent *d;
   while ((d = readdir (dir)) != NULL) {
     if (STREQLEN (d->d_name, device, strlen (device))) {
@@ -165,7 +165,7 @@ add_partitions(const char *device,
   }
 
   /* Check if readdir failed */
-  if(0 != errno) {
+  if (0 != get_error ()) {
       reply_with_perror ("readdir: %s", devdir);
       free_stringslen(*r, *size);
       return -1;
diff --git a/daemon/realpath.c b/daemon/realpath.c
index f49e0c5..1a6bc5f 100644
--- a/daemon/realpath.c
+++ b/daemon/realpath.c
@@ -129,13 +129,13 @@ do_case_sensitive_path (const char *path)
 
     struct dirent *d = NULL;
 
-    errno = 0;
+    clear_error ();
     while ((d = readdir (dir)) != NULL) {
       if (STRCASEEQ (d->d_name, name))
         break;
     }
 
-    if (d == NULL && errno != 0) {
+    if (d == NULL && get_error () != 0) {
       reply_with_perror ("readdir");
       goto error;
     }
-- 
1.6.5.2



More information about the Libguestfs mailing list