<div dir="ltr">Looks good to me, thanks<div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 19, 2013 at 1:17 PM, Ben Pfaff <span dir="ltr"><<a href="mailto:blp@nicira.com" target="_blank">blp@nicira.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Signed-off-by: Ben Pfaff <<a href="mailto:blp@nicira.com">blp@nicira.com</a>><br>
---<br>
<a href="http://configure.ac" target="_blank">configure.ac</a> | 1 +<br>
lib/util.c | 48 +++++++++++++++++++++++++++++++++++++-----------<br>
lib/util.h | 3 ++-<br>
3 files changed, 40 insertions(+), 12 deletions(-)<br>
<br>
diff --git a/<a href="http://configure.ac" target="_blank">configure.ac</a> b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
index 6db4a00..734b2ff 100644<br>
--- a/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
+++ b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
@@ -45,6 +45,7 @@ AC_SEARCH_LIBS([pow], [m])<br>
AC_SEARCH_LIBS([clock_gettime], [rt])<br>
AC_SEARCH_LIBS([timer_create], [rt])<br>
AC_SEARCH_LIBS([pthread_sigmask], [pthread])<br>
+AC_FUNC_STRERROR_R<br>
<br>
OVS_CHECK_ESX<br>
OVS_CHECK_COVERAGE<br>
diff --git a/lib/util.c b/lib/util.c<br>
index 2a06461..6ee8b5c 100644<br>
--- a/lib/util.c<br>
+++ b/lib/util.c<br>
@@ -18,6 +18,7 @@<br>
#include "util.h"<br>
#include <errno.h><br>
#include <limits.h><br>
+#include <pthread.h><br>
#include <stdarg.h><br>
#include <stdint.h><br>
#include <stdio.h><br>
@@ -45,6 +46,9 @@ const char *subprogram_name = "";<br>
/* --version option output. */<br>
static char *program_version;<br>
<br>
+/* Buffer used by ovs_strerror(). */<br>
+DEFINE_PER_THREAD_DATA(struct { char s[128]; }, strerror_buffer, { "" });<br>
+<br></blockquote><div><br></div><div><br></div><div><br></div><div style>This is really cool, learned the Variadic Macros ;D</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
void<br>
ovs_assert_failure(const char *where, const char *function,<br>
const char *condition)<br>
@@ -307,19 +311,41 @@ ovs_error_valist(int err_no, const char *format, va_list args)<br>
const char *<br>
ovs_retval_to_string(int retval)<br>
{<br>
- static char unknown[48];<br>
+ return (!retval ? ""<br>
+ : retval == EOF ? "End of file"<br>
+ : ovs_strerror(retval));<br>
+}<br>
<br>
- if (!retval) {<br>
- return "";<br>
- }<br>
- if (retval > 0) {<br>
- return strerror(retval);<br>
- }<br>
- if (retval == EOF) {<br>
- return "End of file";<br>
+const char *<br>
+ovs_strerror(int error)<br>
+{<br>
+ enum { BUFSIZE = sizeof strerror_buffer_get()->s };<br>
+ int save_errno;<br>
+ char *buffer;<br>
+ char *s;<br>
+<br>
+ save_errno = errno;<br>
+ buffer = strerror_buffer_get()->s;<br>
+<br>
+#if STRERROR_R_CHAR_P<br>
+ /* GNU style strerror_r() might return an immutable static string, or it<br>
+ * might write and return 'buffer', but in either case we can pass the<br>
+ * returned string directly to the caller. */<br>
+ s = strerror_r(error, buffer, BUFSIZE);<br>
+#else /* strerror_r() returns an int. */<br>
+ s = buffer;<br>
+ if (strerror_r(error, buffer, BUFSIZE)) {<br>
+ /* strerror_r() is only allowed to fail on ERANGE (because the buffer<br>
+ * is too short). We don't check the actual failure reason because<br>
+ * POSIX requires strerror_r() to return the error but old glibc<br>
+ * (before 2.13) returns -1 and sets errno. */<br>
+ snprintf(buffer, ptb.bufsize, "Unknown error %d", error);<br>
}<br>
- snprintf(unknown, sizeof unknown, "***unknown return value: %d***", retval);<br>
- return unknown;<br>
+#endif<br>
+<br>
+ errno = save_errno;<br>
+<br>
+ return s;<br>
}<br>
<br>
/* Sets global "program_name" and "program_version" variables. Should<br>
diff --git a/lib/util.h b/lib/util.h<br>
index f5589e3..d7fbe09 100644<br>
--- a/lib/util.h<br>
+++ b/lib/util.h<br>
@@ -1,5 +1,5 @@<br>
/*<br>
- * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.<br>
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.<br>
*<br>
* Licensed under the Apache License, Version 2.0 (the "License");<br>
* you may not use this file except in compliance with the License.<br>
@@ -213,6 +213,7 @@ void ovs_error(int err_no, const char *format, ...) PRINTF_FORMAT(2, 3);<br>
void ovs_error_valist(int err_no, const char *format, va_list)<br>
PRINTF_FORMAT(2, 0);<br>
const char *ovs_retval_to_string(int);<br>
+const char *ovs_strerror(int);<br>
void ovs_hex_dump(FILE *, const void *, size_t, uintptr_t offset, bool ascii);<br>
<br>
bool str_to_int(const char *, int base, int *);<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.2.5<br>
<br>
_______________________________________________<br>
dev mailing list<br>
<a href="mailto:dev@openvswitch.org">dev@openvswitch.org</a><br>
<a href="http://openvswitch.org/mailman/listinfo/dev" target="_blank">http://openvswitch.org/mailman/listinfo/dev</a><br>
</font></span></blockquote></div><br></div></div>