|
|
68b27c |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
68b27c |
From: Martin Wilck <mwilck@suse.com>
|
|
|
68b27c |
Date: Mon, 17 May 2021 22:37:34 +0200
|
|
|
68b27c |
Subject: [PATCH] multipathd: cli_handlers: cleanup setting reply length
|
|
|
68b27c |
|
|
|
68b27c |
Create a macro for setting the reply length for string literals
|
|
|
68b27c |
correctly, and use it where necessary.
|
|
|
68b27c |
|
|
|
68b27c |
In cli_del_path(), don't change the function's return code
|
|
|
68b27c |
if just the buffer allocation for the reply failed.
|
|
|
68b27c |
|
|
|
68b27c |
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
68b27c |
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
68b27c |
---
|
|
|
68b27c |
multipathd/cli_handlers.c | 33 ++++++++++++---------------------
|
|
|
68b27c |
1 file changed, 12 insertions(+), 21 deletions(-)
|
|
|
68b27c |
|
|
|
68b27c |
diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
|
|
|
68b27c |
index 6765fcf0..96064944 100644
|
|
|
68b27c |
--- a/multipathd/cli_handlers.c
|
|
|
68b27c |
+++ b/multipathd/cli_handlers.c
|
|
|
68b27c |
@@ -32,6 +32,12 @@
|
|
|
68b27c |
#include "foreign.h"
|
|
|
68b27c |
#include "cli_handlers.h"
|
|
|
68b27c |
|
|
|
68b27c |
+#define SET_REPLY_AND_LEN(__rep, __len, string_literal) \
|
|
|
68b27c |
+ do { \
|
|
|
68b27c |
+ *(__rep) = strdup(string_literal); \
|
|
|
68b27c |
+ *(__len) = *(__rep) ? sizeof(string_literal) : 0; \
|
|
|
68b27c |
+ } while (0)
|
|
|
68b27c |
+
|
|
|
68b27c |
int
|
|
|
68b27c |
show_paths (char ** r, int * len, struct vectors * vecs, char * style,
|
|
|
68b27c |
int pretty)
|
|
|
68b27c |
@@ -802,8 +808,7 @@ cli_add_path (void * v, char ** reply, int * len, void * data)
|
|
|
68b27c |
}
|
|
|
68b27c |
return ev_add_path(pp, vecs, 1);
|
|
|
68b27c |
blacklisted:
|
|
|
68b27c |
- *reply = strdup("blacklisted\n");
|
|
|
68b27c |
- *len = strlen(*reply) + 1;
|
|
|
68b27c |
+ SET_REPLY_AND_LEN(reply, len, "blacklisted\n");
|
|
|
68b27c |
condlog(2, "%s: path blacklisted", param);
|
|
|
68b27c |
return 0;
|
|
|
68b27c |
}
|
|
|
68b27c |
@@ -824,23 +829,10 @@ cli_del_path (void * v, char ** reply, int * len, void * data)
|
|
|
68b27c |
return 1;
|
|
|
68b27c |
}
|
|
|
68b27c |
ret = ev_remove_path(pp, vecs, 1);
|
|
|
68b27c |
- if (ret == REMOVE_PATH_DELAY) {
|
|
|
68b27c |
- *reply = strdup("delayed\n");
|
|
|
68b27c |
- if (*reply)
|
|
|
68b27c |
- *len = strlen(*reply) + 1;
|
|
|
68b27c |
- else {
|
|
|
68b27c |
- *len = 0;
|
|
|
68b27c |
- ret = REMOVE_PATH_FAILURE;
|
|
|
68b27c |
- }
|
|
|
68b27c |
- } else if (ret == REMOVE_PATH_MAP_ERROR) {
|
|
|
68b27c |
- *reply = strdup("map reload error. removed\n");
|
|
|
68b27c |
- if (*reply)
|
|
|
68b27c |
- *len = strlen(*reply) + 1;
|
|
|
68b27c |
- else {
|
|
|
68b27c |
- *len = 0;
|
|
|
68b27c |
- ret = REMOVE_PATH_FAILURE;
|
|
|
68b27c |
- }
|
|
|
68b27c |
- }
|
|
|
68b27c |
+ if (ret == REMOVE_PATH_DELAY)
|
|
|
68b27c |
+ SET_REPLY_AND_LEN(reply, len, "delayed\n");
|
|
|
68b27c |
+ else if (ret == REMOVE_PATH_MAP_ERROR)
|
|
|
68b27c |
+ SET_REPLY_AND_LEN(reply, len, "map reload error. removed\n");
|
|
|
68b27c |
return (ret == REMOVE_PATH_FAILURE);
|
|
|
68b27c |
}
|
|
|
68b27c |
|
|
|
68b27c |
@@ -865,8 +857,7 @@ cli_add_map (void * v, char ** reply, int * len, void * data)
|
|
|
68b27c |
invalid = 1;
|
|
|
68b27c |
pthread_cleanup_pop(1);
|
|
|
68b27c |
if (invalid) {
|
|
|
68b27c |
- *reply = strdup("blacklisted\n");
|
|
|
68b27c |
- *len = strlen(*reply) + 1;
|
|
|
68b27c |
+ SET_REPLY_AND_LEN(reply, len, "blacklisted\n");
|
|
|
68b27c |
condlog(2, "%s: map blacklisted", param);
|
|
|
68b27c |
return 1;
|
|
|
68b27c |
}
|