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:
parent
1f717873d6
commit
618cd7006b
@ -17,6 +17,8 @@ Broker:
|
||||
Closes #1689. Closes #1741.
|
||||
- Log protocol error message where appropriate from a bad UNSUBSCRIBE, rather
|
||||
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:
|
||||
- Improved documentation around connect callback return codes. Close #1730.
|
||||
|
@ -24,6 +24,7 @@ Contributors:
|
||||
#include <time.h>
|
||||
|
||||
#ifdef WITH_DLT
|
||||
#include <sys/stat.h>
|
||||
#include <dlt/dlt.h>
|
||||
#endif
|
||||
|
||||
@ -55,6 +56,29 @@ static int log_priorities = MOSQ_LOG_ERR | MOSQ_LOG_WARNING | MOSQ_LOG_NOTICE |
|
||||
|
||||
#ifdef WITH_DLT
|
||||
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
|
||||
|
||||
static int get_time(struct tm **ti)
|
||||
@ -120,8 +144,11 @@ int log__init(struct mosquitto__config *config)
|
||||
restore_privileges();
|
||||
}
|
||||
#ifdef WITH_DLT
|
||||
dlt_fifo_check();
|
||||
if(dlt_allowed){
|
||||
DLT_REGISTER_APP("MQTT","mosquitto log");
|
||||
dlt_register_context(&dltContext, "MQTT", "mosquitto DLT context");
|
||||
}
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
@ -143,8 +170,10 @@ int log__close(struct mosquitto__config *config)
|
||||
}
|
||||
|
||||
#ifdef WITH_DLT
|
||||
if(dlt_allowed){
|
||||
dlt_unregister_context(&dltContext);
|
||||
DLT_UNREGISTER_APP();
|
||||
}
|
||||
#endif
|
||||
/* FIXME - do something for all destinations! */
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
|
Loading…
Reference in New Issue
Block a user