A tevent function to propagate error info up the stack

Simo idra at samba.org
Wed May 1 06:29:44 MDT 2013


On 05/01/2013 01:24 AM, Richard Sharpe wrote:
> 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?
Not sure it is.
It would require you to keep around the subreq, which is something we do
not do in tevent_req style requests.
Why don't you simply ask for the location string and carry it on yourself ?
Maybe a pair of functions, one to get the location and one to set it
explicitly instead of implicitly so you can simply chain up this function:

bool tevent_req_get_error(struct tevent_req *req,
enum tevent_req_state *state,
uint64_t *error,
char **location);

with this new one, by passing the retrieved location on your local state.
location would be allocated on req and needs to be stolen as the req you
retrieve it from (the subreq) is going to be freed soon enough, and
usually before you use location.

#define tevent_req_error_loc(req, error, location) \
_tevent_req_error(req, error, __location__)


In any case propogate -> propagate


Simo.

> 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
>
>



More information about the samba-technical mailing list