1
0
mirror of https://github.com/eclipse/mosquitto.git synced 2025-05-08 16:52:13 +08:00

Fix mosquitto_pub -l not sending the final line of stdin

This would happen if the final line did not end with a new line.

Closes #1473. Thanks to majekw.
This commit is contained in:
Roger A. Light 2019-11-07 18:25:56 +00:00
parent 05171b266d
commit 1e04b22833
2 changed files with 11 additions and 1 deletions

View File

@ -24,6 +24,8 @@ Client library:
Clients:
- Fix duplicate cfg definition in rr_client. Closes #1453.
- Fix `mosquitto_pub -l` hang when stdin stream ends. Closes #1448.
- Fix `mosquitto_pub -l` not sending the final line of stdin if it does not
end with a new line. Closes #1473.
Build:
- Added `CLIENT_STATIC_LDADD` to makefile builds to allow more libraries to be

View File

@ -223,7 +223,7 @@ int pub_shared_init(void)
int pub_stdin_line_loop(struct mosquitto *mosq)
{
char *buf2;
int buf_len_actual;
int buf_len_actual = 0;
int pos;
int rc = MOSQ_ERR_SUCCESS;
int read_len;
@ -240,6 +240,7 @@ int pub_stdin_line_loop(struct mosquitto *mosq)
if(line_buf[buf_len_actual-1] == '\n'){
line_buf[buf_len_actual-1] = '\0';
rc = my_publish(mosq, &mid_sent, cfg.topic, buf_len_actual-1, line_buf, cfg.qos, cfg.retain);
pos = 0;
if(rc){
err_printf(&cfg, "Error: Publish returned %d, disconnecting.\n", rc);
mosquitto_disconnect_v5(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props);
@ -257,6 +258,13 @@ int pub_stdin_line_loop(struct mosquitto *mosq)
line_buf = buf2;
}
}
if(pos != 0){
rc = my_publish(mosq, &mid_sent, cfg.topic, buf_len_actual, line_buf, cfg.qos, cfg.retain);
if(rc){
err_printf(&cfg, "Error: Publish returned %d, disconnecting.\n", rc);
mosquitto_disconnect_v5(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props);
}
}
if(feof(stdin)){
if(mid_sent == -1){
/* Empty file */