cmdmon: don't create socket when cmdport is 0
This commit is contained in:
parent
cc1c6c94e3
commit
129aa587c6
2 changed files with 12 additions and 12 deletions
|
@ -1447,7 +1447,8 @@ There is also a @code{cmddeny all} directive with similar behaviour to the
|
||||||
|
|
||||||
The @code{cmdport} directive allows the port that is used for run-time
|
The @code{cmdport} directive allows the port that is used for run-time
|
||||||
command and monitoring (via the program @code{chronyc}) to be altered
|
command and monitoring (via the program @code{chronyc}) to be altered
|
||||||
from its default (323/udp).
|
from its default (323/udp). If set to 0, @code{chronyd} will not open the
|
||||||
|
port, this is useful to disable the @code{chronyc} access completely.
|
||||||
|
|
||||||
An example shows the syntax
|
An example shows the syntax
|
||||||
|
|
||||||
|
|
21
cmdmon.c
21
cmdmon.c
|
@ -171,22 +171,19 @@ static ADF_AuthTable access_auth_table;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Forward prototypes */
|
/* Forward prototypes */
|
||||||
static int prepare_socket(int family);
|
|
||||||
static void read_from_cmd_socket(void *anything);
|
static void read_from_cmd_socket(void *anything);
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
prepare_socket(int family)
|
prepare_socket(int family, int port_number)
|
||||||
{
|
{
|
||||||
int port_number, sock_fd;
|
int sock_fd;
|
||||||
socklen_t my_addr_len;
|
socklen_t my_addr_len;
|
||||||
union sockaddr_in46 my_addr;
|
union sockaddr_in46 my_addr;
|
||||||
IPAddr bind_address;
|
IPAddr bind_address;
|
||||||
int on_off = 1;
|
int on_off = 1;
|
||||||
|
|
||||||
port_number = CNF_GetCommandPort();
|
|
||||||
|
|
||||||
sock_fd = socket(family, SOCK_DGRAM, 0);
|
sock_fd = socket(family, SOCK_DGRAM, 0);
|
||||||
if (sock_fd < 0) {
|
if (sock_fd < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_CmdMon, "Could not open %s command socket : %s",
|
LOG(LOGS_ERR, LOGF_CmdMon, "Could not open %s command socket : %s",
|
||||||
|
@ -265,7 +262,7 @@ prepare_socket(int family)
|
||||||
void
|
void
|
||||||
CAM_Initialise(int family)
|
CAM_Initialise(int family)
|
||||||
{
|
{
|
||||||
int i;
|
int i, port_number;
|
||||||
|
|
||||||
assert(!initialised);
|
assert(!initialised);
|
||||||
initialised = 1;
|
initialised = 1;
|
||||||
|
@ -293,18 +290,20 @@ CAM_Initialise(int family)
|
||||||
free_replies = NULL;
|
free_replies = NULL;
|
||||||
kept_replies.next = NULL;
|
kept_replies.next = NULL;
|
||||||
|
|
||||||
if (family == IPADDR_UNSPEC || family == IPADDR_INET4)
|
port_number = CNF_GetCommandPort();
|
||||||
sock_fd4 = prepare_socket(AF_INET);
|
|
||||||
|
if (port_number && (family == IPADDR_UNSPEC || family == IPADDR_INET4))
|
||||||
|
sock_fd4 = prepare_socket(AF_INET, port_number);
|
||||||
else
|
else
|
||||||
sock_fd4 = -1;
|
sock_fd4 = -1;
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
if (family == IPADDR_UNSPEC || family == IPADDR_INET6)
|
if (port_number && (family == IPADDR_UNSPEC || family == IPADDR_INET6))
|
||||||
sock_fd6 = prepare_socket(AF_INET6);
|
sock_fd6 = prepare_socket(AF_INET6, port_number);
|
||||||
else
|
else
|
||||||
sock_fd6 = -1;
|
sock_fd6 = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (sock_fd4 < 0
|
if (port_number && sock_fd4 < 0
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
&& sock_fd6 < 0
|
&& sock_fd6 < 0
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue