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>
This commit is contained in:
parent
e94cf19989
commit
61702d7acc
@ -262,8 +262,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);
|
rc = my_publish(mosq, &mid_sent, cfg.topic, buf_len_actual-1, line_buf, cfg.qos, cfg.retain);
|
||||||
pos = 0;
|
pos = 0;
|
||||||
if(rc){
|
if(rc){
|
||||||
err_printf(&cfg, "Error: Publish returned %d, disconnecting.\n", rc);
|
err_printf(&cfg, "Error: Publish returned %d.\n", rc);
|
||||||
mosquitto_disconnect_v5(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props);
|
if(cfg.qos>0) return rc;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}else{
|
}else{
|
||||||
@ -281,8 +281,8 @@ int pub_stdin_line_loop(struct mosquitto *mosq)
|
|||||||
if(pos != 0){
|
if(pos != 0){
|
||||||
rc = my_publish(mosq, &mid_sent, cfg.topic, buf_len_actual, line_buf, cfg.qos, cfg.retain);
|
rc = my_publish(mosq, &mid_sent, cfg.topic, buf_len_actual, line_buf, cfg.qos, cfg.retain);
|
||||||
if(rc){
|
if(rc){
|
||||||
err_printf(&cfg, "Error: Publish returned %d, disconnecting.\n", rc);
|
err_printf(&cfg, "Error: Publish returned %d.\n", rc);
|
||||||
mosquitto_disconnect_v5(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props);
|
if(cfg.qos>0) return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(feof(stdin)){
|
if(feof(stdin)){
|
||||||
|
Loading…
Reference in New Issue
Block a user