--- util.c.orig	Thu Jul 24 04:35:26 1997
+++ util.c	Thu Feb 19 20:56:11 1998
@@ -166,8 +166,8 @@
     struct servent *sp;
     struct servent sp_def;
     struct sockaddr_in s_in;
-    int sock;
-    register int i;
+    int sock, sock2;
+    int i, try;
 
     memset((void *)&s_in, 0, sizeof(s_in));
     if (nntpport == 0) {
@@ -185,44 +185,68 @@
     hp = gethostbyname( upstream );
     if (hp) {
 
-	/* Try to make connection to each of the addresses in turn. */
-	for (i = 0; (int *)(hp->h_addr_list)[i]; i++) {
-	    s_in.sin_family = hp->h_addrtype;
-	    s_in.sin_port = sp->s_port;
-	    s_in.sin_addr = incopy(hp->h_addr_list[i]);
-
-	    sock = socket(AF_INET, SOCK_STREAM, 0);
-	    if (sock < 0)
-		break;
+	/* Try the connection 5 times, are we paranoid or what! */
+	for (try = 0; try < 5; try++) {
 
-	    if (setjmp(timeout) != 0) {
+	    /* Try to make connection to each of the addresses in turn. */
+	    for (i = 0; (int *)(hp->h_addr_list)[i]; i++) {
+		s_in.sin_family = hp->h_addrtype;
+		s_in.sin_port = sp->s_port;
+		s_in.sin_addr = incopy(hp->h_addr_list[i]);
+
+		sock = socket(AF_INET, SOCK_STREAM, 0);
+		if (sock < 0)
+		    break;
+
+#ifdef DO_WE_REALLY_NEED_AN_ALARM
+		if (setjmp(timeout) != 0) {
+		    (void) close(sock);
+		    continue;
+		}
+
+		(void) signal(SIGALRM, timer);
+		(void) alarm((unsigned)10); /* 10 seconds to open conn */
+#endif
+		if (connect(sock, (struct sockaddr *)&s_in, sizeof(s_in)) < 0) {
+		    (void) close(sock);
+		    continue;
+		}
+#ifdef DO_WE_REALLY_NEED_AN_ALARM
+		(void) alarm((unsigned)0);
+#endif
+
+		nntpout = fdopen(sock, "w");
+		if (nntpout == NULL) {
+		    shutdown(sock, 2);
+		    (void) close(sock);
+		    break;
+		}
+
+		sock2 = dup(sock);
+		nntpin  = fdopen(sock2, "r");
+		if (nntpin == NULL)  {
+		    shutdown(sock, 2);
+		    (void) close(sock);
+		    (void) close(sock2);
+		    break;
+		}
+
+		switch(nntpreply()) {
+		case 200: 
+		case 201: 
+		    syslog( LOG_INFO, "connected to %s",
+			    inet_ntoa( s_in.sin_addr ) );
+		    return TRUE;
+		}
+
+		shutdown(sock, 2);
 		(void) close(sock);
-		continue;
-	    }
+		(void) close(sock2);
+	    }/* end of IP-addresses for loop */
 
-	    (void) signal(SIGALRM, timer);
-	    (void) alarm((unsigned)10); /* 10 seconds to open conn */
-	    if (connect(sock, (struct sockaddr *)&s_in, sizeof(s_in)) < 0)
-		break;
-	    (void) alarm((unsigned)0);
-
-	    nntpout = fdopen(sock, "w");
-	    if (nntpout == NULL)
-		break;
-
-	    nntpin  = fdopen(dup(sock), "r");
-	    if (nntpin == NULL) 
-		break;
-
-	    switch(nntpreply()) {
-	    case 200: 
-	    case 201: 
-		syslog( LOG_INFO, "connected to %s",
-			inet_ntoa( s_in.sin_addr ) );
-		return TRUE;
-	    }
-	    shutdown(fileno(nntpout), 0);
-	}/* end of IP-addresses for loop */
+	    /* wait for some time to elapse before trying again */
+	    sleep(2);
+	}/* end of retry for loop */
     }
     return FALSE;
 }/* end of connect function */
@@ -560,15 +584,17 @@
 
     strcpy(s, libdir);
     strcat(s, "/groupinfo");
-    fd = open( s, O_RDONLY );
     if ( stat( s, &st ) ) {
 	syslog( LOG_ERR, "can't stat %s: %m", s );
 	return;
     }
     stuff = critmalloc( st.st_size+1, "Reading group info" );
-    if ( (fd=open( s, O_RDONLY))<0 ||
-	 (read( fd, stuff, st.st_size ) < st.st_size) ) {
-	syslog( LOG_ERR, "can't open/read %s: %m", s );
+    if ( ( fd=open( s, O_RDONLY ) ) < 0) {
+	syslog( LOG_ERR, "can't open %s: %m", s );
+	return;
+    } else if ( read( fd, stuff, st.st_size ) < st.st_size ) {
+	syslog( LOG_ERR, "can't read %s: %m", s );
+	close( fd );
 	return;
     } else {
 	close( fd );
