qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [42/50] [abbrv] qpid-proton git commit: PROTON-1495: c epoll use strerror_r() instead of unsafe strerr()
Date Fri, 09 Jun 2017 01:26:05 GMT
PROTON-1495: c epoll use strerror_r() instead of unsafe strerr()


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/8ef841c5
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/8ef841c5
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/8ef841c5

Branch: refs/heads/go1
Commit: 8ef841c53dab1762fdbe1bc7058cc290f3a4f439
Parents: cb5996e
Author: Alan Conway <aconway@redhat.com>
Authored: Wed Jun 7 13:22:13 2017 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Wed Jun 7 13:22:13 2017 -0400

----------------------------------------------------------------------
 proton-c/src/proactor/epoll.c             | 39 +++++++++++++++++---------
 proton-c/src/proactor/libuv.c             |  6 ++--
 proton-c/src/proactor/proactor-internal.c |  5 +++-
 3 files changed, 31 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8ef841c5/proton-c/src/proactor/epoll.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/epoll.c b/proton-c/src/proactor/epoll.c
index b6d2bd0..0bb0b10 100644
--- a/proton-c/src/proactor/epoll.c
+++ b/proton-c/src/proactor/epoll.c
@@ -20,12 +20,14 @@
  */
 
 /* Enable POSIX features for pthread.h */
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
+#ifndef _DEFAULT_SOURCE
+#define _DEFAULT_SOURCE
 #endif
+/* Avoid GNU extensions, in particular the incompatible alternative strerror_r() */
+#undef _GNU_SOURCE
 
 #include "../core/log_private.h"
-#include "proactor-internal.h"
+#include "./proactor-internal.h"
 
 #include <proton/condition.h>
 #include <proton/connection_driver.h>
@@ -66,12 +68,23 @@
 // looking for pending wakes before a kernel call to epoll_wait(), or there
 // could be several eventfds with random assignment of wakeables.
 
+
+typedef char strerrorbuf[1024];      /* used for pstrerror message buffer */
+
+/* Like strerror_r but provide a default message if strerror_r fails */
+static void pstrerror(int err, strerrorbuf msg) {
+  int e = strerror_r(err, msg, sizeof(strerrorbuf));
+  if (e) snprintf(msg, sizeof(strerrorbuf), "unknown error %d", err);
+}
+
 /* Internal error, no recovery */
-#define EPOLL_FATAL(EXPR, SYSERRNO)                                   \
-  do {                                                                \
-    fprintf(stderr, "epoll proactor failure in %s:%d: %s: %s\n",      \
-            __FILE__, __LINE__ , #EXPR, strerror(SYSERRNO));          \
-    abort();                                                          \
+#define EPOLL_FATAL(EXPR, SYSERRNO)                                     \
+  do {                                                                  \
+    strerrorbuf msg;                                                    \
+    pstrerror((SYSERRNO), msg);                                         \
+    fprintf(stderr, "epoll proactor failure in %s:%d: %s: %s\n",        \
+            __FILE__, __LINE__ , #EXPR, msg);                           \
+    abort();                                                            \
   } while (0)
 
 // ========================================================================
@@ -580,18 +593,16 @@ static pn_event_t *log_event(void* p, pn_event_t *e) {
 }
 
 static void psocket_error(psocket_t *ps, int err, const char* what) {
+  strerrorbuf msg;
+  pstrerror(err, msg);
   if (!ps->listener) {
     pn_connection_driver_t *driver = &psocket_pconnection(ps)->driver;
     pn_connection_driver_bind(driver); /* Bind so errors will be reported */
-    pn_connection_driver_errorf(driver, PNI_IO_CONDITION, "%s %s:%s: %s",
-                                what, ps->host, ps->port,
-                                strerror(err));
+    pni_proactor_set_cond(pn_transport_condition(driver->transport), what, ps->host,
ps->port, msg);
     pn_connection_driver_close(driver);
   } else {
     pn_listener_t *l = psocket_listener(ps);
-    pn_condition_format(l->condition, PNI_IO_CONDITION, "%s %s:%s: %s",
-                        what, ps->host, ps->port,
-                        strerror(err));
+    pni_proactor_set_cond(l->condition, what, ps->host, ps->port, msg);
     listener_begin_close(l);
   }
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8ef841c5/proton-c/src/proactor/libuv.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/libuv.c b/proton-c/src/proactor/libuv.c
index a851c4e..cf3daab 100644
--- a/proton-c/src/proactor/libuv.c
+++ b/proton-c/src/proactor/libuv.c
@@ -455,10 +455,8 @@ static inline void pconnection_bad_connect(pconnection_t *pc, int err)
{
 static void pconnection_set_error(pconnection_t *pc, int err, const char* what) {
   pn_connection_driver_t *driver = &pc->driver;
   pn_connection_driver_bind(driver); /* Make sure we are bound so errors will be reported
*/
-  if (!pn_condition_is_set(pn_transport_condition(driver->transport))) {
-    pni_proactor_set_cond(pn_transport_condition(driver->transport),
-                                what, pc->addr.host , pc->addr.port, uv_strerror(err));
-  }
+  pni_proactor_set_cond(pn_transport_condition(driver->transport),
+                        what, pc->addr.host , pc->addr.port, uv_strerror(err));
 }
 
 /* Set the error condition and close the driver. */

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8ef841c5/proton-c/src/proactor/proactor-internal.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/proactor-internal.c b/proton-c/src/proactor/proactor-internal.c
index 3525c71..0c82573 100644
--- a/proton-c/src/proactor/proactor-internal.c
+++ b/proton-c/src/proactor/proactor-internal.c
@@ -72,5 +72,8 @@ static inline const char *nonull(const char *str) { return str ? str : "";
}
 void pni_proactor_set_cond(
   pn_condition_t *cond, const char *what, const char *host, const char *port, const char
*msg)
 {
-  pn_condition_format(cond, PNI_IO_CONDITION, "%s - %s %s:%s", msg, what, nonull(host), nonull(port));
+  if (!pn_condition_is_set(cond)) { /* Preserve older error information */
+    pn_condition_format(cond, PNI_IO_CONDITION, "%s - %s %s:%s",
+                        msg, what, nonull(host), nonull(port));
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message