Re: armv7 and unified TLBs

2016-08-02 Thread Jonathan Gray
On Tue, Aug 02, 2016 at 01:43:10PM +0200, Mark Kettenis wrote:
> > Date: Tue, 2 Aug 2016 02:02:57 +1000
> > From: Jonathan Gray 
> 
> Adding back tech@ just in case a knwoledgable person there wants to
> chime in...
> 
> > On Mon, Aug 01, 2016 at 05:10:48PM +0200, Mark Kettenis wrote:
> > > So the ARMv7 ARM says in B4.2.2:
> > > 
> > >   - on an implementation with separate data and instruction TLBs, any
> > > unified TLB operation operates on both TLBs
> > >  
> > >   - on an implementation with a unified TLB, any instruction TLB
> > > operation, and any data TLB operation, operates on the unified TLB
> > > 
> > >   - ARM deprecates use of instruction TLB operations and data TLB
> > > operations, and recommends that software always uses the unified
> > > TLB operations.
> > > 
> > > It seems that All the Cortex-A CPUs, with the exception of the
> > > Cortex-A8 have a unified TLB.  Since the non-unified TLB operations
> > > are deprecated, and using the unified TLB operations leads to some
> > > code simplifications, I think it makes sense to switch armv7 to these.
> > > This might be a slight pessimisation on Cortex-A8, although I'm not
> > > sure it will be noticable.
> > > 
> > > Thoughts?
> > > 
> > > Tested on Cortex-A9.  Would be nice if somebody could test this on
> > > Cortex-A8.
> > 
> > We could just drop the I and D specific functions like FreeBSD did?
> > 
> > /*
> >  * TLB functions.  ARMv7 does all TLB ops based on a unified TLB 
> > model
> >  * whether the hardware implements separate I+D or not, so we use 
> > the
> >  * same 'ID' functions for all 3 variations.
> >  */
> > 
> > armv7_tlb_flushID,  /* tlb_flushID  */
> > armv7_tlb_flushID_SE,   /* tlb_flushID_SE   */
> > armv7_tlb_flushID,  /* tlb_flushD   */
> > armv7_tlb_flushID_SE,   /* tlb_flushD_SE*/
> > 
> > https://lists.freebsd.org/pipermail/freebsd-arm/2014-March/007849.html
> 
> I think it makes sense to keep the distinction betwwen the ID and D
> variants for now.  The ID variants also flush the branch predictor
> wheras the D variants don't.
> 
> That raises some question about my simplifications of the armv7 pmap.
> Those replace the conditional executation of ID or D variants with
> unconditional executaion of D variants.  I think that that is still
> worth doing.  In theory there is some additional overhead for flushing
> the branch prediction.  But the elemination of the branch instructions
> will at least partly compensate for that.  And on most, if not all,
> Cortex CPUs flushing the branch predictor isn't necessary.  So on
> those we can simply change the function pointers to always use the D
> variants.  I'll do that in a fllowup diff.
> 
> So, as a first step I'd like to commit the diff below.
> 
> ok?

You seem to be missing a cpufunc.c diff, I think this is
what you meant to send?

In which case ok jsg@

Index: cpufunc.c
===
RCS file: /cvs/src/sys/arch/arm/arm/cpufunc.c,v
retrieving revision 1.42
diff -u -p -r1.42 cpufunc.c
--- cpufunc.c   31 Jul 2016 03:49:51 -  1.42
+++ cpufunc.c   2 Aug 2016 12:09:04 -
@@ -109,8 +109,8 @@ struct cpu_functions armv7_cpufuncs = {
 
armv7_tlb_flushID,  /* tlb_flushID  */
armv7_tlb_flushID_SE,   /* tlb_flushID_SE   */
-   armv7_tlb_flushI,   /* tlb_flushI   */
-   armv7_tlb_flushI_SE,/* tlb_flushI_SE*/
+   armv7_tlb_flushID,  /* tlb_flushI   */
+   armv7_tlb_flushID_SE,   /* tlb_flushI_SE*/
armv7_tlb_flushD,   /* tlb_flushD   */
armv7_tlb_flushD_SE,/* tlb_flushD_SE*/
 
Index: cpufunc_asm_armv7.S
===
RCS file: /cvs/src/sys/arch/arm/arm/cpufunc_asm_armv7.S,v
retrieving revision 1.10
diff -u -p -r1.10 cpufunc_asm_armv7.S
--- cpufunc_asm_armv7.S 25 Apr 2016 04:46:56 -  1.10
+++ cpufunc_asm_armv7.S 2 Aug 2016 12:09:04 -
@@ -45,7 +45,7 @@ ENTRY(armv7_setttb)
isb sy
 
mcr CP15_TTBR0(r0)  /* load new TTB */
-   mcr CP15_TLBIALL(r0)/* invalidate I+D TLBs */
+   mcr CP15_TLBIALL(r0)/* invalidate unified TLB */
dsb sy
isb sy
 
@@ -55,45 +55,27 @@ ENTRY(armv7_setttb)
  * TLB functions
  */
 ENTRY(armv7_tlb_flushID_SE)
-   mcr CP15_DTLBIMVA   /* flush D tlb single entry */
-   mcr CP15_ITLBIMVA   /* flush I tlb single entry */
+   mcr CP15_TLBIMVA(r0)/* flush unified tlb single entry */
mcr CP15_BPIMVA /* flush va from BP */
dsb sy
isb sy
mov pc, lr
 
-ENTRY(armv7_tlb_flushI_SE)
-   mcr CP15_ITLBIMVA   

NextThing C.H.I.P. eeprom -p output

2016-08-02 Thread Marcus Glocker
To whom is interested.


Node 0x48
name: ''
serial-number: '1625420d0402c2c0'
#address-cells: 0001
#size-cells: 0001
interrupt-parent: 0001
model: 'NextThing C.H.I.P.'
compatible: 'nextthing,chip' + 'allwinner,sun5i-r8'

Node 0xf0
name: 'chosen'
openbsd,bootduid: df1c321f.c22f665b
bootargs: 'sd0a:/bsd'
linux,stdout-path: '/soc@01c0/serial@01c28400:115200'
#address-cells: 0001
#size-cells: 0001
ranges: 
stdout-path: 'serial0:115200n8'

Node 0x1a8
name: 'framebuffer'
compatible: 'allwinner,simple-framebuffer' + 'simple-framebuffer'
allwinner,pipeline: 'de_be0-lcd0'
clocks: 0002.0001.0003.0024.0003.002c
status: 'disabled'

Node 0x250
name: 'framebuffer'
format: 'x8r8g8b8'
stride: 0b40
height: 0218
width: 0290
reg: 5fe79000.00178e00
compatible: 'allwinner,simple-framebuffer' + 'simple-framebuffer'
allwinner,pipeline: 'de_be0-lcd0-tve0'
clocks: 
0002.0001.0003.0022.0003.0024.0003.002c
status: 'okay'

Node 0x36c
name: 'aliases'
i2c0: '/soc@01c0/i2c@01c2ac00'
i2c2: '/soc@01c0/i2c@01c2b400'
serial0: '/soc@01c0/serial@01c28400'
serial1: '/soc@01c0/serial@01c28c00'

Node 0x424
name: 'memory'
device_type: 'memory'
reg: 4000.1fe6a000

Node 0x45c
name: 'cpus'
#address-cells: 0001
#size-cells: 

Node 0x488
name: 'cpu'
device_type: 'cpu'
compatible: 'arm,cortex-a8'
reg: 
clocks: 0004
clock-latency: 0003b9b0
operating-points: 
000f6180.00155cc0.000dea80.00149970.000d2f00.0013d620.00098580.00124f80.0008ca00.00124f80.00069780.00124f80
#cooling-cells: 0002
cooling-min-level: 
cooling-max-level: 0005
cpu-supply: 0005
linux,phandle: 002b
phandle: 002b

Node 0x594
name: 'clocks'
#address-cells: 0001
#size-cells: 0001
ranges: 

Node 0x5cc
name: 'dummy'
#clock-cells: 
compatible: 'fixed-clock'
clock-frequency: 
linux,phandle: 0009
phandle: 0009

Node 0x634
name: 'clk'
#clock-cells: 
compatible: 'allwinner,sun4i-a10-osc-clk'
reg: 01c20050.0004
clock-frequency: 016e3600
clock-output-names: 'osc24M'
linux,phandle: 0006
phandle: 0006

Node 0x6dc
name: 'clk'
#clock-cells: 
compatible: 'fixed-clock'
clock-frequency: 8000
clock-output-names: 'osc32k'
linux,phandle: 0007
phandle: 0007

Node 0x758
name: 'clk'
#clock-cells: 
compatible: 'allwinner,sun4i-a10-pll1-clk'
reg: 01c2.0004
clocks: 0006
clock-output-names: 'pll1'
linux,phandle: 0008
phandle: 0008

Node 0x804
name: 'clk'
#clock-cells: 0001
compatible: 'allwinner,sun5i-a13-pll2-clk'
reg: 01c20008.0008
clocks: 0006
clock-output-names: 'pll2-1x' + 'pll2-2x' + 'pll2-4x' + 'pll2-8x'
linux,phandle: 000d
phandle: 000d

Node 0x8c8
name: 'clk'
#clock-cells: 
compatible: 'allwinner,sun4i-a10-pll1-clk'
reg: 01c20018.0004
clocks: 0006
clock-output-names: 'pll4'

Node 0x954
name: 'clk'
#clock-cells: 0001
compatible: 'allwinner,sun4i-a10-pll5-clk'
reg: 01c20020.0004
clocks: 0006
clock-output-names: 'pll5_ddr' + 'pll5_other'
linux,phandle: 0002
phandle: 0002

Node 0xa0c
name: 'clk'
#clock-cells: 0001
compatible: 'allwinner,sun4i-a10-pll6-clk'
reg: 01c20028.0004
clocks: 0006
clock-output-names: 'pll6_sata' + 'pll6_other' + 'pll6'
linux,phandle: 000b
phandle: 000b

Node 0xacc
name: 'cpu'
#clock-cells: 
compatible: 'allwinner,sun4i-a10-cpu-clk'
reg: 01c20054.0004
clocks: 0007.0006.0008.0009
clock-output-names: 'cpu'
   

Re: move rusers(1) to poll(2)

2016-08-02 Thread Todd C. Miller
On Tue, 02 Aug 2016 18:51:13 +0200, Jeremie Courreges-Anglas wrote:

> Low priority as there isn't really room for fd_set overflow here, but
> I think we agree that moving to poll(2) is always a good thing.  Seems
> to work fine in a simple setup.
> 
> Not checking for POLLHUP since those are UDP sockets.

OK millert@

 - todd



move rusers(1) to poll(2)

2016-08-02 Thread Jeremie Courreges-Anglas

Low priority as there isn't really room for fd_set overflow here, but
I think we agree that moving to poll(2) is always a good thing.  Seems
to work fine in a simple setup.

Not checking for POLLHUP since those are UDP sockets.

ok?


Index: rusers.c
===
RCS file: /cvs/src/usr.bin/rusers/rusers.c,v
retrieving revision 1.38
diff -u -p -p -u -r1.38 rusers.c
--- rusers.c28 Mar 2016 11:06:09 -  1.38
+++ rusers.c1 Aug 2016 21:29:29 -
@@ -66,6 +66,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define MINIMUM(a, b)  (((a) < (b)) ? (a) : (b))
 #define MAXIMUM(a, b)  (((a) > (b)) ? (a) : (b))
@@ -486,9 +487,9 @@ allhosts(void)
AUTH *unix_auth;
size_t outlen[2];
int sock[2] = { -1, -1 };
-   int i, maxfd, rval;
+   int i, rval;
u_long xid[2], port[2];
-   fd_set *fds = NULL;
+   struct pollfd pfd[2];
struct sockaddr_in *sin, baddr;
struct rmtcallargs args;
struct rmtcallres res[2];
@@ -533,11 +534,6 @@ allhosts(void)
outlen[1] = xdr_getpos(&xdr);
xdr_destroy(&xdr);
 
-   maxfd = MAXIMUM(sock[0], sock[1]) + 1;
-   fds = calloc(howmany(maxfd, NFDBITS), sizeof(fd_mask));
-   if (fds == NULL)
-   err(1, NULL);
-
baddr.sin_len = sizeof(struct sockaddr_in);
baddr.sin_family = AF_INET;
baddr.sin_port = htons(PMAPPORT);
@@ -558,7 +554,7 @@ allhosts(void)
 * a version 3 broadcast.  On odd ones we send a version 2
 * broadcast.  This should give version 3 replies enough
 * of an 'edge' over the old version 2 ones in most cases.
-* We select() waiting for replies for 5 seconds in between
+* We poll() waiting for replies for 5 seconds in between
 * each broadcast.
 */
for (i = 0; i < 6; i++) {
@@ -587,28 +583,30 @@ allhosts(void)
}
 
/*
-* We stay in the select loop for ~5 seconds
+* We stay in the poll loop for ~5 seconds
 */
timeout.it_value.tv_sec = 5;
timeout.it_value.tv_usec = 0;
while (timerisset(&timeout.it_value)) {
-   FD_SET(sock[0], fds);
-   FD_SET(sock[1], fds);
+   pfd[0].fd = sock[0];
+   pfd[0].events = POLLIN;
+   pfd[1].fd = sock[1];
+   pfd[1].events = POLLIN;
setitimer(ITIMER_REAL, &timeout, NULL);
-   rval = select(maxfd, fds, NULL, NULL, NULL);
+   rval = poll(pfd, 2, 0);
setitimer(ITIMER_REAL, NULL, &timeout);
if (rval == -1) {
if (errno == EINTR)
break;
-   err(1, "select");   /* shouldn't happen */
+   err(1, "poll"); /* shouldn't happen */
}
-   if (FD_ISSET(sock[1], fds)) {
+   if (pfd[1].revents & POLLIN) {
stat = get_reply(sock[1], (in_port_t)port[1],
xid[1], &msg[1], &res[1], rusers_reply_3);
if (stat != RPC_SUCCESS)
goto cleanup;
}
-   if (FD_ISSET(sock[0], fds)) {
+   if (pfd[0].revents & POLLIN) {
stat = get_reply(sock[0], (in_port_t)port[0],
xid[0], &msg[0], &res[0], rusers_reply);
if (stat != RPC_SUCCESS)
@@ -619,7 +617,6 @@ allhosts(void)
 cleanup:
if (ifap != NULL)
freeifaddrs(ifap);
-   free(fds);
if (sock[0] >= 0)
(void)close(sock[0]);
if (sock[1] >= 0)

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



Re: read(2) on directories

2016-08-02 Thread Todd C. Miller
On Tue, 02 Aug 2016 18:42:43 +0200, Jeremie Courreges-Anglas wrote:

> So I think that we agree that EISDIR is more useful, and seems safe from
> a portability POV.   I've built base and x sets on i386, and ajacoutot
> ran the ports bulk builds.  The two offenders in the ports tree were due
> to an unrelated glitch in base libtool which has since been fixed.

OK millert@

 - todd



Re: read(2) on directories

2016-08-02 Thread Jeremie Courreges-Anglas
"Todd C. Miller"  writes:

> From source inspection, Net and Free appear to allow read(2) of
> dirs to succeed.  However, since Linux, Mac OS X and Solaris have
> the EISDIR behavior I think it is probably safe from a portability
> standpoint.
>
> We're long past the days when opendir(3)/readdir(3) used read(2)...
>
> HP-UX and AIX still allow reads of directories but no one cares
> about them ;-)

So I think that we agree that EISDIR is more useful, and seems safe from
a portability POV.   I've built base and x sets on i386, and ajacoutot
ran the ports bulk builds.  The two offenders in the ports tree were due
to an unrelated glitch in base libtool which has since been fixed.

ok?


Index: lib/libc/sys/read.2
===
RCS file: /cvs/src/lib/libc/sys/read.2,v
retrieving revision 1.35
diff -u -p -r1.35 read.2
--- lib/libc/sys/read.2 5 Feb 2015 02:33:09 -   1.35
+++ lib/libc/sys/read.2 9 Jul 2016 17:20:39 -
@@ -152,13 +152,15 @@ is not a valid file or socket descriptor
 Part of
 .Fa buf
 points outside the process's allocated address space.
-.It Bq Er EIO
-An I/O error occurred while reading from the file system.
 .It Bq Er EINTR
 A read from a slow device
 (i.e. one that might block for an arbitrary amount of time)
 was interrupted by the delivery of a signal
 before any data arrived.
+.It Bq Er EIO
+An I/O error occurred while reading from the file system.
+.It Bq Er EISDIR
+The underlying file is a directory.
 .El
 .Pp
 In addition,
Index: sys/kern/vfs_vnops.c
===
RCS file: /cvs/src/sys/kern/vfs_vnops.c,v
retrieving revision 1.85
diff -u -p -r1.85 vfs_vnops.c
--- sys/kern/vfs_vnops.c19 Jun 2016 11:54:33 -  1.85
+++ sys/kern/vfs_vnops.c9 Jul 2016 17:20:39 -
@@ -336,11 +336,13 @@ vn_read(struct file *fp, off_t *poff, st
if (vp->v_type != VCHR && count > LLONG_MAX - *poff)
return (EINVAL);
 
+   if (vp->v_type == VDIR)
+   return (EISDIR);
+
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
uio->uio_offset = *poff;
-   if (vp->v_type != VDIR)
-   error = VOP_READ(vp, uio,
-   (fp->f_flag & FNONBLOCK) ? IO_NDELAY : 0, cred);
+   error = VOP_READ(vp, uio, (fp->f_flag & FNONBLOCK) ? IO_NDELAY : 0,
+   cred);
*poff += count - uio->uio_resid;
VOP_UNLOCK(vp, p);
return (error);


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



Re: confpars.c patch

2016-08-02 Thread Jeremie Courreges-Anglas
Edgar Pettijohn  writes:

> Sent from my iPhone
>
>> On Aug 2, 2016, at 7:00 AM, Jeremie Courreges-Anglas  wrote:
>> 
>> Edgar Pettijohn  writes:
>> 
>>> I'm not sure if this was intentional or not, but here is a small diff
>>> for usr.sbin/dhcpd/confpars.c.
>> 
>> K&R vs ANSI function definitions.  That file contains other occurrences.
>> 
>> -- 
>> jca | PGP: 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE
>
> Is there any interest in changing them? If so I'll dig through and find them.

I don't lurk often in dhcpd code, but I'd say that this is low priority;
also mechanical diffs like this can conflict with wip from other
developers.  Maybe krw@ will pick it up?

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



Re: Alternative control socket location in ripd

2016-08-02 Thread Jeremie Courreges-Anglas

Committed, thanks.

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



Re: Alternative control socket location in ripd

2016-08-02 Thread Sebastian Benoit
reads ok benno@

Jeremie Courreges-Anglas(j...@wxcvbn.org) on 2016.08.02 13:48:11 +0200:
> Nima GHOTBI  writes:
> 
> > please try the attachments
> >
> > On Sun, Jul 31, 2016 at 7:27 PM, Jeremie Courreges-Anglas 
> > wrote:
> >
> >> Nima GHOTBI  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
> 
> Here's an updated diff that fixes whitespace and tries to match ospfd
> a bit more closely.
> 
> Comments / oks?
> 
> 
> Index: usr.sbin/ripd/control.c
> ===
> RCS file: /cvs/src/usr.sbin/ripd/control.c,v
> retrieving revision 1.22
> diff -u -p -r1.22 control.c
> --- usr.sbin/ripd/control.c   5 Dec 2015 13:13:47 -   1.22
> +++ usr.sbin/ripd/control.c   2 Aug 2016 11:35:57 -
> @@ -39,7 +39,7 @@ struct ctl_conn *control_connbypid(pid_t
>  void  control_close(int);
>  
>  int
> -control_init(void)
> +control_init(char *path)
>  {
>   struct sockaddr_un   sun;
>   int  fd;
> @@ -53,28 +53,28 @@ control_init(void)
>  
>   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 @@ control_listen(void)
>  }
>  
>  void
> -control_cleanup(void)
> +control_cleanup(char *path)
>  {
>   event_del(&control_state.ev);
>   event_del(&control_state.evt);
> - unlink(RIPD_SOCKET);
> + unlink(path);
>  }
>  
>  /* ARGSUSED */
> Index: usr.sbin/ripd/control.h
> ===
> RCS file: /cvs/src/usr.sbin/ripd/control.h,v
> retrieving revision 1.4
> diff -u -p -r1.4 control.h
> --- usr.sbin/ripd/control.h   9 Feb 2015 12:13:42 -   1.4
> +++ usr.sbin/ripd/control.h   2 Aug 2016 11:34:44 -
> @@ -34,11 +34,11 @@ struct ctl_conn {
>   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_ */
> Index: usr.sbin/ripd/ripd.c
> ===
> RCS file: /cvs/src/usr.sbin/ripd/ripd.c,v
> retrieving revision 1.27
> diff -u -p -r1.27 ripd.c
> --- usr.sbin/ripd/ripd.c  2 Feb 2016 17:51:11 -   1.27
> +++ usr.sbin/ripd/ripd.c  2 Aug 2016 11:44:24 -
> @@ -70,7 +70,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);
>  }
> @@ -122,15 +123,17 @@ main(int argc, char *argv[])
>   int  ch;
>   int  opts = 0;
>   char*conffile;
> + char*sockname;
>   size_t   len;
>  
>   conffile = CONF_FILE;
>   ripd_process = PROC_MAIN;
> + sockname = RIPD_SOCKET;
>  
>   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 +152,9 @@ main(int argc, char *argv[])
>   case 'n':
>   opts |= RIPD_OPT_NOACTION;
>   break;
> + case '

Re: quiet legacy drivers on amd64

2016-08-02 Thread joshua stein
On Tue, 02 Aug 2016 at 12:30:51 +0200, Joerg Jung wrote:
> 
> > Am 01.08.2016 um 23:14 schrieb joshua stein :
> > 
> > are these complaints really helpful on modern machines?
> 
> Can't speak for clock. But I tend to not like this for nvram.
> IMHO, even with recent HW this is a valid concern and reminder
> that someone should handle setting of the nvram options correctly.

Who is that someone, and what nvram options are they supposed to
set?

jcs@cvs:~> grep 'nvram: invalid checksum' /var/log/dmesglog* | wc -l
 308

jcs@cvs:~> grep 'clock: unknown CMOS layout' /var/log/dmesglog* | wc -l
 362



Re: Alternative control socket location in ripd

2016-08-02 Thread Claudio Jeker
On Tue, Aug 02, 2016 at 01:48:11PM +0200, Jeremie Courreges-Anglas wrote:
> Nima GHOTBI  writes:
> 
> > please try the attachments
> >
> > On Sun, Jul 31, 2016 at 7:27 PM, Jeremie Courreges-Anglas 
> > wrote:
> >
> >> Nima GHOTBI  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
> 
> Here's an updated diff that fixes whitespace and tries to match ospfd
> a bit more closely.
> 
> Comments / oks?
> 

Reads good to me. I think this is a worth addition to ripd.

> 
> Index: usr.sbin/ripd/control.c
> ===
> RCS file: /cvs/src/usr.sbin/ripd/control.c,v
> retrieving revision 1.22
> diff -u -p -r1.22 control.c
> --- usr.sbin/ripd/control.c   5 Dec 2015 13:13:47 -   1.22
> +++ usr.sbin/ripd/control.c   2 Aug 2016 11:35:57 -
> @@ -39,7 +39,7 @@ struct ctl_conn *control_connbypid(pid_t
>  void  control_close(int);
>  
>  int
> -control_init(void)
> +control_init(char *path)
>  {
>   struct sockaddr_un   sun;
>   int  fd;
> @@ -53,28 +53,28 @@ control_init(void)
>  
>   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 @@ control_listen(void)
>  }
>  
>  void
> -control_cleanup(void)
> +control_cleanup(char *path)
>  {
>   event_del(&control_state.ev);
>   event_del(&control_state.evt);
> - unlink(RIPD_SOCKET);
> + unlink(path);
>  }
>  
>  /* ARGSUSED */
> Index: usr.sbin/ripd/control.h
> ===
> RCS file: /cvs/src/usr.sbin/ripd/control.h,v
> retrieving revision 1.4
> diff -u -p -r1.4 control.h
> --- usr.sbin/ripd/control.h   9 Feb 2015 12:13:42 -   1.4
> +++ usr.sbin/ripd/control.h   2 Aug 2016 11:34:44 -
> @@ -34,11 +34,11 @@ struct ctl_conn {
>   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_ */
> Index: usr.sbin/ripd/ripd.c
> ===
> RCS file: /cvs/src/usr.sbin/ripd/ripd.c,v
> retrieving revision 1.27
> diff -u -p -r1.27 ripd.c
> --- usr.sbin/ripd/ripd.c  2 Feb 2016 17:51:11 -   1.27
> +++ usr.sbin/ripd/ripd.c  2 Aug 2016 11:44:24 -
> @@ -70,7 +70,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);
>  }
> @@ -122,15 +123,17 @@ main(int argc, char *argv[])
>   int  ch;
>   int  opts = 0;
>   char*conffile;
> + char*sockname;
>   size_t   len;
>  
>   conffile = CONF_FILE;
>   ripd_process = PROC_MAIN;
> + sockname = RIPD_SOCKET;
>  
>   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 +152,9 @@ main(int argc, char *argv[])
>   case 'n':
>   opts |= RIPD_OPT_NOACTION;
> 

Re: confpars.c patch

2016-08-02 Thread Edgar Pettijohn


Sent from my iPhone

> On Aug 2, 2016, at 7:00 AM, Jeremie Courreges-Anglas  wrote:
> 
> Edgar Pettijohn  writes:
> 
>> I'm not sure if this was intentional or not, but here is a small diff
>> for usr.sbin/dhcpd/confpars.c.
> 
> K&R vs ANSI function definitions.  That file contains other occurrences.
> 
> -- 
> jca | PGP: 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Is there any interest in changing them? If so I'll dig through and find them.


Re: confpars.c patch

2016-08-02 Thread Jeremie Courreges-Anglas
Edgar Pettijohn  writes:

> I'm not sure if this was intentional or not, but here is a small diff
> for usr.sbin/dhcpd/confpars.c.

K&R vs ANSI function definitions.  That file contains other occurrences.

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



Re: libtool -bindir support

2016-08-02 Thread Jeremie Courreges-Anglas
Marc Espie  writes:

> On Mon, Aug 01, 2016 at 01:58:24PM +0200, Jeremie Courreges-Anglas wrote:
>> j...@wxcvbn.org (Jeremie Courreges-Anglas) writes:
>> 
>> > +cc espie and jasper
>> >
>> > Antoine Jacoutot  writes:
>> >
>> >> On Sun, Jul 31, 2016 at 07:21:39PM +0200, Antoine Jacoutot wrote:
>> >>> On July 31, 2016 7:14:21 PM GMT+02:00, j...@wxcvbn.org wrote:
>> >>> >
>> >>> >Making read(2) return EISDIR for directories breaks two ports, both
>> >>> >because they use libtool -bindir.  cc(1) gets executed with an unknown
>> >>> >option, -bindir, and a path such as /usr/local/bin, which then gets
>> >>> >passed to ld(1).  ld(1) copes with read(2) returning 0, not with
>> >>> >EISDIR.
>> >>> >Thanks to Antoine who ran the bulk builds that exposed this problem.
>> >>> >
>> >>> >-bindir support is meaningless on OpenBSD so handling that option
>> >>> >should
>> >>> >be easy.  The problem is that I don't know how to implement it in
>> >>> >libtool(1).  GNU libtool recognizes -bindir among cc flags, while our
>> >>> >version seems to only handle options passed right after argv[0].
>> >>> >
>> >>> >I plan to work around that problem by using GNU libtool for the ports
>> >>> >mentioned above, but someone else might want to poke at libtool(1)
>> >>> >internals. :)
>> >>> >
>> >>> >-- 
>> >>> >jca | PGP: 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524
>> >>> >E7EE
>> >>> 
>> >>> I can have a look at it during g2k16 if no one beats me to it.
>> >>> -- 
>> >>> Antoine
>> >>
>> >> Hi Jeremie.
>> >>
>> >> This seems to do the trick for me:
>> >
>> > Thanks for looking at it.  Yup, that works, but I think I know
>> > understand why I got confused first.
>> >
>> > -bindir is just one option among others that should be recognized and
>> > ignored in *link* mode.  The following diff does just that, I think it
>> > fits better in the existing code.  I can successfully build
>> > devel/libiscsi, -bindir /usr/local/bin doesn't get passed to cc(1).
>> >
>> > Thoughts?
>> >
>> >
>> > Index: Link.pm
>> > ===
>> > RCS file: /cvs/src/usr.bin/libtool/LT/Mode/Link.pm,v
>> > retrieving revision 1.31
>> > diff -u -p -p -u -r1.31 Link.pm
>> > --- Link.pm27 Apr 2016 09:50:57 -  1.31
>> > +++ Link.pm1 Aug 2016 11:36:31 -
>> > @@ -127,6 +127,7 @@ sub run
>> >'all-static',
>> >'allow-undefined', # we don't care about THAT one
>> >'avoid-version',
>> > +  'bindir:',
>> >'dlopen:',
>> >'dlpreopen:',
>> >'export-dynamic',
>> > @@ -152,7 +153,7 @@ sub run
>> >'version-info:',
>> >'version-number:');
>> >  
>> > -  # XXX options ignored: dlopen, dlpreopen, no-fast-install,
>> > +  # XXX options ignored: bindir, dlopen, dlpreopen, no-fast-install,
>> >#   no-install, no-undefined, precious-files-regex,
>> >#   shrext, thread-safe, prefer-pic, prefer-non-pic
>> 
>> I'm wondering about the second hunk: is this a mix of options that we
>> don't support on purpose and of options that could be useful?
>> (eg. -no-undefined.)  So is the second hunk of this diff desirable?
>> 
> The main thing about that diff is that it has to go into a successful
> bulk.

It did, thanks to Antoine, no breakage.  I already got an ok from
Antoine.  Objections / ok?

> As for ignored options, it's informative. It tells us we ignore those
> options.   Which ones should actually be supported is another story.

Fine with me.

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



Re: Alternative control socket location in ripd

2016-08-02 Thread Jeremie Courreges-Anglas
Nima GHOTBI  writes:

> please try the attachments
>
> On Sun, Jul 31, 2016 at 7:27 PM, Jeremie Courreges-Anglas 
> wrote:
>
>> Nima GHOTBI  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

Here's an updated diff that fixes whitespace and tries to match ospfd
a bit more closely.

Comments / oks?


Index: usr.sbin/ripd/control.c
===
RCS file: /cvs/src/usr.sbin/ripd/control.c,v
retrieving revision 1.22
diff -u -p -r1.22 control.c
--- usr.sbin/ripd/control.c 5 Dec 2015 13:13:47 -   1.22
+++ usr.sbin/ripd/control.c 2 Aug 2016 11:35:57 -
@@ -39,7 +39,7 @@ struct ctl_conn   *control_connbypid(pid_t
 voidcontrol_close(int);
 
 int
-control_init(void)
+control_init(char *path)
 {
struct sockaddr_un   sun;
int  fd;
@@ -53,28 +53,28 @@ control_init(void)
 
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 @@ control_listen(void)
 }
 
 void
-control_cleanup(void)
+control_cleanup(char *path)
 {
event_del(&control_state.ev);
event_del(&control_state.evt);
-   unlink(RIPD_SOCKET);
+   unlink(path);
 }
 
 /* ARGSUSED */
Index: usr.sbin/ripd/control.h
===
RCS file: /cvs/src/usr.sbin/ripd/control.h,v
retrieving revision 1.4
diff -u -p -r1.4 control.h
--- usr.sbin/ripd/control.h 9 Feb 2015 12:13:42 -   1.4
+++ usr.sbin/ripd/control.h 2 Aug 2016 11:34:44 -
@@ -34,11 +34,11 @@ struct ctl_conn {
struct imsgev   iev;
 };
 
-intcontrol_init(void);
+intcontrol_init(char *);
 intcontrol_listen(void);
 void   control_accept(int, short, void *);
 void   control_dispatch_imsg(int, short, void *);
 intcontrol_imsg_relay(struct imsg *);
-void   control_cleanup(void);
+void   control_cleanup(char *);
 
 #endif /* _CONTROL_H_ */
Index: usr.sbin/ripd/ripd.c
===
RCS file: /cvs/src/usr.sbin/ripd/ripd.c,v
retrieving revision 1.27
diff -u -p -r1.27 ripd.c
--- usr.sbin/ripd/ripd.c2 Feb 2016 17:51:11 -   1.27
+++ usr.sbin/ripd/ripd.c2 Aug 2016 11:44:24 -
@@ -70,7 +70,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);
 }
@@ -122,15 +123,17 @@ main(int argc, char *argv[])
int  ch;
int  opts = 0;
char*conffile;
+   char*sockname;
size_t   len;
 
conffile = CONF_FILE;
ripd_process = PROC_MAIN;
+   sockname = RIPD_SOCKET;
 
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 +152,9 @@ main(int argc, char *argv[])
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 +188,7 @@ m

Re: armv7 and unified TLBs

2016-08-02 Thread Mark Kettenis
> Date: Tue, 2 Aug 2016 02:02:57 +1000
> From: Jonathan Gray 

Adding back tech@ just in case a knwoledgable person there wants to
chime in...

> On Mon, Aug 01, 2016 at 05:10:48PM +0200, Mark Kettenis wrote:
> > So the ARMv7 ARM says in B4.2.2:
> > 
> >   - on an implementation with separate data and instruction TLBs, any
> > unified TLB operation operates on both TLBs
> >  
> >   - on an implementation with a unified TLB, any instruction TLB
> > operation, and any data TLB operation, operates on the unified TLB
> > 
> >   - ARM deprecates use of instruction TLB operations and data TLB
> > operations, and recommends that software always uses the unified
> > TLB operations.
> > 
> > It seems that All the Cortex-A CPUs, with the exception of the
> > Cortex-A8 have a unified TLB.  Since the non-unified TLB operations
> > are deprecated, and using the unified TLB operations leads to some
> > code simplifications, I think it makes sense to switch armv7 to these.
> > This might be a slight pessimisation on Cortex-A8, although I'm not
> > sure it will be noticable.
> > 
> > Thoughts?
> > 
> > Tested on Cortex-A9.  Would be nice if somebody could test this on
> > Cortex-A8.
> 
> We could just drop the I and D specific functions like FreeBSD did?
> 
> /*
>  * TLB functions.  ARMv7 does all TLB ops based on a unified TLB model
>  * whether the hardware implements separate I+D or not, so we use the
>  * same 'ID' functions for all 3 variations.
>  */
> 
> armv7_tlb_flushID,  /* tlb_flushID  */
> armv7_tlb_flushID_SE,   /* tlb_flushID_SE   */
> armv7_tlb_flushID,  /* tlb_flushD   */
> armv7_tlb_flushID_SE,   /* tlb_flushD_SE*/
> 
> https://lists.freebsd.org/pipermail/freebsd-arm/2014-March/007849.html

I think it makes sense to keep the distinction betwwen the ID and D
variants for now.  The ID variants also flush the branch predictor
wheras the D variants don't.

That raises some question about my simplifications of the armv7 pmap.
Those replace the conditional executation of ID or D variants with
unconditional executaion of D variants.  I think that that is still
worth doing.  In theory there is some additional overhead for flushing
the branch prediction.  But the elemination of the branch instructions
will at least partly compensate for that.  And on most, if not all,
Cortex CPUs flushing the branch predictor isn't necessary.  So on
those we can simply change the function pointers to always use the D
variants.  I'll do that in a fllowup diff.

So, as a first step I'd like to commit the diff below.

ok?


Index: cpufunc_asm_armv7.S
===
RCS file: /cvs/src/sys/arch/arm/arm/cpufunc_asm_armv7.S,v
retrieving revision 1.10
diff -u -p -r1.10 cpufunc_asm_armv7.S
--- cpufunc_asm_armv7.S 25 Apr 2016 04:46:56 -  1.10
+++ cpufunc_asm_armv7.S 2 Aug 2016 11:26:38 -
@@ -45,7 +45,7 @@ ENTRY(armv7_setttb)
isb sy
 
mcr CP15_TTBR0(r0)  /* load new TTB */
-   mcr CP15_TLBIALL(r0)/* invalidate I+D TLBs */
+   mcr CP15_TLBIALL(r0)/* invalidate unified TLB */
dsb sy
isb sy
 
@@ -55,45 +55,27 @@ ENTRY(armv7_setttb)
  * TLB functions
  */
 ENTRY(armv7_tlb_flushID_SE)
-   mcr CP15_DTLBIMVA   /* flush D tlb single entry */
-   mcr CP15_ITLBIMVA   /* flush I tlb single entry */
+   mcr CP15_TLBIMVA(r0)/* flush unified tlb single entry */
mcr CP15_BPIMVA /* flush va from BP */
dsb sy
isb sy
mov pc, lr
 
-ENTRY(armv7_tlb_flushI_SE)
-   mcr CP15_ITLBIMVA   /* flush I tlb single entry */
-   mcr CP15_BPIMVA /* flush va from BP */
-   dsb sy
-   isb sy
-   mov pc, lr
-
-/*
- * TLB functions
- */
 ENTRY(armv7_tlb_flushID)
-   mcr CP15_TLBIALL(r0)/* flush I+D tlb */
+   mcr CP15_TLBIALL(r0)/* flush unified tlb */
mcr CP15_BPIALL /* Flush BP cache */
dsb sy
isb sy
mov pc, lr
 
-ENTRY(armv7_tlb_flushI)
-   mcr CP15_ITLBIALL   /* flush I tlb */
-   mcr CP15_BPIALL /* Flush BP cache */
+ENTRY(armv7_tlb_flushD_SE)
+   mcr CP15_TLBIMVA(r0)/* flush unified tlb single entry */
dsb sy
isb sy
mov pc, lr
 
 ENTRY(armv7_tlb_flushD)
-   mcr CP15_DTLBIALL   /* flush D tlb */
-   dsb sy
-   isb sy
-   mov pc, lr
-
-ENTRY(armv7_tlb_flushD_SE)
-   mcr CP15_DTLBIMVA   /* flush D tlb single entry */
+   mcr CP15_TLBIALL(r0)/* flush unified tlb */
dsb sy
isb sy
mov pc, lr
@@ -251,7 +233,7 @@ ENTRY(armv7_cont

Re: quiet legacy drivers on amd64

2016-08-02 Thread Joerg Jung

> Am 01.08.2016 um 23:14 schrieb joshua stein :
> 
> are these complaints really helpful on modern machines?

Can't speak for clock. But I tend to not like this for nvram.
IMHO, even with recent HW this is a valid concern and reminder
that someone should handle setting of the nvram options correctly.

> Index: arch/amd64/amd64/nvram.c
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/nvram.c,v
> retrieving revision 1.6
> diff -u -p -u -p -r1.6 nvram.c
> --- arch/amd64/amd64/nvram.c6 Mar 2016 22:41:24 -1.6
> +++ arch/amd64/amd64/nvram.c1 Aug 2016 21:13:09 -
> @@ -64,8 +64,11 @@ nvramattach(int num)
>printf("nvram: initialized\n");
> #endif
>nvram_initialized = 1;
> -} else
> +}
> +#ifdef NVRAM_DEBUG
> +else
>printf("nvram: invalid checksum\n");
> +#endif
> }
> 
> int
> Index: arch/amd64/isa/clock.c
> ===
> RCS file: /cvs/src/sys/arch/amd64/isa/clock.c,v
> retrieving revision 1.22
> diff -u -p -u -p -r1.22 clock.c
> --- arch/amd64/isa/clock.c14 Mar 2015 03:38:46 -1.22
> +++ arch/amd64/isa/clock.c1 Aug 2016 21:13:09 -
> @@ -428,7 +428,7 @@ clock_expandyear(int clockyear)
>cmoscentury = 0;
>splx(s);
>if (!cmoscentury) {
> -#ifdef DIAGNOSTIC
> +#ifdef DEBUG_CLOCK
>printf("clock: unknown CMOS layout\n");
> #endif
>return (clockyear);
> 



Re: Alternative control socket location in ripd

2016-08-02 Thread Nima GHOTBI
please try the attachments

On Sun, Jul 31, 2016 at 7:27 PM, Jeremie Courreges-Anglas 
wrote:

> Nima GHOTBI  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.c2015-12-05 15:13:47.0 +0200
> > +++ usr.sbin/ripd/control.c2016-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.h2015-02-09 14:13:42.0 +0200
> > +++ usr.sbin/ripd/control.h2016-07-14 14:42:48.209546392 +0300
> > @@ -34,11 +34,11 @@
> >  struct imsgeviev;
> >  };
> >
> > -intcontrol_init(void);
> > +intcontrol_init(char *);
> >  intcontrol_listen(void);
> >  voidcontrol_accept(int, short, void *);
> >  voidcontrol_dispatch_imsg(int, short, void *);
> >  intcontrol_imsg_relay(struct imsg *);
> > -voidcontrol_cleanup(void);
> > +voidcontrol_cleanup(char *);
> >
> >  #endif/* _CONTROL_H_ */
> > --- BASE/usr.sbin/ripd/ripd.c2016-02-02 19:51:11.0 +0200
> > +++ usr.sbin/ripd/ripd.c2016-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.h2015-09-27 20:32:36.0 +0300