Skip to content

Commit ffb241f

Browse files
committed
agents: fix profile/snapshot messages body format
In general fix `ZmqAgent::send_command_message` so it handles correctly both an empty and a null body. PR-URL: #23 Reviewed-by: Trevor Norris <[email protected]>
1 parent 6e37c40 commit ffb241f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

agents/zmq/src/zmq_agent.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ int ZmqAgent::send_command_message(const char* command,
10951095
return PrintZmqError(zmq::ZMQ_ERROR_SEND_COMMAND_NO_DATA_HANDLE, command);
10961096
}
10971097

1098+
const char* real_body = body ? (strlen(body) ? body : "\"\"") : "null";
10981099
auto recorded = create_recorded(system_clock::now());
10991100
int r;
11001101
if (request_id == nullptr) {
@@ -1108,7 +1109,7 @@ int ZmqAgent::send_command_message(const char* command,
11081109
0,
11091110
metrics_period_,
11101111
version_,
1111-
body);
1112+
real_body);
11121113

11131114
} else {
11141115
r = snprintf(msg_buf_,
@@ -1122,7 +1123,7 @@ int ZmqAgent::send_command_message(const char* command,
11221123
0,
11231124
metrics_period_,
11241125
version_,
1125-
body);
1126+
real_body);
11261127
}
11271128

11281129
if (r < 0) {
@@ -1371,7 +1372,7 @@ int ZmqAgent::generate_snapshot(const json& message,
13711372
}
13721373

13731374
// send snapshot command reponse thru data channel
1374-
int r = send_command_message("snapshot", req_id.c_str(), "");
1375+
int r = send_command_message("snapshot", req_id.c_str(), nullptr);
13751376
if (r < 0) {
13761377
return r;
13771378
}
@@ -2208,7 +2209,7 @@ std::string ZmqAgent::got_cpu_profile(int status,
22082209
// send profile_stop command reponse thru data channel
22092210
// only if the profile is complete
22102211
if (profileStreamComplete) {
2211-
int r = send_command_message("profile_stop", req_id.c_str(), "");
2212+
int r = send_command_message("profile_stop", req_id.c_str(), nullptr);
22122213
if (r < 0) {
22132214
return req_id;
22142215
}
@@ -2292,7 +2293,7 @@ int ZmqAgent::start_profiling(const json& message,
22922293
}
22932294

22942295
// send profile command reponse thru data channel
2295-
err = send_command_message(kProfile, req_id.c_str(), "");
2296+
err = send_command_message(kProfile, req_id.c_str(), nullptr);
22962297
if (err < 0) {
22972298
return err;
22982299
}

0 commit comments

Comments
 (0)