Provide help for users trying to bind to privileged ports.

Closes #2098.
This commit is contained in:
Roger A. Light 2021-04-03 11:33:57 +01:00
parent eead0d2943
commit 983dc14f2c

View File

@ -754,6 +754,12 @@ static int net__socket_listen_tcp(struct mosquitto__listener *listener)
#endif
if(bind(sock, rp->ai_addr, rp->ai_addrlen) == -1){
#if defined(__linux__)
if(errno == EACCES){
log__printf(NULL, MOSQ_LOG_ERR, "If you are trying to bind to a privileged port (<1024), try using setcap and do not start the broker as root:");
log__printf(NULL, MOSQ_LOG_ERR, " sudo setcap 'CAP_NET_BIND_SERVICE=+ep /usr/sbin/mosquitto'");
}
#endif
net__print_error(MOSQ_LOG_ERR, "Error: %s");
COMPAT_CLOSE(sock);
freeaddrinfo(ainfo);