mg end of buffer page down diff

2012-05-25 Thread Mark Lumsden
When you page down a document and get to the last page, mg doesn't
stop, it keeps going until the last line is at the top of the window.
This diff makes mg stop paging down when the end of the text is
visible. 

Comments/ok?

-lum
ps some whitespace for readability added. 

Index: basic.c
===
RCS file: /cvs/src/usr.bin/mg/basic.c,v
retrieving revision 1.30
diff -u -p -r1.30 basic.c
--- basic.c 4 Jun 2009 02:23:37 -   1.30
+++ basic.c 25 May 2012 07:40:33 -
@@ -266,16 +266,20 @@ forwpage(int f, int n)
n = 1;  /* if tiny window.   */
} else if (n  0)
return (backpage(f | FFRAND, -n));
+
lp = curwp-w_linep;
-   while (n--  lforw(lp) != curbp-b_headp) {
-   lp = lforw(lp);
-   }
+   while (n--)
+   if ((lp = lforw(lp)) == curbp-b_headp)
+   return(TRUE);
+
curwp-w_linep = lp;
curwp-w_rflag |= WFFULL;
+
/* if in current window, don't move dot */
-   for (n = curwp-w_ntrows; n--  lp != curbp-b_headp; lp = lforw(lp))
+   for (n = curwp-w_ntrows; n--; lp = lforw(lp))
if (lp == curwp-w_dotp)
return (TRUE);
+
/* Advance the dot the slow way, for line nos */
while (curwp-w_dotp != curwp-w_linep) {
curwp-w_dotp = lforw(curwp-w_dotp);



mg history and window relocation

2012-05-25 Thread Mark Lumsden
Move the windows section in the tutorial to a more sensible place
(next to buffers) and move the mg history into the README file which
seems a more sensible place as well.

ok?

-lum

Index: README
===
RCS file: /cvs/src/usr.bin/mg/README,v
retrieving revision 1.9
diff -u -p -r1.9 README
--- README  11 Apr 2012 17:51:10 -  1.9
+++ README  25 May 2012 10:30:31 -
@@ -40,8 +40,16 @@ People who have worked on previous versi
 
rtech!da...@sun.com Dave Brower
 
-Currently maintained in the OpenBSD src tree, with contributions from
-many others.
+Early release history:
+
+* Nov 16, 1986: First release to mod.sources
+* Mar 3, 1987: First Release (mg1a) via comp.sources.unix
+* May 26, 1988: Second release: (mg2a) via comp.sources.misc
+* Jan 26, 1992: Linux port released by Charles Hedrick. This version
+  later makes its way onto tsx-11, Infomagic, and various other Linux
+  repositories.
+* Feb 25, 2000: First import into the OpenBSD tree, where it is
+  currently maintained.
 
 --
 
Index: tutorial
===
RCS file: /cvs/src/usr.bin/mg/tutorial,v
retrieving revision 1.9
diff -u -p -r1.9 tutorial
--- tutorial7 May 2012 13:52:58 -   1.9
+++ tutorial25 May 2012 10:30:32 -
@@ -118,20 +118,6 @@ screen when you type C-g indicating that
 
 In general, when in doubt, use C-g to get out of trouble.
 
-Windows

-
-The mg editor can support several windows at the same time, each one displaying
-different text. To split a screen into two horizontal windows use C-x 2 to do
-this. To return to one window, use C-x 1 to close the other windows and only
-keep the current window.
-
- Use C-x 2 to split the screen into two windows. 
-
- Use C-x o to move from one window to the other. You can scroll up and down
-   in each window using the cursor keys or C-n and C-p keys.
-
- Use C-x 1 to restore back to one window.
 
 Inserting/Deleting Text
 ---
@@ -267,6 +253,21 @@ in the bottom of your screen. In general
 often. When you save a file, mg saves a backup of the file with a tilde (~)
 character at the end.
 
+Windows
+---
+
+The mg editor can support several windows at the same time, each one displaying
+different text. To split a screen into two horizontal windows use C-x 2 to do
+this. To return to one window, use C-x 1 to close the other windows and only
+keep the current window.
+
+ Use C-x 2 to split the screen into two windows. 
+
+ Use C-x o to move from one window to the other. You can scroll up and down
+   in each window using the cursor keys or C-n and C-p keys.
+
+ Use C-x 1 to restore back to one window.
+
 Buffers
 ---
 
@@ -334,31 +335,11 @@ information available via the mg(1) man 
 improvement, please don't hesitate to drop a message or (better still) submit
 a diff to tech@openbsd.org.
 
-History

-
-mg is a public-domain text editor. It was originally based on MicroEMACS, but
-has since moved to more closely resemble GNU Emacs while still maintaining a
-small memory footprint and fast speed. 
-
-* Nov 16, 1986: First release to mod.sources
-* Mar 3, 1987: First Release (mg1a) via comp.sources.unix
-* May 26, 1988: Second release: (mg2a) via comp.sources.misc
-* Jan 26, 1992: Linux port released by Charles Hedrick. This version
-  later makes its way onto tsx-11, Infomagic, and various other Linux
-  repositories. 
-* Feb 25, 2000: First import into the OpenBSD tree, where it is
-  currently maintained
-
-The mg editor was originally named MicroGNUEmacs. The name was changed at
-the request of Richard Stallman, as this software is entirely unrelated to
-the GNU project. 
-
 Author Info
 ---
 
 Original Author of this document: Mayukh Bose, 
-Date last updated: 2012-01-17
+Date last updated: 2012-05-25
 
 Copyright
 -



ftp synopsis

2012-05-25 Thread Jason McIntyre
the size of ftp's synopsis is making it very ugly. any objections to
shortening it? i.e. this diff is cosmetic.

jmc

Index: ftp.1
===
RCS file: /cvs/src/usr.bin/ftp/ftp.1,v
retrieving revision 1.82
diff -u -r1.82 ftp.1
--- ftp.1   30 Apr 2012 13:41:26 -  1.82
+++ ftp.1   25 May 2012 20:44:52 -
@@ -39,17 +39,17 @@
 .Sh SYNOPSIS
 .Nm ftp
 .Op Fl 46AadEegimnptVv
-.Op Fl k Ar seconds
+.Op Fl k Ar sec
 .Op Fl P Ar port
-.Op Fl r Ar seconds
-.Op Fl s Ar srcaddr
+.Op Fl r Ar sec
+.Op Fl s Ar src
 .Op Ar host Op Ar port
 .Nm ftp
 .Op Fl C
-.Op Fl o Ar output
-.Op Fl s Ar srcaddr
+.Op Fl o Ar out
+.Op Fl s Ar src
 .Sm off
-.No ftp:// Oo Ar user : password No @
+.No ftp:// Oo Ar user : pass No @
 .Oc Ar host Oo : Ar port
 .Oc No / Ar file Oo /
 .Oc
@@ -58,8 +58,8 @@
 .Nm ftp
 .Op Fl C
 .Op Fl c Ar cookie
-.Op Fl o Ar output
-.Op Fl s Ar srcaddr
+.Op Fl o Ar out
+.Op Fl s Ar src
 .Sm off
 .No http:// Ar host Oo : Ar port
 .Oc No / Ar file
@@ -68,8 +68,8 @@
 .Nm ftp
 .Op Fl C
 .Op Fl c Ar cookie
-.Op Fl o Ar output
-.Op Fl s Ar srcaddr
+.Op Fl o Ar out
+.Op Fl s Ar src
 .Sm off
 .No https:// Ar host Oo : Ar port
 .Oc No / Ar file
@@ -77,16 +77,16 @@
 .Ar ...
 .Nm ftp
 .Op Fl C
-.Op Fl o Ar output
-.Op Fl s Ar srcaddr
+.Op Fl o Ar out
+.Op Fl s Ar src
 .Sm off
 .No file: Ar file
 .Sm on
 .Ar ...
 .Nm ftp
 .Op Fl C
-.Op Fl o Ar output
-.Op Fl s Ar srcaddr
+.Op Fl o Ar out
+.Op Fl s Ar src
 .Sm off
 .Ar host : No / Ar file Oo /
 .Oc
@@ -167,11 +167,11 @@
 .It Fl i
 Turns off interactive prompting during
 multiple file transfers.
-.It Fl k Ar seconds
+.It Fl k Ar sec
 When greater than zero,
-sends a byte after each
-.Ar seconds
-period over the control connection during long transfers,
+sends a byte after each period of
+.Ar sec
+seconds over the control connection during long transfers,
 so that incorrectly configured network equipment won't
 aggressively drop it.
 The FTP protocol supports a
@@ -206,14 +206,14 @@
 will prompt for the remote machine login name (default is the user
 identity on the local machine), and, if necessary, prompt for a password
 and an account with which to log in.
-.It Fl o Ar output
+.It Fl o Ar out
 When fetching a single file or URL, save the contents in
-.Ar output .
+.Ar out .
 To make the contents go to stdout,
 use
 .Sq -
 for
-.Ar output .
+.Ar out .
 .It Fl P Ar port
 Sets the port number to
 .Ar port .
@@ -223,12 +223,13 @@
 .Nm
 now tries to use passive mode by default, falling back to active mode
 if the server does not support passive connections.
-.It Fl r Ar seconds
-Retry to connect if failed, pausing for number of
-.Ar seconds .
-.It Fl s Ar srcaddr
+.It Fl r Ar sec
+Retry to connect if failed, pausing for
+.Ar sec
+seconds.
+.It Fl s Ar src
 Use
-.Ar srcaddr
+.Ar src
 on the local machine as the source address
 of the connection.
 Only useful on systems with more than one address.
@@ -492,12 +493,12 @@
 If no argument is given,
 .Nm
 prints a list of the known commands.
-.It Ic idle Op Ar seconds
+.It Ic idle Op Ar sec
 Set the inactivity timer on the remote server to
-.Ar seconds
+.Ar sec
 seconds.
 If
-.Ar seconds
+.Ar sec
 is omitted, the current inactivity timer is printed.
 .It Ic lcd Op Ar local-directory
 Change the working directory on the local machine.
@@ -1193,12 +1194,12 @@
 .Ar newmask
 is omitted, the current umask is printed.
 .It Xo
-.Ic user Ar username
-.Op Ar password Op Ar account
+.Ic user Ar user
+.Op Ar pass Op Ar account
 .Xc
 Identify yourself to the remote FTP server.
-If the
-.Ar password
+If a password
+.Ar pass
 is not specified and the server requires it,
 .Nm
 will prompt the user for it (after disabling local echo).
@@ -1264,20 +1265,20 @@
 .Dq Classic
 .Nm
 format.
-.It ftp://[user:password@]host[:port]/file[/]
+.It ftp://[user:pass@]host[:port]/file[/]
 An FTP URL, retrieved using the FTP protocol if
 .Ev ftp_proxy
 isn't defined.
 Otherwise, transfer using HTTP via the proxy defined in
 .Ev ftp_proxy .
 If
-.Ar user : Ns Ar password Ns @
+.Ar user : Ns Ar pass Ns @
 is given and
 .Ev ftp_proxy
 isn't defined, log in as
 .Ar user
 with a password of
-.Ar password .
+.Ar pass .
 .It http://host[:port]/file
 An HTTP URL, retrieved using the HTTP protocol.
 If
@@ -1328,11 +1329,11 @@
 of
 .Ar file .
 If
-.Fl o Ar output
+.Fl o Ar out
 is specified, then
 .Ar file
 is stored as
-.Ar output .
+.Ar out .
 Otherwise, the remote name is used as the local name.
 .Sh ABORTING A FILE TRANSFER
 To abort a file transfer, use the terminal interrupt key
Index: main.c
===
RCS file: /cvs/src/usr.bin/ftp/main.c,v
retrieving revision 1.83
diff -u -r1.83 main.c
--- main.c  19 May 2012 02:04:22 -  1.83
+++ main.c  25 May 2012 20:44:52 -
@@ -758,47 +758,44 @@
 {
(void)fprintf(stderr, usage: %s 
 #ifndef SMALL
-   [-46AadEegimnptVv] [-k seconds] [-P port] 
-   [-r seconds] 

Re: Intel Atom E600 watchdog(4) support

2012-05-25 Thread Matt Dainty
* Miod Vallat m...@online.fr [2012-05-24 09:30:37]:
 We typically prefer shorter names.  tcpcib might not be such a bad name.
 
 Come on. It obviously has to be yapcib since it's yet another pcib.

Third time lucky, I've renamed the driver to tcpcib, (as much as I'd
love to call it yapcib ;-).

Theo suggested I add code to handle suspend/resume so I've done that
although I can't test it as my net6501 doesn't suspend, although the
code simply stops the watchdog if it's running at suspend time and
starts it up again come resume time. I presume that's ok?

I also documented the maximum period supported by the watchdog timer
and also made a note of the lack of driver support for any other parts
of the hardware.

Matt

--- /dev/null   Thu May 24 22:49:02 2012
+++ /usr/src/sys/dev/pci/tcpcib.c   Thu May 24 22:48:17 2012
@@ -0,0 +1,264 @@
+/* $OpenBSD$   */
+
+/*
+ * Copyright (c) 2012 Matt Dainty m...@bodgit-n-scarper.com
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Intel Atom E600 series LPC bridge also containing watchdog
+ */
+
+#include sys/param.h
+#include sys/systm.h
+#include sys/device.h
+
+#include machine/bus.h
+
+#include dev/pci/pcireg.h
+#include dev/pci/pcivar.h
+#include dev/pci/pcidevs.h
+
+#defineE600_LPC_SMBA   0x40/* SMBus Base Address */
+#defineE600_LPC_GBA0x44/* GPIO Base Address */
+#defineE600_LPC_WDTBA  0x84/* WDT Base Address */
+
+#defineE600_WDT_SIZE   64  /* I/O region size */
+#defineE600_WDT_PV10x00/* Preload Value 1 
Register */
+#defineE600_WDT_PV20x04/* Preload Value 2 
Register */
+#defineE600_WDT_RR00x0c/* Reload Register 0 */
+#defineE600_WDT_RR10x0d/* Reload Register 1 */
+#defineE600_WDT_RR1_RELOAD (1  0)/* WDT Reload Flag */
+#defineE600_WDT_RR1_TIMEOUT(1  1)/* WDT Timeout Flag */
+#defineE600_WDT_WDTCR  0x10/* WDT Configuration 
Register */
+#defineE600_WDT_WDTCR_PRE  (1  2)/* WDT Prescalar Select 
*/
+#defineE600_WDT_WDTCR_RESET(1  3)/* WDT Reset Select */
+#defineE600_WDT_WDTCR_ENABLE   (1  4)/* WDT Reset Enable */
+#defineE600_WDT_WDTCR_TIMEOUT  (1  5)/* WDT Timeout Output 
Enable */
+#defineE600_WDT_DCR0x14/* Down Counter 
Register */
+#defineE600_WDT_WDTLR  0x18/* WDT Lock Register */
+#defineE600_WDT_WDTLR_LOCK (1  0)/* Watchdog Timer Lock 
*/
+#defineE600_WDT_WDTLR_ENABLE   (1  1)/* Watchdog Timer 
Enable */
+#defineE600_WDT_WDTLR_TIMEOUT  (1  2)/* WDT Timeout 
Configuration */
+
+struct tcpcib_softc {
+   struct device sc_dev;
+
+   /* Keep track of which parts of the hardware are active */
+   int sc_active;
+#defineE600_WDT_ACTIVE (1  0)
+
+   /* Watchdog interface */
+   bus_space_tag_t sc_wdt_iot;
+   bus_space_handle_t sc_wdt_ioh;
+
+   int sc_wdt_period;
+};
+
+struct cfdriver tcpcib_cd = {
+   NULL, tcpcib, DV_DULL
+};
+
+int tcpcib_match(struct device *, void *, void *);
+voidtcpcib_attach(struct device *, struct device *, void *);
+int tcpcib_activate(struct device *, int);
+
+int tcpcib_wdt_cb(void *, int);
+
+struct cfattach tcpcib_ca = {
+   sizeof(struct tcpcib_softc), tcpcib_match, tcpcib_attach,
+   NULL, tcpcib_activate
+};
+
+/* from arch/*/pci/pcib.c */
+void   pcibattach(struct device *parent, struct device *self, void *aux);
+
+const struct pci_matchid tcpcib_devices[] = {
+   { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_E600_LPC }
+};
+
+static __inline void
+tcpcib_wdt_unlock(struct tcpcib_softc *sc)
+{
+   /* Register unlocking sequence */
+   bus_space_write_1(sc-sc_wdt_iot, sc-sc_wdt_ioh, E600_WDT_RR0, 0x80);
+   bus_space_write_1(sc-sc_wdt_iot, sc-sc_wdt_ioh, E600_WDT_RR0, 0x86);
+}
+
+static void
+tcpcib_wdt_init(struct tcpcib_softc *sc, int period)
+{
+   u_int32_t preload;
+
+   /* Set new timeout */
+   preload = (period * 3300)  15;

Re: Memory leak in snmpd(8)

2012-05-25 Thread Joel Knight
On Thu, May 24, 2012 at 8:16 AM, Kenneth R Westerback
kwesterb...@rogers.com wrote:

 Calling mib_carpget() seems a tad over complex. Wouldn't the diff
 below make it cleaner? Untested except by gcc.

 And doesn't the socket 's' leak too, or does SIOCGVH returning -1
 mean 's' was closed?

Ken,

Your diff looks good to me. I also found a few spots that leak in
pf.c. All combined I've come up with this diff. Ok?


Index: src/usr.sbin/snmpd/mib.c
===
RCS file: /cvs/src/usr.sbin/snmpd/mib.c,v
retrieving revision 1.52
diff -p -u -r1.52 mib.c
--- src/usr.sbin/snmpd/mib.c20 Mar 2012 03:01:26 -  1.52
+++ src/usr.sbin/snmpd/mib.c26 May 2012 05:14:36 -
@@ -1360,7 +1360,7 @@ intmib_carpstats(struct oid *, struct
 int mib_carpiftable(struct oid *, struct ber_oid *, struct ber_element **);
 int mib_carpifnum(struct oid *, struct ber_oid *, struct ber_element **);
 struct carpif
-   *mib_carpifget(struct carpif *, u_int);
+   *mib_carpifget(u_int);
 int mib_memiftable(struct oid *, struct ber_oid *, struct ber_element **);

 static struct oid openbsd_mib[] = {
@@ -2647,9 +2647,10 @@ mib_carpifnum(struct oid *oid, struct be
 }

 struct carpif *
-mib_carpifget(struct carpif *cif, u_int idx)
+mib_carpifget(u_int idx)
 {
struct kif  *kif;
+   struct carpif   *cif;
int  s;
struct ifreq ifr;
struct carpreq   carpr;
@@ -2689,12 +2690,17 @@ mib_carpifget(struct carpif *cif, u_int
memset((char *)carpr, 0, sizeof(carpr));
ifr.ifr_data = (caddr_t)carpr;

-   if (ioctl(s, SIOCGVH, (caddr_t)ifr) == -1)
+   if (ioctl(s, SIOCGVH, (caddr_t)ifr) == -1) {
+   close(s);
return (NULL);
+   }

-   memset(cif, 0, sizeof(struct carpif));
-   memcpy(cif-carpr, carpr, sizeof(struct carpreq));
-   memcpy(cif-kif, kif, sizeof(struct kif));
+   cif = malloc(sizeof(struct carpif));
+   if (cif != NULL) {
+   memset(cif, 0, sizeof(struct carpif));
+   memcpy(cif-carpr, carpr, sizeof(struct carpreq));
+   memcpy(cif-kif, kif, sizeof(struct kif));
+   }

close(s);

@@ -2707,16 +2713,11 @@ mib_carpiftable(struct oid *oid, struct
u_int32_tidx;
struct carpif   *cif;

-   if ((cif = malloc(sizeof(struct carpif))) == NULL)
-   return (1);
-
/* Get and verify the current row index */
idx = o-bo_id[OIDIDX_carpIfEntry];

-   if ((cif = mib_carpifget(cif, idx)) == NULL) {
-   free(cif);
+   if ((cif = mib_carpifget(idx)) == NULL)
return (1);
-   }

/* Tables need to prepend the OID on their own */
o-bo_id[OIDIDX_carpIfEntry] = cif-kif.if_index;
Index: src/usr.sbin/snmpd/pf.c
===
RCS file: /cvs/src/usr.sbin/snmpd/pf.c,v
retrieving revision 1.2
diff -p -u -r1.2 pf.c
--- src/usr.sbin/snmpd/pf.c 14 May 2012 00:02:33 -  1.2
+++ src/usr.sbin/snmpd/pf.c 26 May 2012 05:22:04 -
@@ -228,8 +228,10 @@ pfi_count(void)
struct pfi_kif  *p;
int  c = 0;

-   if (pfi_get(b, NULL))
+   if (pfi_get(b, NULL)) {
+   free(b.pfrb_caddr);
return (-1);
+   }

PFRB_FOREACH(p, b)
c++;
@@ -245,8 +247,10 @@ pfi_get_if(struct pfi_kif *rp, int idx)
struct pfi_kif  *p;
int  i = 1;

-   if (pfi_get(b, NULL))
+   if (pfi_get(b, NULL)) {
+   free(b.pfrb_caddr);
return (-1);
+   }

PFRB_FOREACH(p, b) {
if (i == idx)
@@ -290,9 +294,11 @@ pft_get_table(struct pfr_tstats *rts, in
struct pfr_tstats   *ts;
int  i = 1;

-   if (pft_get(b, NULL))
+   if (pft_get(b, NULL)) {
+   free(b.pfrb_caddr);
return (-1);
-
+   }
+
PFRB_FOREACH(ts, b) {
if (!(ts-pfrts_flags  PFR_TFLAG_ACTIVE))
continue;
@@ -319,8 +325,10 @@ pft_count(void)
struct pfr_tstats   *ts;
int  c = 0;

-   if (pft_get(b, NULL))
+   if (pft_get(b, NULL)) {
+   free(b.pfrb_caddr);
return (-1);
+   }

PFRB_FOREACH(ts, b) {
if (!(ts-pfrts_flags  PFR_TFLAG_ACTIVE))