debuggers.hg
changeset 12847:da87dc126b33
[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@xensource.com>
version which uses strerror_r(), and tries to cope with
the POSIX and GNU versions of that function.
Signed-off-by: Keir Fraser <keir@xensource.com>
author | kfraser@localhost.localdomain |
---|---|
date | Fri Dec 08 11:57:06 2006 +0000 (2006-12-08) |
parents | 6f0f80aa817d |
children | 28403de6c415 970ff2ba748f |
files | tools/libxc/ia64/xc_ia64_linux_save.c tools/libxc/xc_core.c tools/libxc/xc_linux_build.c tools/libxc/xc_private.c tools/libxc/xc_private.h |
line diff
1.1 --- a/tools/libxc/ia64/xc_ia64_linux_save.c Fri Dec 08 11:47:09 2006 +0000 1.2 +++ b/tools/libxc/ia64/xc_ia64_linux_save.c Fri Dec 08 11:57:06 2006 +0000 1.3 @@ -353,7 +353,7 @@ xc_linux_save(int xc_handle, int io_fd, 1.4 It will be remarked dirty. 1.5 FIXME: to be tracked. */ 1.6 fprintf(stderr, "cannot map page %lx: %s\n", 1.7 - page_array[N], strerror (errno)); 1.8 + page_array[N], safe_strerror(errno)); 1.9 continue; 1.10 } 1.11
2.1 --- a/tools/libxc/xc_core.c Fri Dec 08 11:47:09 2006 +0000 2.2 +++ b/tools/libxc/xc_core.c Fri Dec 08 11:57:06 2006 +0000 2.3 @@ -140,7 +140,7 @@ static int local_file_dump(void *args, c 2.4 bytes = write(da->fd, &buffer[offset], length-offset); 2.5 if ( bytes <= 0 ) 2.6 { 2.7 - PERROR("Failed to write buffer: %s", strerror(errno)); 2.8 + PERROR("Failed to write buffer"); 2.9 return -errno; 2.10 } 2.11 } 2.12 @@ -158,7 +158,7 @@ xc_domain_dumpcore(int xc_handle, 2.13 2.14 if ( (da.fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0 ) 2.15 { 2.16 - PERROR("Could not open corefile %s: %s", corename, strerror(errno)); 2.17 + PERROR("Could not open corefile %s", corename); 2.18 return -errno; 2.19 } 2.20
3.1 --- a/tools/libxc/xc_linux_build.c Fri Dec 08 11:47:09 2006 +0000 3.2 +++ b/tools/libxc/xc_linux_build.c Fri Dec 08 11:57:06 2006 +0000 3.3 @@ -593,8 +593,8 @@ static int setup_guest(int xc_handle, 3.4 /* shared_info page starts its life empty. */ 3.5 shared_info = xc_map_foreign_range( 3.6 xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, shared_info_frame); 3.7 - printf("shared_info = %p, err=%s frame=%lx\n", 3.8 - shared_info, strerror (errno), shared_info_frame); 3.9 + printf("shared_info = %p frame=%lx\n", 3.10 + shared_info, shared_info_frame); 3.11 //memset(shared_info, 0, PAGE_SIZE); 3.12 /* Mask all upcalls... */ 3.13 for ( i = 0; i < MAX_VIRT_CPUS; i++ )
4.1 --- a/tools/libxc/xc_private.c Fri Dec 08 11:47:09 2006 +0000 4.2 +++ b/tools/libxc/xc_private.c Fri Dec 08 11:57:06 2006 +0000 4.3 @@ -483,6 +483,19 @@ unsigned long xc_make_page_below_4G( 4.4 return new_mfn; 4.5 } 4.6 4.7 +char *safe_strerror(int errcode) 4.8 +{ 4.9 + static __thread char errbuf[32]; 4.10 +#ifdef __GLIBC__ 4.11 + /* Broken GNU definition of strerror_r may not use our supplied buffer. */ 4.12 + return strerror_r(errcode, errbuf, sizeof(errbuf)); 4.13 +#else 4.14 + /* Assume we have the POSIX definition of strerror_r. */ 4.15 + strerror_r(errcode, errbuf, sizeof(errbuf)); 4.16 + return errbuf; 4.17 +#endif 4.18 +} 4.19 + 4.20 /* 4.21 * Local variables: 4.22 * mode: C
5.1 --- a/tools/libxc/xc_private.h Fri Dec 08 11:47:09 2006 +0000 5.2 +++ b/tools/libxc/xc_private.h Fri Dec 08 11:57:06 2006 +0000 5.3 @@ -59,11 +59,12 @@ 5.4 #define PPRINTF(_f, _a...) 5.5 #endif 5.6 5.7 +char *safe_strerror(int errcode); 5.8 void xc_set_error(int code, const char *fmt, ...); 5.9 5.10 #define ERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m , ## _a ) 5.11 #define PERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m " (%d = %s)", \ 5.12 - ## _a , errno, strerror(errno)) 5.13 + ## _a , errno, safe_strerror(errno)) 5.14 5.15 int lock_pages(void *addr, size_t len); 5.16 void unlock_pages(void *addr, size_t len);