Skip to content

Commit

Permalink
jsonrpc_server: Remove newlines only if JSON RPC logging is enabled
Browse files Browse the repository at this point in the history
We removed newlines by default when JSON RPC logging is supported
because newlines do not affect the functionality of JSON RPC objects.
However, this change lost backward compatibility of some custom
applications which enabled SPDK_JSON_PARSE_FLAG_ALLOW_COMMENTS.

JSON RPC logging is an optional feature. Hence, as a workaround we
remove newlines only if JSON RPC logging is enabled.

Fixes github issue spdk#3155

Signed-off-by: Shuhei Matsumoto <[email protected]>
Change-Id: I3c7bd0b5b0fc27538c22b6fa10a67fd2a6e5895d
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/20505
Reviewed-by: Tomasz Zawadzki <[email protected]>
Community-CI: Mellanox Build Bot
Reviewed-by: Jim Harris <[email protected]>
Tested-by: SPDK CI Jenkins <[email protected]>
  • Loading branch information
shuhei-matsumoto authored and tomzawadzki committed Nov 7, 2023
1 parent 0bfa253 commit 1078198
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/jsonrpc/jsonrpc_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ remove_newlines(char *text)
static void
jsonrpc_log(char *buf, const char *prefix)
{
/* Remove newlines to print in a single line.
* Newlines does not affect the functionality of JSON RPC objects.
* Hence for simplicity, remove newlines by default.
/* Some custom applications have enabled SPDK_JSON_PARSE_FLAG_ALLOW_COMMENTS
* to allow comments in JSON RPC objects. To keep backward compatibility of
* these applications, remove newlines only if JSON RPC logging is enabled.
*/
remove_newlines(buf);
if (g_rpc_log_level != SPDK_LOG_DISABLED || g_rpc_log_file != NULL) {
remove_newlines(buf);
}

if (g_rpc_log_level != SPDK_LOG_DISABLED) {
spdk_log(g_rpc_log_level, NULL, 0, NULL, "%s%s\n", prefix, buf);
Expand Down

0 comments on commit 1078198

Please sign in to comment.