From: Martin Wilck <mwilck@xxxxxxxx> 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@xxxxxxxxxx> Signed-off-by: Martin Wilck <mwilck@xxxxxxxx> --- 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 0820a05..dbe6dc7 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1537,48 +1537,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) { @@ -1715,7 +1673,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.1 -- dm-devel mailing list dm-devel@xxxxxxxxxx https://listman.redhat.com/mailman/listinfo/dm-devel