]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Pass through the fd_errno from kevent
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 4 Jul 2017 21:38:32 +0000 (17:38 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 4 Jul 2017 21:38:32 +0000 (17:38 -0400)
src/include/event.h
src/lib/io/network.c
src/lib/util/event.c
src/main/connection.c
src/main/unlang_interpret.c
src/modules/rlm_logtee/rlm_logtee.c
src/modules/rlm_rest/io.c

index 966ce168e141b1e9badfa324f43c3b697ff2d4cc..95288277b03e2bcb40497b59ad5aa8a834eb84d4 100644 (file)
@@ -71,6 +71,16 @@ typedef      int (*fr_event_status_t)(void *uctx, struct timeval *now);
  */
 typedef void (*fr_event_fd_handler_t)(fr_event_list_t *el, int sock, int flags, void *uctx);
 
+/** Called when an IO error event occurs on a file descriptor
+ *
+ * @param[in] el       Event list the file descriptor was inserted into.
+ * @param[in] sock     That experienced the IO event.
+ * @param[in] flags    field as returned by kevent.
+ * @param[in] fd_errno File descriptor error.
+ * @param[in] uctx     User ctx passed to #fr_event_fd_insert.
+ */
+typedef void (*fr_event_fd_error_handler_t)(fr_event_list_t *el, int sock, int flags, int fd_errno, void *uctx);
+
 /** Called when a user kevent occurs
  *
  * @param[in] kq       that received the user kevent.
@@ -88,7 +98,7 @@ int           fr_event_fd_delete(fr_event_list_t *el, int fd);
 int            fr_event_fd_insert(fr_event_list_t *el, int fd,
                                   fr_event_fd_handler_t read_fn,
                                   fr_event_fd_handler_t write_fn,
-                                  fr_event_fd_handler_t error,
+                                  fr_event_fd_error_handler_t error,
                                   void *ctx);
 
 int            fr_event_timer_delete(fr_event_list_t *el, fr_event_timer_t **parent);
index 1fb9edf02ea7157f53e5965b14007245406a1fbf..46094a8be4111af46a6396d4cca3a3e9a1ec8cb3 100644 (file)
@@ -413,12 +413,14 @@ static void fr_network_write(UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUS
 
 /** Handle errors for a socket.
  *
- * @param el the event list
- * @param sockfd the socket which has a fatal error.
- * @param flags returned by kevent.
- * @param ctx the network socket context.
+ * @param[in] el               the event list
+ * @param[in] sockfd           the socket which has a fatal error.
+ * @param[in] flags            returned by kevent.
+ * @param[in] fd_errno         returned by kevent.
+ * @param[in] ctx              the network socket context.
  */
-static void fr_network_error(UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUSED int flags, void *ctx)
+static void fr_network_error(UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUSED int flags,
+                            UNUSED int fd_errno, void *ctx)
 {
        fr_network_socket_t *s = ctx;
 
index 9ac168ca077fe53838362323629497668cdc2d3d..c3ed6a1f005c42a746585812e7b088d4da0ae99d 100644 (file)
@@ -68,7 +68,7 @@ typedef struct fr_event_fd_t {
 
        fr_event_fd_handler_t   read;                   //!< Callback for when data is available.
        fr_event_fd_handler_t   write;                  //!< Callback for when we can write data.
-       fr_event_fd_handler_t   error;                  //!< Callback for when an error occurs on the FD.
+       fr_event_fd_error_handler_t     error;          //!< Callback for when an error occurs on the FD.
 
        bool                    is_registered;          //!< Whether this fr_event_fd_t's FD has been registered with
                                                        //!< kevent.  Mostly for debugging.
@@ -327,7 +327,7 @@ static int _fr_event_fd_free(fr_event_fd_t *ef)
 int fr_event_fd_insert(fr_event_list_t *el, int fd,
                       fr_event_fd_handler_t read_fn,
                       fr_event_fd_handler_t write_fn,
-                      fr_event_fd_handler_t error,
+                      fr_event_fd_error_handler_t error,
                       void *ctx)
 {
        int             filter = 0;
@@ -935,6 +935,7 @@ void fr_event_service(fr_event_list_t *el)
         */
        for (i = 0; i < el->num_fd_events; i++) {
                fr_event_fd_t *ev;
+               int fd_errno = 0;
                int flags = el->events[i].flags;
 
                /*
@@ -963,16 +964,15 @@ void fr_event_service(fr_event_list_t *el)
                if (!fr_cond_assert(ev->is_registered)) continue;
 
                 if (flags & EV_ERROR) {
+                       fd_errno = el->events[i].data;
                 ev_error:
                         /*
                          *      Call the error handler which should
                          *      tear down the connection.
                          */
-                        if (ev->error) {
-                                ev->error(el, ev->fd, flags, ev->ctx);
-                                continue;
-                        }
+                        if (ev->error) ev->error(el, ev->fd, flags, fd_errno, ev->ctx);
                         fr_event_fd_delete(el, ev->fd);
+                        continue;
                 }
 
                 /*
@@ -1003,6 +1003,8 @@ void fr_event_service(fr_event_list_t *el)
                         */
                        if ((ev->sock_type == SOCK_RAW) && ev->pf_attached) goto service;
 #endif
+                       fd_errno = el->events[i].fflags;
+
                        goto ev_error;
                 }
 
@@ -1160,7 +1162,7 @@ fr_event_list_t *fr_event_list_alloc(TALLOC_CTX *ctx, fr_event_status_t status,
        FR_DLIST_INIT(el->pre_callbacks);
        FR_DLIST_INIT(el->post_callbacks);
        FR_DLIST_INIT(el->user_callbacks);
-       
+
        if (status) (void) fr_event_pre_insert(el, status, status_ctx);
 
        /*
index 709a747c80fbf8c02defb8345bf2ab4508e0f0ae..1202a5d74d21df11d0803f421bd258f8871bdd26 100644 (file)
@@ -161,15 +161,16 @@ static void _connection_timeout(UNUSED fr_event_list_t *el, struct timeval *now,
  *
  * @param[in] el       event list the I/O event occurred on.
  * @param[in] sock     the I/O even occurred for.
- * @param[in] flags    from kevent.
+ * @param[in] flags    from_kevent.
+ * @param[in] fd_errno from kevent.
  * @param[in] uctx     The #fr_connection_t this fd is associated with.
  */
-static void _connection_error(UNUSED fr_event_list_t *el, UNUSED int sock, UNUSED int flags, void *uctx)
+static void _connection_error(UNUSED fr_event_list_t *el, UNUSED int sock, UNUSED int flags, int fd_errno, void *uctx)
 {
        fr_connection_t *conn = talloc_get_type_abort(uctx, fr_connection_t);
        struct timeval  now;
 
-       ERROR("Connection failed");
+       ERROR("Connection failed: %s", fr_syserror(fd_errno));
        gettimeofday(&now, NULL);
        connection_state_failed(conn, &now);
 }
index 3a60cd86bf09d61be538a95b7afcf1e8dd203f90..51aaa654cd262904b0d93782a4ed456db061cdcd 100644 (file)
@@ -509,13 +509,13 @@ static unlang_action_t unlang_fork(REQUEST *request, unlang_stack_t *stack,
                da = fr_dict_attr_by_name(NULL, "Packet-Type");
                if (!da) {
                        *result = RLM_MODULE_FAIL;
-                       return UNLANG_ACTION_CALCULATE_RESULT;                  
+                       return UNLANG_ACTION_CALCULATE_RESULT;
                }
 
                dval = fr_dict_enum_by_alias(NULL, da, g->vpt->name);
                if (!dval) {
                        *result = RLM_MODULE_FAIL;
-                       return UNLANG_ACTION_CALCULATE_RESULT;                  
+                       return UNLANG_ACTION_CALCULATE_RESULT;
                }
 
                child->packet->code = dval->value->vb_uint32;
@@ -1784,9 +1784,11 @@ static void unlang_event_fd_write_handler(UNUSED fr_event_list_t *el, int fd, UN
  * @param[in] el       containing the event (not passed to the callback).
  * @param[in] fd       the I/O event occurred on.
  * @param[in] flags    from kevent.
+ * @param[in] fd_errno from kevent.
  * @param[in] ctx      unlang_event_t structure holding callbacks.
  */
-static void unlang_event_fd_error_handler(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *ctx)
+static void unlang_event_fd_error_handler(UNUSED fr_event_list_t *el, int fd,
+                                         UNUSED int flags, UNUSED int fd_errno, void *ctx)
 {
        unlang_event_t *ev = talloc_get_type_abort(ctx, unlang_event_t);
        void *mutable_ctx;
index b0b15fa1d5d7de5ce4217df0fad96df4b5fe913b..54e5d210c95b876a18fdda2989f1b63006d07f16 100644 (file)
@@ -195,10 +195,12 @@ static rlm_rcode_t mod_insert_logtee(void *instance, UNUSED void *thread, REQUES
 /** Connection errored
  *
  */
-static void _logtee_conn_error(UNUSED fr_event_list_t *el, UNUSED int sock, UNUSED int flags, void *uctx)
+static void _logtee_conn_error(UNUSED fr_event_list_t *el, int sock, UNUSED int flags, int fd_errno, void *uctx)
 {
        rlm_logtee_thread_t     *t = talloc_get_type_abort(uctx, rlm_logtee_thread_t);
 
+       ERROR("Connection failed (%i): %s", sock, fr_syserror(fd_errno));
+
        /*
         *      Something bad happened... Fix it...
         */
index 99c93bb0ef39aef1a27a216823f41f21294d3c60..20dcc8cbccb01a800dca16c611ba44db65fddef7 100644 (file)
@@ -139,15 +139,16 @@ static void _rest_io_timer_expired(UNUSED fr_event_list_t *el, UNUSED struct tim
  * @param[in] el       fd was registered with.
  * @param[in] fd       that errored.
  * @param[in] flags    from kevent.
+ * @param[in] fd_errno from kevent.
  * @param[in] ctx      The rlm_rest_thread_t specific to this thread.
  */
-static void _rest_io_service_errored(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *ctx)
+static void _rest_io_service_errored(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, int fd_errno, void *ctx)
 {
        rlm_rest_thread_t *t;
 
        t = talloc_get_type_abort(ctx, rlm_rest_thread_t);
 
-       DEBUG4("libcurl fd %i errored", fd);
+       DEBUG4("libcurl fd %i errored: %s", fd, fr_syserror(fd_errno));
 
        _rest_io_service(t, fd, CURL_CSELECT_ERR);
 }