Re: cloneable tun

2012-12-03 Thread Anders Berggren
>> dev_t dev = makedev(40, i); // from MAKEDEV :(
> 
> 40 is incorrect.  It is MD.
> 
> /usr/src/etc/etc.alpha/MAKEDEV: M tun$U c 7 $U 600
> /usr/src/etc/etc.amd64/MAKEDEV: M tun$U c 40 $U 600

Thanks, guess I'd better use system("cd /dev; sh MAKEDEV tunX");



Re: cloneable tun

2012-12-03 Thread Theo de Raadt
> dev_t dev = makedev(40, i); // from MAKEDEV :(

40 is incorrect.  It is MD.

/usr/src/etc/etc.alpha/MAKEDEV: M tun$U c 7 $U 600
/usr/src/etc/etc.amd64/MAKEDEV: M tun$U c 40 $U 600
/usr/src/etc/etc.armish/MAKEDEV:M tun$U c 33 $U 600
/usr/src/etc/etc.aviion/MAKEDEV:M tun$U c 23 $U 600
/usr/src/etc/etc.beagle/MAKEDEV:M tun$U c 33 $U 600
/usr/src/etc/etc.hp300/MAKEDEV: M tun$U c 23 $U 600
/usr/src/etc/etc.hppa/MAKEDEV:  M tun$U c 18 $U 600
/usr/src/etc/etc.hppa64/MAKEDEV:M tun$U c 18 $U 600
/usr/src/etc/etc.i386/MAKEDEV:  M tun$U c 40 $U 600
/usr/src/etc/etc.landisk/MAKEDEV:   M tun$U c 33 $U 600
/usr/src/etc/etc.loongson/MAKEDEV:  M tun$U c 13 $U 600
/usr/src/etc/etc.luna88k/MAKEDEV:   M tun$U c 23 $U 600
/usr/src/etc/etc.macppc/MAKEDEV:M tun$U c 23 $U 600
/usr/src/etc/etc.mvme68k/MAKEDEV:   M tun$U c 23 $U 600
/usr/src/etc/etc.mvme88k/MAKEDEV:   M tun$U c 23 $U 600
/usr/src/etc/etc.palm/MAKEDEV:  M tun$U c 33 $U 600
/usr/src/etc/etc.sgi/MAKEDEV:   M tun$U c 13 $U 600
/usr/src/etc/etc.socppc/MAKEDEV:M tun$U c 23 $U 600
/usr/src/etc/etc.sparc/MAKEDEV: M tun$U c 111 $U 600
/usr/src/etc/etc.sparc64/MAKEDEV:   M tun$U c 111 $U 600
/usr/src/etc/etc.vax/MAKEDEV:   M tun$U c 57 $U 600
/usr/src/etc/etc.zaurus/MAKEDEV:M tun$U c 33 $U 600



Re: cloneable tun

2012-12-03 Thread Anders Berggren
>   unit = 13;
>if ((fd = open("/dev/tun0", O_RDONLY)) == -1)
>err(1, "failed to open /dev/tun0");
>if (ioctl(fd, TUNSIFUNIT, &unit) == -1)
>err(1, "ioctl failed");

I like it. I've got a few questions from npppd and openvpn users hitting the 4 
tun limit, and think it would make more sense to to write code that dynamically 
creates tun interfaces (in C/C++ progs such as the mentioned) if you didn't 
have to use system() or something like

if (stat(node, &_stat) == 0)
continue;
dev_t dev = makedev(40, i); // from MAKEDEV :(
if (mknod(node, 0600 | S_IFCHR, dev) < 0) // from MAKEDEV :(
syslog(LOG_ERR, "mknod %s: %m", node);
chown(node, 0, 0);

but rather the ioctl example above.



tip(1)/cu(1) fix

2012-12-03 Thread Mark Kettenis
So the code doesn't check for EOF, and even has a nice fat XXX for it.
This has some nasty consequences.  If you ssh into a machine, run
cu(1), and then break the connection, cu(1) start sending the '-1'
character down the serial line like crazy.  This is especially bad
since it seems our tty subsystem hangs on closing a tty if it has any
characters in its output buffer.  This diff adds the necessary EOF
checks and calls cleanup(0) if it detects one, which will terminate
the process.

ok?


Index: tip.c
===
RCS file: /cvs/src/usr.bin/tip/tip.c,v
retrieving revision 1.53
diff -u -p -r1.53 tip.c
--- tip.c   3 Jul 2010 03:33:12 -   1.53
+++ tip.c   3 Dec 2012 22:28:39 -
@@ -296,8 +296,10 @@ tipin(void)
}
 
while (1) {
-   gch = getchar()&STRIP_PAR;
-   /* XXX does not check for EOF */
+   gch = getchar();
+   if (gch == EOF)
+   cleanup(0);
+   gch &= STRIP_PAR;
if (gch == vgetnum(ESCAPE) && bol) {
if (!noesc) {
if (!(gch = escape()))
@@ -313,8 +315,12 @@ tipin(void)
if (vgetnum(HALFDUPLEX))
printf("\r\n");
continue;
-   } else if (!cumode && gch == vgetnum(FORCE))
-   gch = getchar() & STRIP_PAR;
+   } else if (!cumode && gch == vgetnum(FORCE)) {
+   gch = getchar();
+   if (gch == EOF)
+   cleanup(0);
+   gch &= STRIP_PAR;
+   }
bol = any(gch, vgetstr(EOL));
if (vgetnum(RAISE) && islower(gch))
gch = toupper(gch);
@@ -338,8 +344,10 @@ escape(void)
esctable_t *p;
char c = vgetnum(ESCAPE);
 
-   gch = (getchar()&STRIP_PAR);
-   /* XXX does not check for EOF */
+   gch = getchar();
+   if (gch == EOF)
+   cleanup(0);
+   gch &= STRIP_PAR;
for (p = etable; p->e_char; p++)
if (p->e_char == gch) {
printf("%s", ctrl(c));



Re: mg: column-number-mode

2012-12-03 Thread Reyk Floeter
On Mon, Dec 03, 2012 at 11:59:00AM +0100, Jasper Lievisse Adriaanse wrote:
> Hi,
> 
> Some weeks ago the column number display was removed from the modeline; while
> it's totally understandable this is a horror on slower displays, it's still
> usefull on faster displays.
> 
> mg has a line-number-mode, but not a column-number-mode like Emacs has. This
> diff adds the column-number-mode, and thus partly reverting the previous 
> change.
> Column numbers are still disabled by default.
> 
> I've also removed the unconditional LINENOMODE define which is unused 
> elsewhere,
> but the linenos handling could use some more cleanup; which is for a later 
> diff.
> 
> OK?
> 

Yes, please, I was actually missing the column number. OK reyk.

> Index: def.h
> ===
> RCS file: /cvs/src/usr.bin/mg/def.h,v
> retrieving revision 1.131
> diff -p -u -r1.131 def.h
> --- def.h 27 Nov 2012 19:46:46 -  1.131
> +++ def.h 3 Dec 2012 10:53:14 -
> @@ -424,6 +424,7 @@ void  vtinit(void);
>  void vttidy(void);
>  void update(void);
>  int  linenotoggle(int, int);
> +int  colnotoggle(int, int);
>  
>  /* echo.c X */
>  void  eerase(void);
> Index: display.c
> ===
> RCS file: /cvs/src/usr.bin/mg/display.c,v
> retrieving revision 1.38
> diff -p -u -r1.38 display.c
> --- display.c 11 Nov 2012 20:40:49 -  1.38
> +++ display.c 3 Dec 2012 10:53:14 -
> @@ -101,10 +101,8 @@ struct video   blanks;   /* Blank line im
>   */
>  struct score *score; /* [NROW * NROW] */
>  
> -#ifndef LINENOMODE
> -#define LINENOMODE TRUE
> -#endif /* !LINENOMODE */
> -static intlinenos = LINENOMODE;
> +static intlinenos = TRUE;
> +static intcolnos  = FALSE;
>  
>  /* Is macro recording enabled? */
>  extern int macrodef;
> @@ -129,6 +127,19 @@ linenotoggle(int f, int n)
>   return (TRUE);
>  }
>  
> +int
> +colnotoggle(int f, int n)
> +{
> + if (f & FFARG)
> + colnos = n > 0;
> + else
> + colnos = !colnos;
> +
> + sgarbf = TRUE;
> +
> + return (TRUE);
> +}
> +
>  /*
>   * Reinit the display data structures, this is called when the terminal
>   * size changes.
> @@ -835,7 +846,12 @@ modeline(struct mgwin *wp)
>   ++n;
>  
>   if (linenos) {
> - len = snprintf(sl, sizeof(sl), "--L%d", wp->w_dotline);
> + if (colnos)
> + len = snprintf(sl, sizeof(sl), "--L%d--C%d", 
> wp->w_dotline,
> + getcolpos());
> + else
> + len = snprintf(sl, sizeof(sl), "--L%d", wp->w_dotline);
> +
>   if (len < sizeof(sl) && len != -1)
>   n += vtputs(sl);
>   }
> Index: funmap.c
> ===
> RCS file: /cvs/src/usr.bin/mg/funmap.c,v
> retrieving revision 1.43
> diff -p -u -r1.43 funmap.c
> --- funmap.c  27 Nov 2012 19:46:46 -  1.43
> +++ funmap.c  3 Dec 2012 10:53:14 -
> @@ -40,6 +40,7 @@ static struct funmap functnames[] = {
>   {capword, "capitalize-word",},
>   {changedir, "cd",},
>   {clearmark, "clear-mark",},
> + {colnotoggle, "column-number-mode",},
>   {copyregion, "copy-region-as-kill",},
>  #ifdef   REGEX
>   {cntmatchlines, "count-matches",},
> Index: mg.1
> ===
> RCS file: /cvs/src/usr.bin/mg/mg.1,v
> retrieving revision 1.72
> diff -p -u -r1.72 mg.1
> --- mg.1  27 Nov 2012 19:46:46 -  1.72
> +++ mg.1  3 Dec 2012 10:53:14 -
> @@ -414,6 +414,8 @@ upper case, and subsequent letters to lo
>  .It cd
>  Change the global working directory.
>  See also global-wd-mode.
> +.It column-number-mode
> +Show the current column number in the mode line.
>  .It copy-region-as-kill
>  Copy all of the characters in the region to the kill buffer,
>  clearing the mark afterwards.
> 
> -- 
> Cheers,
> Jasper
> 
> "Stay Hungry. Stay Foolish"



Re: rs(1) segmentation fault fix

2012-12-03 Thread Otto Moerbeek
On Mon, Dec 03, 2012 at 08:48:46PM +0200, Arto Jonsson wrote:

> Hi,
> 
> noticed this on -current (dated Dec 2) amd64:
> 
> $ who | rs
> Segmentation fault (core dumped)
> 
> $ jot -r 100 | rs 10 10
> Segmentation fault (core dumped)
> 
> I traced it to v1.10 of rs.c:
> http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/rs/rs.c.diff?r1=1.9;r2=1.10;f=h

Your fix is right, I'll commit soon, thanks,

-Otto

> 
> Index: rs.c
> ===
> RCS file: /cvs/src/usr.bin/rs/rs.c,v
> retrieving revision 1.21
> diff -u -r1.21 rs.c
> --- rs.c  4 Mar 2012 04:05:15 -   1.21
> +++ rs.c  3 Dec 2012 18:31:18 -
> @@ -336,17 +336,16 @@
>  getptrs(char **sp)
>  {
>   char **p;
> - int newsize, gap;
> + int newsize;
>  
>   newsize = allocsize * 2;
>   p = realloc(elem, newsize * sizeof(char *));
>   if (p == NULL)
>   err(1, "no memory");
>  
> - gap = p - elem;
> - elem = p;
>   allocsize = newsize;
> - sp += gap;
> + sp += p - elem;
> + elem = p;
>   endelem = elem + allocsize;
>   return(sp);
>  }



rs(1) segmentation fault fix

2012-12-03 Thread Arto Jonsson
Hi,

noticed this on -current (dated Dec 2) amd64:

$ who | rs
Segmentation fault (core dumped)

$ jot -r 100 | rs 10 10
Segmentation fault (core dumped)

I traced it to v1.10 of rs.c:
http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/rs/rs.c.diff?r1=1.9;r2=1.10;f=h

Index: rs.c
===
RCS file: /cvs/src/usr.bin/rs/rs.c,v
retrieving revision 1.21
diff -u -r1.21 rs.c
--- rs.c4 Mar 2012 04:05:15 -   1.21
+++ rs.c3 Dec 2012 18:31:18 -
@@ -336,17 +336,16 @@
 getptrs(char **sp)
 {
char **p;
-   int newsize, gap;
+   int newsize;
 
newsize = allocsize * 2;
p = realloc(elem, newsize * sizeof(char *));
if (p == NULL)
err(1, "no memory");
 
-   gap = p - elem;
-   elem = p;
allocsize = newsize;
-   sp += gap;
+   sp += p - elem;
+   elem = p;
endelem = elem + allocsize;
return(sp);
 }



Re: PMAP_NOCACHE -> PMAP_NC

2012-12-03 Thread Mark Kettenis
> Date: Mon, 3 Dec 2012 17:49:49 +0100
> From: Martin Pieuchot 
> 
> On 28/11/12(Wed) 16:49, Mark Kettenis wrote:
> > > Date: Tue, 27 Nov 2012 15:02:31 +0100
> > > From: Martin Pieuchot 
> > > 
> > > While working on drm support for macppc that makes use of non-cached
> > > memory I found that some platforms (amd64, i386, powerpc) use the MD
> > > PMAP_NOCACHE flag where others (sparc, sparc64, solbourne) use PMAP_NC
> > > for the same purpose.
> > > 
> > > Because I'd like to use this flag in the drm code and for coherency
> > > the diff below rename PMAP_NOCACHE into PMAP_NC.
> > > 
> > > Tested on macppc and amd64, ok?
> > 
> > Hi Martin,
> > 
> > These flags are not really supposed to be used in MI code.  So I don't
> > think the drm and agp code should use these flags, at least not
> > directly.  Fortunately doing so isn't really necessary, at least for
> > the agp stuff.  There we can do something like:
> 
> Following your suggestion, here's a diff that implements the
> BUS_DMA_NOCACHE flag for bus_dmamem_mmap(9) on macppc. Ok?

ok kettenis@

> Martin
> 
> Index: macppc/dma.c
> ===
> RCS file: /cvs/src/sys/arch/macppc/macppc/dma.c,v
> retrieving revision 1.36
> diff -u -p -r1.36 dma.c
> --- macppc/dma.c  30 Aug 2012 18:14:26 -  1.36
> +++ macppc/dma.c  3 Dec 2012 11:56:09 -
> @@ -522,7 +522,10 @@ paddr_t
>  _dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, off_t off,
>  int prot, int flags)
>  {
> - int i;
> + int i, pmapflags = 0;
> +
> + if (flags & BUS_DMA_NOCACHE)
> + pmapflags |= PMAP_NOCACHE;
>  
>   for (i = 0; i < nsegs; i++) {
>  #ifdef DIAGNOSTIC
> @@ -539,7 +542,7 @@ _dmamem_mmap(bus_dma_tag_t t, bus_dma_se
>   continue;
>   }
>  
> - return (segs[i].ds_addr + off);
> + return ((segs[i].ds_addr + off) | pmapflags);
>   }
>  
>   /* Page not found. */



Re: PMAP_NOCACHE -> PMAP_NC

2012-12-03 Thread Martin Pieuchot
On 28/11/12(Wed) 16:49, Mark Kettenis wrote:
> > Date: Tue, 27 Nov 2012 15:02:31 +0100
> > From: Martin Pieuchot 
> > 
> > While working on drm support for macppc that makes use of non-cached
> > memory I found that some platforms (amd64, i386, powerpc) use the MD
> > PMAP_NOCACHE flag where others (sparc, sparc64, solbourne) use PMAP_NC
> > for the same purpose.
> > 
> > Because I'd like to use this flag in the drm code and for coherency
> > the diff below rename PMAP_NOCACHE into PMAP_NC.
> > 
> > Tested on macppc and amd64, ok?
> 
> Hi Martin,
> 
> These flags are not really supposed to be used in MI code.  So I don't
> think the drm and agp code should use these flags, at least not
> directly.  Fortunately doing so isn't really necessary, at least for
> the agp stuff.  There we can do something like:

Following your suggestion, here's a diff that implements the
BUS_DMA_NOCACHE flag for bus_dmamem_mmap(9) on macppc. Ok?

Martin

Index: macppc/dma.c
===
RCS file: /cvs/src/sys/arch/macppc/macppc/dma.c,v
retrieving revision 1.36
diff -u -p -r1.36 dma.c
--- macppc/dma.c30 Aug 2012 18:14:26 -  1.36
+++ macppc/dma.c3 Dec 2012 11:56:09 -
@@ -522,7 +522,10 @@ paddr_t
 _dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, off_t off,
 int prot, int flags)
 {
-   int i;
+   int i, pmapflags = 0;
+
+   if (flags & BUS_DMA_NOCACHE)
+   pmapflags |= PMAP_NOCACHE;
 
for (i = 0; i < nsegs; i++) {
 #ifdef DIAGNOSTIC
@@ -539,7 +542,7 @@ _dmamem_mmap(bus_dma_tag_t t, bus_dma_se
continue;
}
 
-   return (segs[i].ds_addr + off);
+   return ((segs[i].ds_addr + off) | pmapflags);
}
 
/* Page not found. */



mg: column-number-mode

2012-12-03 Thread Jasper Lievisse Adriaanse
Hi,

Some weeks ago the column number display was removed from the modeline; while
it's totally understandable this is a horror on slower displays, it's still
usefull on faster displays.

mg has a line-number-mode, but not a column-number-mode like Emacs has. This
diff adds the column-number-mode, and thus partly reverting the previous change.
Column numbers are still disabled by default.

I've also removed the unconditional LINENOMODE define which is unused elsewhere,
but the linenos handling could use some more cleanup; which is for a later diff.

OK?

Index: def.h
===
RCS file: /cvs/src/usr.bin/mg/def.h,v
retrieving revision 1.131
diff -p -u -r1.131 def.h
--- def.h   27 Nov 2012 19:46:46 -  1.131
+++ def.h   3 Dec 2012 10:53:14 -
@@ -424,6 +424,7 @@ voidvtinit(void);
 void   vttidy(void);
 void   update(void);
 intlinenotoggle(int, int);
+intcolnotoggle(int, int);
 
 /* echo.c X */
 voideerase(void);
Index: display.c
===
RCS file: /cvs/src/usr.bin/mg/display.c,v
retrieving revision 1.38
diff -p -u -r1.38 display.c
--- display.c   11 Nov 2012 20:40:49 -  1.38
+++ display.c   3 Dec 2012 10:53:14 -
@@ -101,10 +101,8 @@ struct video blanks;   /* Blank line im
  */
 struct score *score;   /* [NROW * NROW] */
 
-#ifndef LINENOMODE
-#define LINENOMODE TRUE
-#endif /* !LINENOMODE */
-static int  linenos = LINENOMODE;
+static int  linenos = TRUE;
+static int  colnos  = FALSE;
 
 /* Is macro recording enabled? */
 extern int macrodef;
@@ -129,6 +127,19 @@ linenotoggle(int f, int n)
return (TRUE);
 }
 
+int
+colnotoggle(int f, int n)
+{
+   if (f & FFARG)
+   colnos = n > 0;
+   else
+   colnos = !colnos;
+
+   sgarbf = TRUE;
+
+   return (TRUE);
+}
+
 /*
  * Reinit the display data structures, this is called when the terminal
  * size changes.
@@ -835,7 +846,12 @@ modeline(struct mgwin *wp)
++n;
 
if (linenos) {
-   len = snprintf(sl, sizeof(sl), "--L%d", wp->w_dotline);
+   if (colnos)
+   len = snprintf(sl, sizeof(sl), "--L%d--C%d", 
wp->w_dotline,
+   getcolpos());
+   else
+   len = snprintf(sl, sizeof(sl), "--L%d", wp->w_dotline);
+
if (len < sizeof(sl) && len != -1)
n += vtputs(sl);
}
Index: funmap.c
===
RCS file: /cvs/src/usr.bin/mg/funmap.c,v
retrieving revision 1.43
diff -p -u -r1.43 funmap.c
--- funmap.c27 Nov 2012 19:46:46 -  1.43
+++ funmap.c3 Dec 2012 10:53:14 -
@@ -40,6 +40,7 @@ static struct funmap functnames[] = {
{capword, "capitalize-word",},
{changedir, "cd",},
{clearmark, "clear-mark",},
+   {colnotoggle, "column-number-mode",},
{copyregion, "copy-region-as-kill",},
 #ifdef REGEX
{cntmatchlines, "count-matches",},
Index: mg.1
===
RCS file: /cvs/src/usr.bin/mg/mg.1,v
retrieving revision 1.72
diff -p -u -r1.72 mg.1
--- mg.127 Nov 2012 19:46:46 -  1.72
+++ mg.13 Dec 2012 10:53:14 -
@@ -414,6 +414,8 @@ upper case, and subsequent letters to lo
 .It cd
 Change the global working directory.
 See also global-wd-mode.
+.It column-number-mode
+Show the current column number in the mode line.
 .It copy-region-as-kill
 Copy all of the characters in the region to the kill buffer,
 clearing the mark afterwards.

-- 
Cheers,
Jasper

"Stay Hungry. Stay Foolish"



Re: Problems compiling libsqlite3

2012-12-03 Thread Stuart Henderson
Run 'make includes' in /usr/src (this is part of 'make build' so a standard 
full build would work ok).

James Turner  wrote:

>I'm trying to build the latest libsqlite3 in tree and am running into a
>number of problems. First I want to make sure I'm following the correct
>build procedure.
>
>In lib/libsqlite3 I'm running
>
>make obj
>make depend
>make
>
>During make I get the following build failure on amd64:
>
>/usr/src/lib/libsqlite3/src/btree.c: In function 'sqlite3BtreeOpen':
>/usr/src/lib/libsqlite3/src/btree.c:1790: error: too many arguments to
>function 'sqlite3PagerFilename'
>/usr/src/lib/libsqlite3/src/btree.c: In function
>'sqlite3BtreeGetFilename':
>/usr/src/lib/libsqlite3/src/btree.c:8063: error: too many arguments to
>function 'sqlite3PagerFilename'
>*** Error 1 in /usr/src/lib/libsqlite3 (:37 'btree.o': @cc
>-O2 -pipe -g   -I/usr/src/lib/libsqlite3/obj
>-I/usr/src/lib/libsqlite...
>
>The problem is in pager.h, sqlite3PagerFilename's prototype hasn't been
>updated to accept a second parameter. It should be:
>
>-const char *sqlite3PagerFilename(Pager*);
>+const char *sqlite3PagerFilename(Pager*, int);
>
>With that fix the build get's a bit farther but then it fails with
>this:
>
>/usr/src/lib/libsqlite3/src/callback.c:332: error: conflicting types
>for 'sqlite3FindFunction'
>/usr/src/lib/libsqlite3/src/sqliteInt.h:2863: error: previous
>declaration of 'sqlite3FindFunction' was here
>*** Error 1 in /usr/src/lib/libsqlite3 (:37 'callback.o':
>@cc -O2 -pipe -g   -I/usr/src/lib/libsqlite3/obj
>-I/usr/src/lib/libsql...)
>
>So, I'm just wondering if anyone is able to build libsqlite3 on amd64
>or
>is it just me? Thanks.