Skip to content

Commit

Permalink
Don't print connect/disconnect messages when connection_messages false.
Browse files Browse the repository at this point in the history
Closes #772. Closes #613. Closes #537.

Thanks to Christopher Maynard, Brandon Arrendondo, and qubeck.
  • Loading branch information
ralight committed Dec 11, 2018
1 parent a00dd29 commit 89f3d7b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Broker:
- Don't reload auth_opt_ options on reload, to match the behaviour of the
other plugin options. Closes #1068.
- Print message on error when installing/uninstalling as a Windows service.
- All non-error connect/disconnect messages are controlled by the
`connection_messages` option. Closes #772. Closes #613. Closes #537.

Library:
- Fix reconnect delay backoff behaviour. Closes #1027.
Expand Down
8 changes: 6 additions & 2 deletions src/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ static void temp__expire_websockets_clients(struct mosquitto_db *db)
}else{
id = "<unknown>";
}
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s has exceeded timeout, disconnecting.", id);
if(db->config->connection_messages == true){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s has exceeded timeout, disconnecting.", id);
}
}
/* Client has exceeded keepalive*1.5 */
do_disconnect(db, context);
Expand Down Expand Up @@ -666,7 +668,9 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context)
}
#ifdef WITH_EPOLL
if (context->sock != INVALID_SOCKET && epoll_ctl(db->epollfd, EPOLL_CTL_DEL, context->sock, &ev) == -1) {
log__printf(NULL, MOSQ_LOG_DEBUG, "Error in epoll disconnecting: %s", strerror(errno));
if(db->config->connection_messages == true){
log__printf(NULL, MOSQ_LOG_DEBUG, "Error in epoll disconnecting: %s", strerror(errno));
}
}
#endif
context__disconnect(db, context);
Expand Down
26 changes: 17 additions & 9 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ int net__socket_accept(struct mosquitto_db *db, mosq_sock_t listensock)
fromhost(&wrap_req);
if(!hosts_access(&wrap_req)){
/* Access is denied */
if(!net__socket_get_address(new_sock, address, 1024)){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied access by tcpd.", address);
if(db->config->connection_messages == true){
if(!net__socket_get_address(new_sock, address, 1024)){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied access by tcpd.", address);
}
}
COMPAT_CLOSE(new_sock);
return -1;
Expand Down Expand Up @@ -187,7 +189,9 @@ int net__socket_accept(struct mosquitto_db *db, mosq_sock_t listensock)
}

if(new_context->listener->max_connections > 0 && new_context->listener->client_count > new_context->listener->max_connections){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", new_context->address);
if(db->config->connection_messages == true){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", new_context->address);
}
context__cleanup(db, new_context, true);
return -1;
}
Expand Down Expand Up @@ -217,12 +221,14 @@ int net__socket_accept(struct mosquitto_db *db, mosq_sock_t listensock)
}else if(rc == SSL_ERROR_WANT_WRITE){
new_context->want_write = true;
}else{
e = ERR_get_error();
while(e){
log__printf(NULL, MOSQ_LOG_NOTICE,
"Client connection from %s failed: %s.",
new_context->address, ERR_error_string(e, ebuf));
if(db->config->connection_messages == true){
e = ERR_get_error();
while(e){
log__printf(NULL, MOSQ_LOG_NOTICE,
"Client connection from %s failed: %s.",
new_context->address, ERR_error_string(e, ebuf));
e = ERR_get_error();
}
}
context__cleanup(db, new_context, true);
return -1;
Expand All @@ -234,7 +240,9 @@ int net__socket_accept(struct mosquitto_db *db, mosq_sock_t listensock)
}
#endif

log__printf(NULL, MOSQ_LOG_NOTICE, "New connection from %s on port %d.", new_context->address, new_context->listener->port);
if(db->config->connection_messages == true){
log__printf(NULL, MOSQ_LOG_NOTICE, "New connection from %s on port %d.", new_context->address, new_context->listener->port);
}

return new_sock;
}
Expand Down
4 changes: 3 additions & 1 deletion src/websockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ static int callback_mqtt(struct libwebsocket_context *context,
return -1;
}
if(mosq->listener->max_connections > 0 && mosq->listener->client_count > mosq->listener->max_connections){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", mosq->address);
if(db->config->connection_messages == true){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", mosq->address);
}
mosquitto__free(mosq);
u->mosq = NULL;
return -1;
Expand Down

0 comments on commit 89f3d7b

Please sign in to comment.