A tevent function to propagate error info up the stack

Richard Sharpe realrichardsharpe at gmail.com
Tue Apr 30 23:24:39 MDT 2013


Hi folks,

This is designed to allow us to propagate error locations up the stack
so that DEBUG messages can tell us where the error really came from.

Does this seem like a reasonable approach?

diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h
index 6b4d371..296033a 100644
--- a/lib/tevent/tevent.h
+++ b/lib/tevent/tevent.h
@@ -1037,6 +1037,45 @@ bool _tevent_req_error(struct tevent_req *req,

 #ifdef DOXYGEN
 /**
+ * @brief An async request is passing on an error from below.
+ *
+ * This function is to be used by implementors of async requests. When a
+ * callback needs to pass an error back up to another callback, use this
+ * function with the appropriate status code and request to get the error
+ * location from.
+ *
+ * If error is 0 the function returns false and does nothing more.
+ *
+ * @param[in]  req      The request with an error.
+ *
+ * @param[in]  error    The error code.
+ *
+ * @param[in]  orig_req The request to take the error location from.
+ *
+ * @return              On success true is returned, false if error is 0.
+ *
+ * @code
+ * ret = some_func(subreq, &sys_errno);
+ * if (ret == -1) {
+ *     tevent_req_error_propogate(req, sys_errno, subreq);
+ *     return;
+ * }
+ * @endcode
+ */
+bool tevent_req_error_propogate(struct tevent_req *req,
+                               uint64_t error,
+                               struct tevent_req *subreq);
+#else
+bool _tevent_req_error_propogate(struct tevent_req *req,
+                                uint64_t error,
+                                struct tevent_req *subreq,
+                                const char *location);
+#define tevent_req_error_propogate(req, error) \
+       _tevent_req_error_propogate(req, error, subreq, __location__)
+#endif
+
+#ifdef DOXYGEN
+/**
  * @brief Helper function for nomem check.
  *
  * Convenience helper to easily check alloc failure within a callback


-- 
Regards,
Richard Sharpe
(何以解憂?唯有杜康。--曹操)


More information about the samba-technical mailing list