$NetBSD: patch-ab,v 1.6 2013/09/10 14:15:11 joerg Exp $

--- common/ttio.c.orig	1997-02-21 23:06:09.000000000 +0000
+++ common/ttio.c
@@ -45,12 +45,20 @@ static char copyright[] =
 #include "osdep.h"
 #include "cdefs.h"
 #include "global.h"
+#include <ctype.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <syslog.h>
 #include "mcap.h"
 #include "ttio.h"
 #include <pwd.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#ifndef __sun
+#include <util.h>
+#else
+#include <sys/file.h>
+#endif
 
 static void dectl PROTO ((char *, int, char *, int, char *));
 
@@ -73,6 +81,16 @@ int ttsetup (name)
     {
       if (chown (nbuf, pw -> pw_uid, pw -> pw_gid) < 0)
 	warn ("Can't set owner on %s: %m", nbuf);
+#ifdef __NetBSD__
+      if (chmod (nbuf, 0600) < 0)
+        warn ("Can't set mode on %s: %m", nbuf);
+      revoke(nbuf);
+      if (ttyaction(nbuf, "modemd", "root"))
+        warn ("Can't ttyaction %s: %m", nbuf);
+
+      /* delay open so DTR stays down long enough to be detected */
+      usleep(100);
+#endif
     }
 
   /* Open the terminal device. */
@@ -131,20 +149,19 @@ int ttsetup (name)
   return fd;
 }
 
-void ttnormal (fd)
+void ttnormal (int fd)
 {
   NORMAL_TTY (ts);
   PUT_TTY_STATE (fd, ts);
 }
 
-void tthupcl (fd)
+void tthupcl (int fd)
 {
   HUPCL_TTY (ts);
   PUT_TTY_STATE (fd, ts);
 }
 
-void redirect_std (fd)
-     int fd;
+void redirect_std (int fd)
 {
   int i;
 
@@ -203,10 +220,8 @@ static int tteof = 0;
 
 /* Match the specified string with input from the specified tty.
    Return nonzero if input matches, zero if not. */
-ttmatch (ANSI_DECL (int) tty, ANSI_DECL (int) timeout, VA_DOTDOTDOT)
-     KandR (int tty;)
-     KandR (int timeout;)
-     va_dcl
+int
+ttmatch (int tty, int timeout, ...)
 {
   TIME entry, now, to;
   int cur, curmatch, next;
@@ -230,7 +245,7 @@ ttmatch (ANSI_DECL (int) tty, ANSI_DECL 
 	 match, try reading some more data from the tty... */
       matchID = 1;
       VA_start (list, timeout);
-      while (string = va_arg (list, char *))
+      while ((string = va_arg (list, char *)))
 	{
 	  syslog (LOG_DEBUG, "Matching against %s", string);
 	  for (cur = ttstart; cur != ttend; cur = NEXT (cur))
@@ -316,9 +331,7 @@ ttmatch (ANSI_DECL (int) tty, ANSI_DECL 
 }
 
 /* Read a connect speed from standard in... */
-ttread_connect_speed (tty, timeout)
-     int tty;
-     int timeout;
+int ttread_connect_speed (int tty, int timeout)
 {
   TIME entry, now, to;
   int status;
