Subject: Fix for DG/UX "Resource unavailable" bug in 3.92

From: [email-masked] (Ken Weaverling)
Date: 2 Apr 1996 17:37:53 -0500

The new rev of Pine doesn't work on m88k implementations of DG/UX when
accessing remote folders or remote news.   The problem is in new code
to allow a timeout value for tcp open functions in tcp_unix.c in the
c-client directory.

The problem is really with DG/UX and its bogus attempt to remain 
compatible with past brokeness.   From the man page for select()....

       EAGAIN         The socket is non-blocking and the connection cannot
                      be completed immediately.  This errno is returned on
                      the 88K platform only, other platforms return
                      EINPROGRESS.
 
       EINPROGRESS    The socket is non-blocking and the connection cannot
                      be completed immediately. The 88K platform returns
                      EAGAIN instead of EINPROGRESS.  EINPROGRESS is the BSD
                      de-facto standard errno. EAGAIN is maintined on the
                      88K platform for application backward compability.
 
The problem at about line 180 in tcp_unix.c is that it is looping on a
non-blocking call to connect() and failing because DG/UX is returning 
EAGAIN instead of EINPROGRESS.  The error message for EAGAIN translates
to "Resource temporarily unavailable".  The fix is to add a case statement
for EAGAIN to the code.  For example, in tcp_unix.c at line 180:

  while ((i = connect (sock,(struct sockaddr *) &sin,sizeof (sin))) < 0 &&
         errno == EINTR);
  if (i < 0) switch (errno) {   /* failed? */
  case EINPROGRESS:
  case EAGAIN:                  /* For DG/UX brain dead behavior */
  case EISCONN:
  case EADDRINUSE:
    break;                      /* well, not really, it was interrupted */
  default:
    sprintf (tmp,"Can't connect to %.80s,%d: %s",hostname,port,
             strerror (errno));
    mm_log (tmp,ERROR);
    close (sock);               /* flush socket */
    return NIL;
  }

In addition to the above change, some changes are needed for compiling on
DG/UX 4.11 since DG fixed some other braindead stuff in this release.
Specifically, you no longer need a portable_utime, crypt now has a 
prototype and setpgrp has a version compatible with the rest of the world
but now is called setpgrp2....

I'm also seeing annoying messages about "New mailbox modification time but
apparently no changes".   I have a feeling this has to do with utime
hyper-resolution.  It's just annoying but I'll look at that later...

- - - - - - - 

The below os_d-g.c will work with 4.11.  If you don't have 4.11, don't
use it... you'll break the current os_d-g.c .... sigh....

#include "tcp_unix.h"           /* must be before osdep includes tcp.h */
#include "mail.h"
#include "osdep.h"
#include <stdio.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <ctype.h>
#include <errno.h>
extern int errno;               /* just in case */
#include <pwd.h>
#include <utime.h>
#include "misc.h"
#define setpgrp setpgrp2
#include "fs_unix.c"
#include "ftl_unix.c"
#include "nl_unix.c"
#include "env_unix.c"
#include "tcp_unix.c"
#include "log_std.c"
#include "gr_waitp.c"
#include "tz_sv4.c"

-- 
Ken Weaverling,  Delaware Tech               [email-masked]   (WHOIS: KJW)
                   finger me for PGP and home page info.