On 23/06/17 11:07, Kapetanakis Giannis wrote: > On 23/06/17 04:43, David Gwynne wrote: >> >>> On 23 Jun 2017, at 01:15, Kapetanakis Giannis <bil...@edu.physics.uoc.gr> >>> wrote: >>> >>> Hi, >>> >>> Here is a patch for using alternative control socket for relayd and >>> relayctl. >>> It's based on ospfd. I would like for this to get in order to be able to >>> control multiple relayd daemons on different rdomains. >> >> i had something very much like this here, but more to limit the scope of >> failure than run in multiple rdomains. >> >> id like to see some tweaks for the ctl side though. see below. > > Thanks for the comments. > updated diff bellow > > btw char instead of const char is used all over the tree, also for conf files. > > G
Hi, After reading back in the archive, I found out that it's preferred for this to be in conf file instead of argument. Here is an updated version for relayd that uses configuration file. relayctl is the same so I don't post again. regards, Giannis Index: config.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/config.c,v retrieving revision 1.32 diff -u -p -r1.32 config.c --- config.c 27 May 2017 08:33:25 -0000 1.32 +++ config.c 10 Jul 2017 08:49:09 -0000 @@ -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; Index: parse.y =================================================================== RCS file: /cvs/src/usr.sbin/relayd/parse.y,v retrieving revision 1.215 diff -u -p -r1.215 parse.y --- parse.y 27 May 2017 08:33:25 -0000 1.215 +++ parse.y 10 Jul 2017 08:49:09 -0000 @@ -413,6 +413,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; } Index: relayd.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/relayd.c,v retrieving revision 1.169 diff -u -p -r1.169 relayd.c --- relayd.c 31 May 2017 04:14:34 -0000 1.169 +++ relayd.c 10 Jul 2017 08:49:09 -0000 @@ -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); Index: relayd.conf.5 =================================================================== RCS file: /cvs/src/usr.sbin/relayd/relayd.conf.5,v retrieving revision 1.177 diff -u -p -r1.177 relayd.conf.5 --- relayd.conf.5 19 Apr 2017 10:48:57 -0000 1.177 +++ relayd.conf.5 10 Jul 2017 08:49:09 -0000 @@ -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 created and no other sockets are created. .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. > > Index: relayctl/relayctl.8 > =================================================================== > RCS file: /cvs/src/usr.sbin/relayctl/relayctl.8,v > retrieving revision 1.32 > diff -u -p -r1.32 relayctl.8 > --- relayctl/relayctl.8 28 Nov 2015 01:22:44 -0000 1.32 > +++ relayctl/relayctl.8 23 Jun 2017 07:57:59 -0000 > @@ -23,6 +23,7 @@ > .Nd control the relay daemon > .Sh SYNOPSIS > .Nm > +.Op Fl s Ar socket > .Ar command > .Op Ar argument ... > .Sh DESCRIPTION > @@ -31,6 +32,21 @@ The > program controls the > .Xr relayd 8 > daemon. > +Commands may be abbreviated to the minimum unambiguous prefix; for example, > +.Cm sh su > +for > +.Cm show summary . > +.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 > Index: relayctl/relayctl.c > =================================================================== > RCS file: /cvs/src/usr.sbin/relayctl/relayctl.c,v > retrieving revision 1.57 > diff -u -p -r1.57 relayctl.c > --- relayctl/relayctl.c 3 Sep 2016 14:44:21 -0000 1.57 > +++ relayctl/relayctl.c 23 Jun 2017 07:57:59 -0000 > @@ -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) > Index: relayd/relayd.8 > =================================================================== > RCS file: /cvs/src/usr.sbin/relayd/relayd.8,v > retrieving revision 1.25 > diff -u -p -r1.25 relayd.8 > --- relayd/relayd.8 27 Jul 2015 14:50:58 -0000 1.25 > +++ relayd/relayd.8 23 Jun 2017 07:57:26 -0000 > @@ -25,6 +25,7 @@ > .Op Fl dnv > .Op Fl D Ar macro Ns = Ns Ar value > .Op Fl f Ar file > +.Op Fl s Ar socket > .Sh DESCRIPTION > .Nm > is a daemon to relay and dynamically redirect incoming connections to > @@ -118,6 +119,8 @@ The default is > .It Fl n > Configtest mode. > Only check the configuration file for validity. > +.It Fl s Ar socket > +Use an alternate location for the default control socket. > .It Fl v > Produce more verbose output. > .El > Index: relayd/relayd.c > =================================================================== > RCS file: /cvs/src/usr.sbin/relayd/relayd.c,v > retrieving revision 1.169 > diff -u -p -r1.169 relayd.c > --- relayd/relayd.c 31 May 2017 04:14:34 -0000 1.169 > +++ relayd/relayd.c 23 Jun 2017 07:57:26 -0000 > @@ -107,7 +107,8 @@ usage(void) > { > extern char *__progname; > > - fprintf(stderr, "usage: %s [-dnv] [-D macro=value] [-f file]\n", > + fprintf(stderr, "usage: %s [-dnv] [-D macro=value] [-f file]" > + " [-s socket]\n", > __progname); > exit(1); > } > @@ -121,12 +122,13 @@ main(int argc, char *argv[]) > struct relayd *env; > struct privsep *ps; > const char *conffile = CONF_FILE; > + const char *sockname = RELAYD_SOCKET; > enum privsep_procid proc_id = PROC_PARENT; > int proc_instance = 0; > const char *errp, *title = NULL; > int argc0 = argc; > > - while ((c = getopt(argc, argv, "dD:nI:P:f:v")) != -1) { > + while ((c = getopt(argc, argv, "dD:nI:P:f:s:v")) != -1) { > switch (c) { > case 'd': > debug = 2; > @@ -143,6 +145,9 @@ main(int argc, char *argv[]) > case 'f': > conffile = optarg; > break; > + case 's': > + sockname = optarg; > + break; > case 'v': > verbose++; > opts |= RELAYD_OPT_VERBOSE; > @@ -200,7 +205,7 @@ main(int argc, char *argv[]) > errx(1, "unknown user %s", RELAYD_USER); > > /* Configure the control socket */ > - ps->ps_csock.cs_name = RELAYD_SOCKET; > + ps->ps_csock.cs_name = sockname; > > log_init(debug, LOG_DAEMON); > log_setverbose(verbose); >