[SSSD] [PATCH] Reduce the code duplication in Data Provider

Pavel Březina pbrezina at redhat.com
Mon Nov 16 10:31:32 UTC 2015


On 11/11/2015 02:28 PM, Jakub Hrozek wrote:
> Hi,
>
> I think one of the prime reasons for #2861 was copy-pasting code. The
> two attached patches reduce the code duplication and hopefully will make
> future additions to Data Provider safer.
>
> Ideas on different solutions are welcome!

> +static errno_t be_sbus_req_reply(struct sbus_request *sbus_req,
> +                                 const char *req_name,
> +                                 int dp_err_type,
> +                                 int errnum,
> +                                 const char *errstr)
> +{
> +    const char *req_msg;
> +    dbus_uint16_t err_maj;
> +    dbus_uint32_t err_min;
> +
> +    err_maj = dp_err_type;
> +    err_min = errnum;
> +
> +    req_msg = req_name ? req_name : "sbus";

        ^^ unused, along with req_name

> +    return be_sbus_reply(sbus_req, err_maj, err_min, errstr);
> +}

> +static inline void be_sbus_reply_data_set(struct be_sbus_reply_data *rdata,
> +                                          dbus_uint16_t err_maj,
> +                                          dbus_uint32_t err_min,
> +                                          const char *err_msg)
> +{

if (rdata == NULL) {
     DEBUG(SSSDBG_CRIT_FAILURE, "Bug: ...\n");
}

> +    if (rdata) {
> +        rdata->err_maj = err_maj;
> +        rdata->err_min = err_min;
> +        rdata->err_msg = err_msg;
> +    }
> +}

I like it!


More information about the sssd-devel mailing list