[dm-devel] [PATCH 20/35] multipathd: move uxsock_trigger() to uxlsnr.c
Benjamin Marzinski
bmarzins at redhat.com
Thu Sep 16 02:19:20 UTC 2021
On Fri, Sep 10, 2021 at 01:41:05PM +0200, mwilck at suse.com wrote:
> From: Martin Wilck <mwilck at suse.com>
>
> uxsock_trigger() really belongs into cli.c. I suppose that way back in
> the past there were strong reasons to call this function via a
> pointer. I don't think these reasons are valid any more. Moving
> the function to cli.c allows restructuring the code.
>
> No functional changes.
>
Reviewed-by: Benjamin Marzinski <bmarzins at redhat.com>
> Signed-off-by: Martin Wilck <mwilck at suse.com>
> ---
> multipathd/main.c | 44 +-------------------------------------------
> multipathd/uxlsnr.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
> multipathd/uxlsnr.h | 4 +---
> 3 files changed, 44 insertions(+), 48 deletions(-)
>
> diff --git a/multipathd/main.c b/multipathd/main.c
> index c6357ef..ec4bcc3 100644
> --- a/multipathd/main.c
> +++ b/multipathd/main.c
> @@ -1526,48 +1526,6 @@ map_discovery (struct vectors * vecs)
> return 0;
> }
>
> -int
> -uxsock_trigger (char * str, char ** reply, int * len, bool is_root,
> - void * trigger_data)
> -{
> - struct vectors * vecs;
> - int r;
> -
> - *reply = NULL;
> - *len = 0;
> - vecs = (struct vectors *)trigger_data;
> -
> - if ((str != NULL) && (is_root == false) &&
> - (strncmp(str, "list", strlen("list")) != 0) &&
> - (strncmp(str, "show", strlen("show")) != 0)) {
> - *reply = STRDUP("permission deny: need to be root");
> - if (*reply)
> - *len = strlen(*reply) + 1;
> - return 1;
> - }
> -
> - r = parse_cmd(str, reply, len, vecs, uxsock_timeout / 1000);
> -
> - if (r > 0) {
> - if (r == ETIMEDOUT)
> - *reply = STRDUP("timeout\n");
> - else
> - *reply = STRDUP("fail\n");
> - if (*reply)
> - *len = strlen(*reply) + 1;
> - r = 1;
> - }
> - else if (!r && *len == 0) {
> - *reply = STRDUP("ok\n");
> - if (*reply)
> - *len = strlen(*reply) + 1;
> - r = 0;
> - }
> - /* else if (r < 0) leave *reply alone */
> -
> - return r;
> -}
> -
> int
> uev_trigger (struct uevent * uev, void * trigger_data)
> {
> @@ -1704,7 +1662,7 @@ uxlsnrloop (void * ap)
> == DAEMON_CONFIGURE)
> handle_signals(false);
>
> - uxsock_listen(&uxsock_trigger, ux_sock, ap);
> + uxsock_listen(ux_sock, ap);
>
> out_sock:
> pthread_cleanup_pop(1); /* uxsock_cleanup */
> diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
> index e701a1c..622aac1 100644
> --- a/multipathd/uxlsnr.c
> +++ b/multipathd/uxlsnr.c
> @@ -311,11 +311,51 @@ static void handle_inotify(int fd, struct watch_descriptors *wds)
> condlog(1, "Multipath configuration updated.\nReload multipathd for changes to take effect");
> }
>
> +static int uxsock_trigger(char *str, char **reply, int *len,
> + bool is_root, void *trigger_data)
> +{
> + struct vectors * vecs;
> + int r;
> +
> + *reply = NULL;
> + *len = 0;
> + vecs = (struct vectors *)trigger_data;
> +
> + if ((str != NULL) && (is_root == false) &&
> + (strncmp(str, "list", strlen("list")) != 0) &&
> + (strncmp(str, "show", strlen("show")) != 0)) {
> + *reply = STRDUP("permission deny: need to be root");
> + if (*reply)
> + *len = strlen(*reply) + 1;
> + return 1;
> + }
> +
> + r = parse_cmd(str, reply, len, vecs, uxsock_timeout / 1000);
> +
> + if (r > 0) {
> + if (r == ETIMEDOUT)
> + *reply = STRDUP("timeout\n");
> + else
> + *reply = STRDUP("fail\n");
> + if (*reply)
> + *len = strlen(*reply) + 1;
> + r = 1;
> + }
> + else if (!r && *len == 0) {
> + *reply = STRDUP("ok\n");
> + if (*reply)
> + *len = strlen(*reply) + 1;
> + r = 0;
> + }
> + /* else if (r < 0) leave *reply alone */
> +
> + return r;
> +}
> +
> /*
> * entry point
> */
> -void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, long ux_sock,
> - void * trigger_data)
> +void *uxsock_listen(long ux_sock, void *trigger_data)
> {
> int rlen;
> char *inbuf;
> diff --git a/multipathd/uxlsnr.h b/multipathd/uxlsnr.h
> index 18f008d..60c3a2c 100644
> --- a/multipathd/uxlsnr.h
> +++ b/multipathd/uxlsnr.h
> @@ -3,10 +3,8 @@
>
> #include <stdbool.h>
>
> -typedef int (uxsock_trigger_fn)(char *, char **, int *, bool, void *);
> -
> void uxsock_cleanup(void *arg);
> -void *uxsock_listen(uxsock_trigger_fn uxsock_trigger, long ux_sock,
> +void *uxsock_listen(long ux_sock,
> void * trigger_data);
>
> #endif
> --
> 2.33.0
More information about the dm-devel
mailing list