Nima GHOTBI <[email protected]> writes:

> Hi everyone
>
> In one of our projects we had to run multiple instances of ripd on
> different rdomains so I made a patch to add "-s" argument to ripd and
> ripctl to let the user change control socket path from /var/run/ripd.sock

Sounds like a valuable addition, but your patch is mangled (whitespace
issue it seems).  Please send a patch that applies.

> diff -Naur BASE/usr.sbin/ripd/control.c usr.sbin/ripd/control.c
> --- BASE/usr.sbin/ripd/control.c    2015-12-05 15:13:47.000000000 +0200
> +++ usr.sbin/ripd/control.c    2016-07-14 14:42:36.545519411 +0300
> @@ -39,7 +39,7 @@
>  void         control_close(int);
>
>  int
> -control_init(void)
> +control_init(char *path)
>  {
>      struct sockaddr_un     sun;
>      int             fd;
> @@ -53,28 +53,28 @@
>
>      bzero(&sun, sizeof(sun));
>      sun.sun_family = AF_UNIX;
> -    strlcpy(sun.sun_path, RIPD_SOCKET, sizeof(sun.sun_path));
> +    strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
>
> -    if (unlink(RIPD_SOCKET) == -1)
> +    if (unlink(path) == -1)
>          if (errno != ENOENT) {
> -            log_warn("control_init: unlink %s", RIPD_SOCKET);
> +            log_warn("control_init: unlink %s", path);
>              close(fd);
>              return (-1);
>          }
>
>      old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH);
>      if (bind(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1) {
> -        log_warn("control_init: bind: %s", RIPD_SOCKET);
> +        log_warn("control_init: bind: %s", path);
>          close(fd);
>          umask(old_umask);
>          return (-1);
>      }
>      umask(old_umask);
>
> -    if (chmod(RIPD_SOCKET, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) {
> +    if (chmod(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) {
>          log_warn("control_init: chmod");
>          close(fd);
> -        (void)unlink(RIPD_SOCKET);
> +        (void)unlink(path);
>          return (-1);
>      }
>
> @@ -101,11 +101,11 @@
>  }
>
>  void
> -control_cleanup(void)
> +control_cleanup(char *path)
>  {
>      event_del(&control_state.ev);
>      event_del(&control_state.evt);
> -    unlink(RIPD_SOCKET);
> +    unlink(path);
>  }
>
>  /* ARGSUSED */
> diff -Naur BASE/usr.sbin/ripd/control.h usr.sbin/ripd/control.h
> --- BASE/usr.sbin/ripd/control.h    2015-02-09 14:13:42.000000000 +0200
> +++ usr.sbin/ripd/control.h    2016-07-14 14:42:48.209546392 +0300
> @@ -34,11 +34,11 @@
>      struct imsgev        iev;
>  };
>
> -int    control_init(void);
> +int    control_init(char *);
>  int    control_listen(void);
>  void    control_accept(int, short, void *);
>  void    control_dispatch_imsg(int, short, void *);
>  int    control_imsg_relay(struct imsg *);
> -void    control_cleanup(void);
> +void    control_cleanup(char *);
>
>  #endif    /* _CONTROL_H_ */
> --- BASE/usr.sbin/ripd/ripd.c    2016-02-02 19:51:11.000000000 +0200
> +++ usr.sbin/ripd/ripd.c    2016-07-14 14:55:51.175415748 +0300
> @@ -70,7 +70,7 @@
>  {
>      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);
>  }
> @@ -122,15 +122,16 @@
>      int         ch;
>      int         opts = 0;
>      char        *conffile;
> +    char         *sockname;
>      size_t         len;
> -
> +    sockname = RIPD_SOCKET;
>      conffile = CONF_FILE;
>      ripd_process = PROC_MAIN;
>
>      log_init(1);    /* log to stderr until daemonized */
>      log_verbose(1);
>
> -    while ((ch = getopt(argc, argv, "cdD:f:nv")) != -1) {
> +    while ((ch = getopt(argc, argv, "cdD:f:ns:v")) != -1) {
>          switch (ch) {
>          case 'c':
>              opts |= RIPD_OPT_FORCE_DEMOTE;
> @@ -149,6 +150,9 @@
>          case 'n':
>              opts |= RIPD_OPT_NOACTION;
>              break;
> +        case 's':
> +            sockname = optarg;
> +            break;
>          case 'v':
>              if (opts & RIPD_OPT_VERBOSE)
>                  opts |= RIPD_OPT_VERBOSE2;
> @@ -182,6 +185,7 @@
>      /* parse config file */
>      if ((conf = parse_config(conffile, opts)) == NULL )
>          exit(1);
> +    conf->csock = sockname;
>
>      if (conf->opts & RIPD_OPT_NOACTION) {
>          if (conf->opts & RIPD_OPT_VERBOSE)
> @@ -287,7 +291,7 @@
>          if_del(i);
>      }
>
> -    control_cleanup();
> +    control_cleanup(conf->csock);
>      kr_shutdown();
>
>      do {
> diff -Naur BASE/usr.sbin/ripd/ripd.h usr.sbin/ripd/ripd.h
> --- BASE/usr.sbin/ripd/ripd.h    2015-09-27 20:32:36.000000000 +0300
> +++ usr.sbin/ripd/ripd.h    2016-07-14 14:46:50.582113056 +0300
> @@ -239,6 +239,7 @@
>      int             rip_socket;
>      int             redistribute;
>      u_int             rdomain;
> +    char            *csock;
>  };
>
>  /* kroute */
> diff -Naur BASE/usr.sbin/ripd/ripe.c usr.sbin/ripd/ripe.c
> --- BASE/usr.sbin/ripd/ripe.c    2015-12-05 15:13:47.000000000 +0200
> +++ usr.sbin/ripd/ripe.c    2016-07-14 14:52:29.370923477 +0300
> @@ -85,7 +85,7 @@
>      }
>
>      /* create ripd control socket outside chroot */
> -    if (control_init() == -1)
> +    if (control_init(xconf->csock) == -1)
>          fatalx("control socket setup failed");
>
>      addr.sin_family = AF_INET;
> diff -Naur BASE/usr.sbin/ripctl/ripctl.c usr.sbin/ripctl/ripctl.c
> --- BASE/usr.sbin/ripctl/ripctl.c    2015-12-05 15:13:47.000000000 +0200
> +++ usr.sbin/ripctl/ripctl.c    2016-07-14 15:10:32.053488404 +0300
> @@ -59,7 +59,7 @@
>  {
>      extern char *__progname;
>
> -    fprintf(stderr, "usage: %s command [argument ...]\n", __progname);
> +    fprintf(stderr, "usage: %s [-s socket] command [argument ...]\n",
> __progname);
>      exit(1);
>  }
>
> @@ -73,6 +73,20 @@
>      int             ctl_sock;
>      int             done = 0, verbose = 0;
>      int             n;
> +    int             ch;
> +  char            *sockname;
> +    sockname = RIPD_SOCKET;
> +
> +    while ((ch = getopt(argc, argv, "s:")) != -1) {
> +        switch (ch) {
> +        case 's':
> +            sockname = optarg;
> +            argc-= 2;
> +            argv+= 2;
> +            break;
> +        }
> +    }
> +
>
>      /* parse options */
>      if ((res = parse(argc - 1, argv + 1)) == NULL)
> @@ -84,9 +98,9 @@
>
>      bzero(&sun, sizeof(sun));
>      sun.sun_family = AF_UNIX;
> -    strlcpy(sun.sun_path, RIPD_SOCKET, sizeof(sun.sun_path));
> +    strlcpy(sun.sun_path, sockname, sizeof(sun.sun_path));
>      if (connect(ctl_sock, (struct sockaddr *)&sun, sizeof(sun)) == -1)
> -        err(1, "connect: %s", RIPD_SOCKET);
> +        err(1, "connect: %s", sockname);
>
>      if (pledge("stdio", NULL) == -1)
>          err(1, "pledge");

-- 
jca | PGP: 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to