Don't try to start DLT logging if DLT unavailable.

This is to avoid a long delay when shutting down the broker.

Closes #1735. Thanks to Colin Law.
This commit is contained in:
Roger A. Light 2020-08-04 11:17:04 +01:00
parent 1f717873d6
commit 618cd7006b
2 changed files with 35 additions and 4 deletions

View File

@ -17,6 +17,8 @@ Broker:
Closes #1689. Closes #1741. Closes #1689. Closes #1741.
- Log protocol error message where appropriate from a bad UNSUBSCRIBE, rather - Log protocol error message where appropriate from a bad UNSUBSCRIBE, rather
than the generic "socket error". than the generic "socket error".
- Don't try to start DLT logging if DLT unavailable, to avoid a long delay
when shutting down the broker. Closes #1735.
Client library: Client library:
- Improved documentation around connect callback return codes. Close #1730. - Improved documentation around connect callback return codes. Close #1730.

View File

@ -24,6 +24,7 @@ Contributors:
#include <time.h> #include <time.h>
#ifdef WITH_DLT #ifdef WITH_DLT
#include <sys/stat.h>
#include <dlt/dlt.h> #include <dlt/dlt.h>
#endif #endif
@ -55,6 +56,29 @@ static int log_priorities = MOSQ_LOG_ERR | MOSQ_LOG_WARNING | MOSQ_LOG_NOTICE |
#ifdef WITH_DLT #ifdef WITH_DLT
static DltContext dltContext; static DltContext dltContext;
static bool dlt_allowed = false;
void dlt_fifo_check(void)
{
struct stat statbuf;
int fd;
/* If we start DLT but the /tmp/dlt fifo doesn't exist, or isn't available
* for writing then there is a big delay when we try and close the log
* later, so check for it first. This has the side effect of not letting
* people using DLT create the fifo after Mosquitto has started, but at the
* benefit of not having a massive delay for everybody else. */
memset(&statbuf, 0, sizeof(statbuf));
if(stat("/tmp/dlt", &statbuf) == 0){
if(S_ISFIFO(statbuf.st_mode)){
fd = open("/tmp/dlt", O_NONBLOCK | O_WRONLY);
if(fd != -1){
dlt_allowed = true;
close(fd);
}
}
}
}
#endif #endif
static int get_time(struct tm **ti) static int get_time(struct tm **ti)
@ -120,8 +144,11 @@ int log__init(struct mosquitto__config *config)
restore_privileges(); restore_privileges();
} }
#ifdef WITH_DLT #ifdef WITH_DLT
DLT_REGISTER_APP("MQTT","mosquitto log"); dlt_fifo_check();
dlt_register_context(&dltContext, "MQTT", "mosquitto DLT context"); if(dlt_allowed){
DLT_REGISTER_APP("MQTT","mosquitto log");
dlt_register_context(&dltContext, "MQTT", "mosquitto DLT context");
}
#endif #endif
return rc; return rc;
} }
@ -143,8 +170,10 @@ int log__close(struct mosquitto__config *config)
} }
#ifdef WITH_DLT #ifdef WITH_DLT
dlt_unregister_context(&dltContext); if(dlt_allowed){
DLT_UNREGISTER_APP(); dlt_unregister_context(&dltContext);
DLT_UNREGISTER_APP();
}
#endif #endif
/* FIXME - do something for all destinations! */ /* FIXME - do something for all destinations! */
return MOSQ_ERR_SUCCESS; return MOSQ_ERR_SUCCESS;