> 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.

> 
> regards,
> 
> Giannis
> 
> Index: relayd.8
> ===================================================================
> RCS file: /cvs/src/usr.sbin/relayd/relayd.8,v
> retrieving revision 1.25
> diff -u -p -u -r1.25 relayd.8
> --- relayd.8  27 Jul 2015 14:50:58 -0000      1.25
> +++ relayd.8  22 Jun 2017 15:08: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.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/relayd/relayd.c,v
> retrieving revision 1.169
> diff -u -p -u -r1.169 relayd.c
> --- relayd.c  31 May 2017 04:14:34 -0000      1.169
> +++ relayd.c  22 Jun 2017 15:08: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);
> 
> Index: relayctl.8
> ===================================================================
> RCS file: /cvs/src/usr.sbin/relayctl/relayctl.8,v
> retrieving revision 1.32
> diff -u -p -u -r1.32 relayctl.8
> --- relayctl.8        28 Nov 2015 01:22:44 -0000      1.32
> +++ relayctl.8        22 Jun 2017 15:08:37 -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.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/relayctl/relayctl.c,v
> retrieving revision 1.57
> diff -u -p -u -r1.57 relayctl.c
> --- relayctl.c        3 Sep 2016 14:44:21 -0000       1.57
> +++ relayctl.c        22 Jun 2017 15:08:37 -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;
> +     char                    *sockname;

this can be const char *

> +
> +     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,7 @@ 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));
> +     (void)strlcpy(sun.sun_path, sockname, sizeof(sun.sun_path));

i would check for truncation here, ie, check what strlcpy returns and fail if 
sockname is too long.

>  reconnect:
>       if (connect(ctl_sock, (struct sockaddr *)&sun, sizeof(sun)) == -1) {
>               /* Keep retrying if running in monitor mode */
> @@ -121,7 +138,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)
> 

Reply via email to