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

[Xen-changelog] [xen-unstable] [LIBXC] Clean up use of sterror(). Define a thread-safe



# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Node ID da87dc126b33d771f50336de30330c81d8eed32d
# Parent  6f0f80aa817de63ff730098a54e333c9bac776d6
[LIBXC] Clean up use of sterror(). Define a thread-safe
version which uses strerror_r(), and tries to cope with
the POSIX and GNU versions of that function.
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
 tools/libxc/ia64/xc_ia64_linux_save.c |    2 +-
 tools/libxc/xc_core.c                 |    4 ++--
 tools/libxc/xc_linux_build.c          |    4 ++--
 tools/libxc/xc_private.c              |   13 +++++++++++++
 tools/libxc/xc_private.h              |    3 ++-
 5 files changed, 20 insertions(+), 6 deletions(-)

diff -r 6f0f80aa817d -r da87dc126b33 tools/libxc/ia64/xc_ia64_linux_save.c
--- a/tools/libxc/ia64/xc_ia64_linux_save.c     Fri Dec 08 11:47:09 2006 +0000
+++ b/tools/libxc/ia64/xc_ia64_linux_save.c     Fri Dec 08 11:57:06 2006 +0000
@@ -353,7 +353,7 @@ xc_linux_save(int xc_handle, int io_fd, 
                    It will be remarked dirty.
                    FIXME: to be tracked.  */
                 fprintf(stderr, "cannot map page %lx: %s\n",
-                        page_array[N], strerror (errno));
+                        page_array[N], safe_strerror(errno));
                 continue;
             }
 
diff -r 6f0f80aa817d -r da87dc126b33 tools/libxc/xc_core.c
--- a/tools/libxc/xc_core.c     Fri Dec 08 11:47:09 2006 +0000
+++ b/tools/libxc/xc_core.c     Fri Dec 08 11:57:06 2006 +0000
@@ -140,7 +140,7 @@ static int local_file_dump(void *args, c
         bytes = write(da->fd, &buffer[offset], length-offset);
         if ( bytes <= 0 )
         {
-            PERROR("Failed to write buffer: %s", strerror(errno));
+            PERROR("Failed to write buffer");
             return -errno;
         }
     }
@@ -158,7 +158,7 @@ xc_domain_dumpcore(int xc_handle,
 
     if ( (da.fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0 )
     {
-        PERROR("Could not open corefile %s: %s", corename, strerror(errno));
+        PERROR("Could not open corefile %s", corename);
         return -errno;
     }
 
diff -r 6f0f80aa817d -r da87dc126b33 tools/libxc/xc_linux_build.c
--- a/tools/libxc/xc_linux_build.c      Fri Dec 08 11:47:09 2006 +0000
+++ b/tools/libxc/xc_linux_build.c      Fri Dec 08 11:57:06 2006 +0000
@@ -593,8 +593,8 @@ static int setup_guest(int xc_handle,
     /* shared_info page starts its life empty. */
     shared_info = xc_map_foreign_range(
         xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, shared_info_frame);
-    printf("shared_info = %p, err=%s frame=%lx\n",
-           shared_info, strerror (errno), shared_info_frame);
+    printf("shared_info = %p frame=%lx\n",
+           shared_info, shared_info_frame);
     //memset(shared_info, 0, PAGE_SIZE);
     /* Mask all upcalls... */
     for ( i = 0; i < MAX_VIRT_CPUS; i++ )
diff -r 6f0f80aa817d -r da87dc126b33 tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c  Fri Dec 08 11:47:09 2006 +0000
+++ b/tools/libxc/xc_private.c  Fri Dec 08 11:57:06 2006 +0000
@@ -483,6 +483,19 @@ unsigned long xc_make_page_below_4G(
     return new_mfn;
 }
 
+char *safe_strerror(int errcode)
+{
+    static __thread char errbuf[32];
+#ifdef __GLIBC__
+    /* Broken GNU definition of strerror_r may not use our supplied buffer. */
+    return strerror_r(errcode, errbuf, sizeof(errbuf));
+#else
+    /* Assume we have the POSIX definition of strerror_r. */
+    strerror_r(errcode, errbuf, sizeof(errbuf));
+    return errbuf;
+#endif
+}
+
 /*
  * Local variables:
  * mode: C
diff -r 6f0f80aa817d -r da87dc126b33 tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h  Fri Dec 08 11:47:09 2006 +0000
+++ b/tools/libxc/xc_private.h  Fri Dec 08 11:57:06 2006 +0000
@@ -59,11 +59,12 @@
 #define PPRINTF(_f, _a...)
 #endif
 
+char *safe_strerror(int errcode);
 void xc_set_error(int code, const char *fmt, ...);
 
 #define ERROR(_m, _a...)  xc_set_error(XC_INTERNAL_ERROR, _m , ## _a )
 #define PERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m " (%d = %s)", \
-                                       ## _a , errno, strerror(errno))
+                                       ## _a , errno, safe_strerror(errno))
 
 int lock_pages(void *addr, size_t len);
 void unlock_pages(void *addr, size_t len);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.