From 07399c2f3cdbb737ed8d26cada05939737fa63cf Mon Sep 17 00:00:00 2001 From: Roger Light Date: Sat, 8 May 2021 23:07:02 +0100 Subject: [PATCH] Fix `mosquitto_pub -l` quitting if broker unavailable. This could occur when a message publication is attempted when the broker is temporarily unavailable. Closes #2187. Thanks to JsBergbau. --- ChangeLog.txt | 2 ++ client/pub_client.c | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 34549160..25a84084 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -9,6 +9,8 @@ Broker: Clients: - If sending mosquitto_sub output to a pipe, mosquitto_sub will now detect that the pipe has closed and disconnect. Closes #2164. +- Fix `mosquitto_pub -l` quitting if a message publication is attempted when + the broker is temporarily unavailable. Closes #2187. 2.0.10 - 2021-04-03 diff --git a/client/pub_client.c b/client/pub_client.c index 036c8c68..4ee026bd 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -268,9 +268,8 @@ static int pub_stdin_line_loop(struct mosquitto *mosq) 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.\n", rc); - if(cfg.qos>0) return rc; + if(rc != MOSQ_ERR_SUCCESS && rc != MOSQ_ERR_NO_CONN){ + return rc; } break; }else{ @@ -288,7 +287,6 @@ static int pub_stdin_line_loop(struct mosquitto *mosq) 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.\n", rc); if(cfg.qos>0) return rc; } } @@ -357,7 +355,7 @@ static int pub_other_loop(struct mosquitto *mosq) rc = my_publish(mosq, &mid_sent, cfg.topic, 0, NULL, cfg.qos, cfg.retain); break; } - if(rc){ + if(rc != MOSQ_ERR_SUCCESS && rc != MOSQ_ERR_NO_CONN){ err_printf(&cfg, "Error sending repeat publish: %s", mosquitto_strerror(rc)); } }