<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">&lt;<a href="mailto:blp@nicira.com" target="_blank">blp@nicira.com</a>&gt;</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 &lt;<a href="mailto:blp@nicira.com">blp@nicira.com</a>&gt;<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 &quot;util.h&quot;<br>
 #include &lt;errno.h&gt;<br>
 #include &lt;limits.h&gt;<br>
+#include &lt;pthread.h&gt;<br>
 #include &lt;stdarg.h&gt;<br>
 #include &lt;stdint.h&gt;<br>
 #include &lt;stdio.h&gt;<br>
@@ -45,6 +46,9 @@ const char *subprogram_name = &quot;&quot;;<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, { &quot;&quot; });<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 ? &quot;&quot;<br>
+            : retval == EOF ? &quot;End of file&quot;<br>
+            : ovs_strerror(retval));<br>
+}<br>
<br>
-    if (!retval) {<br>
-        return &quot;&quot;;<br>
-    }<br>
-    if (retval &gt; 0) {<br>
-        return strerror(retval);<br>
-    }<br>
-    if (retval == EOF) {<br>
-        return &quot;End of file&quot;;<br>
+const char *<br>
+ovs_strerror(int error)<br>
+{<br>
+    enum { BUFSIZE = sizeof strerror_buffer_get()-&gt;s };<br>
+    int save_errno;<br>
+    char *buffer;<br>
+    char *s;<br>
+<br>
+    save_errno = errno;<br>
+    buffer = strerror_buffer_get()-&gt;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 &#39;buffer&#39;, 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&#39;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, &quot;Unknown error %d&quot;, error);<br>
     }<br>
-    snprintf(unknown, sizeof unknown, &quot;***unknown return value: %d***&quot;, retval);<br>
-    return unknown;<br>
+#endif<br>
+<br>
+    errno = save_errno;<br>
+<br>
+    return s;<br>
 }<br>
<br>
 /* Sets global &quot;program_name&quot; and &quot;program_version&quot; 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 &quot;License&quot;);<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>