mosquitto_pub: exit if server becomes unreachable and QOS > 0

Fixes eclipse/mosquitto#1899

In stdin line mode, mosquitto_pub will continue running and accepting
input even if/when/after publishing fails.  This condition is reached
when it first successfully establishes a connection and the server later
is unreachable.

Exiting with a non-zero exit code allows for much easier health
monitoring when used in a long-running pipe.

Signed-off-by: Dan White <dan.white@valpo.edu>
pull/1745/merge
Dan White 5 years ago committed by Roger Light
parent 2196efc90c
commit cdfa2252f1

@ -256,8 +256,8 @@ int pub_stdin_line_loop(struct mosquitto *mosq)
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);
err_printf(&cfg, "Error: Publish returned %d.\n", rc);
if(cfg.qos>0) return rc;
}
break;
}else{
@ -275,8 +275,8 @@ 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, disconnecting.\n", rc);
mosquitto_disconnect_v5(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props);
err_printf(&cfg, "Error: Publish returned %d.\n", rc);
if(cfg.qos>0) return rc;
}
}
if(feof(stdin)){

Loading…
Cancel
Save