Subject: Re: poor man's demand-dial
To: John C. Hayward <johnh@david.wheaton.edu>
From: Michael L. VanLoon -- HeadCandy.com <michaelv@HeadCandy.com>
List: current-users
Date: 03/20/1995 21:01:57
>Secondly do you happen to have the patches which will allow pppd and chat to
>open a modem line in non-blocking mode?  If you have them could you send
>them to me.

I've had several people ask for these, so I'm just sending them to the
list.  I did not write them -- I got them off current-users myself,
several months ago.  I have been running them in 1.0 for probably
close to six months, with satisfactory results.  These are diffed
against 1.0.

--- main.c.orig	Thu Jul  7 01:43:06 1994
+++ main.c	Sat Oct  1 20:46:30 1994
@@ -348,7 +348,7 @@
     /*
      * Open the serial device and set it up to be the ppp interface.
      */
-    if ((fd = open(devnam, O_RDWR /*| O_NDELAY*/)) < 0) {
+    if ((fd = open(devnam, O_RDWR | O_NDELAY)) < 0) {
 	syslog(LOG_ERR, "open(%s): %m", devnam);
 	die(1);
     }
@@ -1144,8 +1144,8 @@
     }
 
     if (pid == 0) {
-	setreuid(getuid(), getuid());
-	setregid(getgid(), getgid());
+	setuid(getuid());
+	setgid(getgid());
 	sigprocmask(SIG_SETMASK, &mask, NULL);
 	dup2(in, 0);
 	dup2(out, 1);
--- chat.c.orig	Mon May 30 04:34:47 1994
+++ chat.c	Sat Oct  1 20:47:47 1994
@@ -873,7 +873,9 @@
     {
     int status;
     char c;
+    int rounds = 0;
 
+again:
     status = read(0, &c, 1);
 
     switch (status)
@@ -886,12 +888,17 @@
 		   status);
 
 	case -1:
-	    if ((status = fcntl(0, F_GETFL, 0)) == -1)
-		sysfatal("Can't get file mode flags on stdin");
-	    else
-		if (fcntl(0, F_SETFL, status & ~FNDELAY) == -1)
-		    sysfatal("Can't set file mode flags on stdin");
-
+	    if (verbose)
+		syslog(LOG_WARNING, "get_char(): %m");
+	    if (errno == EWOULDBLOCK) {
+		if ((status = fcntl(0, F_GETFL, 0)) == -1)
+		    sysfatal("Can't get file mode flags on stdin");
+		else
+		    if (fcntl(0, F_SETFL, status & ~FNDELAY) == -1)
+			sysfatal("Can't set file mode flags on stdin");
+		if (rounds++ == 0)
+		    goto again;
+	    }
 	    return (-1);
 	}
     }


-----------------------------------------------------------------------------
  Michael L. VanLoon                                 michaelv@HeadCandy.com
       --<  Free your mind and your machine -- NetBSD free un*x  >--
     NetBSD working ports: 386+PC, Mac, Amiga, HP300, Sun3, Sun4, PC532,
                           DEC pmax (MIPS R2k/3k), DEC/AXP (Alpha)
     NetBSD ports in progress: VAX and others...
-----------------------------------------------------------------------------