From bcacfb780836f294d9d227e83fd696b6eb9e7e07 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 3 May 2019 13:34:51 -0700 Subject: [PATCH] rpc: do not allow duplicated rpc method names Also print error message when a duplicate is detected. Signed-off-by: Jim Harris Change-Id: Ibcc667700a5b410e3a300507e76b99d04b09cfc1 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/453031 Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Changpeng Liu Reviewed-by: Ben Walker --- lib/rpc/rpc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/rpc/rpc.c b/lib/rpc/rpc.c index de10103c8..df9d1e55f 100644 --- a/lib/rpc/rpc.c +++ b/lib/rpc/rpc.c @@ -87,6 +87,18 @@ _get_rpc_method(const struct spdk_json_val *method) return NULL; } +static struct spdk_rpc_method * +_get_rpc_method_raw(const char *method) +{ + struct spdk_json_val method_val; + + method_val.type = SPDK_JSON_VAL_STRING; + method_val.len = strlen(method); + method_val.start = (char *)method; + + return _get_rpc_method(&method_val); +} + static void spdk_jsonrpc_handler(struct spdk_jsonrpc_request *request, const struct spdk_json_val *method, @@ -224,6 +236,12 @@ spdk_rpc_register_method(const char *method, spdk_rpc_method_handler func, uint3 { struct spdk_rpc_method *m; + m = _get_rpc_method_raw(method); + if (m != NULL) { + SPDK_ERRLOG("duplicate RPC %s registered - ignoring...\n", method); + return; + } + m = calloc(1, sizeof(struct spdk_rpc_method)); assert(m != NULL);