From ec4c1254e5936d5164923fa07b29c66d13a923b8 Mon Sep 17 00:00:00 2001 From: benno Date: Wed, 29 Nov 2017 15:24:50 +0000 Subject: [PATCH] add options to specify the control socket in relayd and relayctl. From Kapetanakis Giannis, thanks. ok claudio@ --- usr.sbin/relayctl/relayctl.8 | 16 ++++++++++++++-- usr.sbin/relayctl/relayctl.c | 29 ++++++++++++++++++++++++----- usr.sbin/relayd/config.c | 3 ++- usr.sbin/relayd/parse.y | 5 ++++- usr.sbin/relayd/relayd.c | 5 +---- usr.sbin/relayd/relayd.conf.5 | 10 ++++++++-- 6 files changed, 53 insertions(+), 15 deletions(-) diff --git a/usr.sbin/relayctl/relayctl.8 b/usr.sbin/relayctl/relayctl.8 index 3ffe5834af6..c329136cdce 100644 --- a/usr.sbin/relayctl/relayctl.8 +++ b/usr.sbin/relayctl/relayctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: relayctl.8,v 1.32 2015/11/28 01:22:44 gsoares Exp $ +.\" $OpenBSD: relayctl.8,v 1.33 2017/11/29 15:24:50 benno Exp $ .\" .\" Copyright (c) 2007 - 2013 Reyk Floeter .\" Copyright (c) 2006 Pierre-Yves Ritschard @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: November 28 2015 $ +.Dd $Mdocdate: November 29 2017 $ .Dt RELAYCTL 8 .Os .Sh NAME @@ -23,6 +23,7 @@ .Nd control the relay daemon .Sh SYNOPSIS .Nm +.Op Fl s Ar socket .Ar command .Op Ar argument ... .Sh DESCRIPTION @@ -32,6 +33,17 @@ program controls the .Xr relayd 8 daemon. .Pp +The following options are available: +.Bl -tag -width Ds +.It Fl s Ar socket +Use +.Ar socket +instead of the default +.Pa /var/run/relayd.sock +to communicate with +.Xr relayd 8 . +.El +.Pp The following commands are available: .Bl -tag -width Ds .It Cm host disable Op Ar name | id diff --git a/usr.sbin/relayctl/relayctl.c b/usr.sbin/relayctl/relayctl.c index 7b52c21e61e..83bacf05b94 100644 --- a/usr.sbin/relayctl/relayctl.c +++ b/usr.sbin/relayctl/relayctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relayctl.c,v 1.57 2016/09/03 14:44:21 reyk Exp $ */ +/* $OpenBSD: relayctl.c,v 1.58 2017/11/29 15:24:50 benno Exp $ */ /* * Copyright (c) 2007 - 2013 Reyk Floeter @@ -88,7 +88,8 @@ usage(void) { extern char *__progname; - fprintf(stderr, "usage: %s command [argument ...]\n", __progname); + fprintf(stderr, "usage: %s [-s socket] command [argument ...]\n", + __progname); exit(1); } @@ -101,9 +102,25 @@ main(int argc, char *argv[]) int ctl_sock; int done = 0; int n, verbose = 0; + int ch; + const char *sockname; + + sockname = RELAYD_SOCKET; + while ((ch = getopt(argc, argv, "s:")) != -1) { + switch (ch) { + case 's': + sockname = optarg; + break; + default: + usage(); + /* NOTREACHED */ + } + } + argc -= optind; + argv += optind; /* parse options */ - if ((res = parse(argc - 1, argv + 1)) == NULL) + if ((res = parse(argc, argv)) == NULL) exit(1); /* connect to relayd control socket */ @@ -112,7 +129,9 @@ main(int argc, char *argv[]) bzero(&sun, sizeof(sun)); sun.sun_family = AF_UNIX; - (void)strlcpy(sun.sun_path, RELAYD_SOCKET, sizeof(sun.sun_path)); + if (strlcpy(sun.sun_path, sockname, sizeof(sun.sun_path)) >= + sizeof(sun.sun_path)) + errx(1, "socket `%s' too long", sockname); reconnect: if (connect(ctl_sock, (struct sockaddr *)&sun, sizeof(sun)) == -1) { /* Keep retrying if running in monitor mode */ @@ -121,7 +140,7 @@ main(int argc, char *argv[]) usleep(100); goto reconnect; } - err(1, "connect: %s", RELAYD_SOCKET); + err(1, "connect: %s", sockname); } if (pledge("stdio", NULL) == -1) diff --git a/usr.sbin/relayd/config.c b/usr.sbin/relayd/config.c index 2a17e1b38e6..a8e88baac37 100644 --- a/usr.sbin/relayd/config.c +++ b/usr.sbin/relayd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.35 2017/11/27 23:21:16 claudio Exp $ */ +/* $OpenBSD: config.c,v 1.36 2017/11/29 15:24:50 benno Exp $ */ /* * Copyright (c) 2011 - 2014 Reyk Floeter @@ -44,6 +44,7 @@ config_init(struct relayd *env) env->sc_conf.interval.tv_usec = 0; env->sc_conf.prefork_relay = RELAY_NUMPROC; env->sc_conf.statinterval.tv_sec = RELAY_STATINTERVAL; + env->sc_ps->ps_csock.cs_name = RELAYD_SOCKET; } ps->ps_what[PROC_PARENT] = CONFIG_ALL; diff --git a/usr.sbin/relayd/parse.y b/usr.sbin/relayd/parse.y index 51e5eb6ae49..0f05f4ee01b 100644 --- a/usr.sbin/relayd/parse.y +++ b/usr.sbin/relayd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.220 2017/11/27 23:21:16 claudio Exp $ */ +/* $OpenBSD: parse.y,v 1.221 2017/11/29 15:24:50 benno Exp $ */ /* * Copyright (c) 2007 - 2014 Reyk Floeter @@ -418,6 +418,9 @@ main : INTERVAL NUMBER { AGENTX_SOCKET, sizeof(conf->sc_conf.snmp_path)); } + | SOCKET STRING { + conf->sc_ps->ps_csock.cs_name = $2; + } ; trap : /* nothing */ { $$ = 0; } diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c index cb7567d6486..0ce53b41d5d 100644 --- a/usr.sbin/relayd/relayd.c +++ b/usr.sbin/relayd/relayd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relayd.c,v 1.170 2017/11/27 21:06:26 claudio Exp $ */ +/* $OpenBSD: relayd.c,v 1.171 2017/11/29 15:24:50 benno Exp $ */ /* * Copyright (c) 2007 - 2016 Reyk Floeter @@ -199,9 +199,6 @@ main(int argc, char *argv[]) if ((ps->ps_pw = getpwnam(RELAYD_USER)) == NULL) errx(1, "unknown user %s", RELAYD_USER); - /* Configure the control socket */ - ps->ps_csock.cs_name = RELAYD_SOCKET; - log_init(debug, LOG_DAEMON); log_setverbose(verbose); diff --git a/usr.sbin/relayd/relayd.conf.5 b/usr.sbin/relayd/relayd.conf.5 index d8af8c7418c..85089d26ac8 100644 --- a/usr.sbin/relayd/relayd.conf.5 +++ b/usr.sbin/relayd/relayd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: relayd.conf.5,v 1.180 2017/11/27 23:21:16 claudio Exp $ +.\" $OpenBSD: relayd.conf.5,v 1.181 2017/11/29 15:24:50 benno Exp $ .\" .\" Copyright (c) 2006 - 2016 Reyk Floeter .\" Copyright (c) 2006, 2007 Pierre-Yves Ritschard @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: November 27 2017 $ +.Dd $Mdocdate: November 29 2017 $ .Dt RELAYD.CONF 5 .Os .Sh NAME @@ -163,6 +163,12 @@ will be used. See .Xr snmpd.conf 5 for more information about SNMP configuration. +.It Ic socket Qo Ar path Qc +Create a control socket at +.Ar path . +By default +.Pa /var/run/relayd.sock +is used.. .It Ic timeout Ar number Set the global timeout in milliseconds for checks. This can be overridden by the timeout value in the table definitions. -- 2.20.1