[net.news.b] bug fixes to ifuncs.c

smk@axiom.UUCP (Steven Kramer) (01/18/84)

Following the fiasco we had in implementing some of the fclose()'s
(by doing the fseek(,0L,0)) I went and simply did the fclose() in
all places of transmit() that returned without closing the file.
The following is the diff -c of ifuncs.c from B2.10 and my changes.
	--steve kramer
----------------------------------
*** ifuncs.c.orig	Thu Mar 31 11:51:44 1983
--- ifuncs.c	Tue Jan 17 14:29:40 1984
***************
*** 28,33
  	fp = xfopen(ARTICLE, "r");
  	if (hread(&h, fp, TRUE) == NULL)
  		xerror("Cannot reread article");
  	fclose(fp);
  	if (h.distribution[0])
  		strcpy(h.nbuf, h.distribution);

--- 28,34 -----
  	fp = xfopen(ARTICLE, "r");
  	if (hread(&h, fp, TRUE) == NULL)
  		xerror("Cannot reread article");
+ #ifndef AXIOM
  	fclose(fp);
  #endif
  	if (h.distribution[0])
***************
*** 29,34
  	if (hread(&h, fp, TRUE) == NULL)
  		xerror("Cannot reread article");
  	fclose(fp);
  	if (h.distribution[0])
  		strcpy(h.nbuf, h.distribution);
  	ngcat(h.nbuf);

--- 30,36 -----
  		xerror("Cannot reread article");
  #ifndef AXIOM
  	fclose(fp);
+ #endif
  	if (h.distribution[0])
  		strcpy(h.nbuf, h.distribution);
  	ngcat(h.nbuf);
***************
*** 43,48
  			hptr++;
  	}
  	*nptr = '\0';
  
  	/* loop once per system. */
  	lock();

--- 45,53 -----
  			hptr++;
  	}
  	*nptr = '\0';
+ #ifdef AXIOM
+ 	fclose(fp);
+ #endif
  
  	/* loop once per system. */
  	lock();
***************
*** 99,104
  	int useexist = (index(sp->s_flags, 'U') != NULL);
  
  	if (local && mode == PROC)
  		return;
  #ifdef DEBUG
  	printf("Transmitting to '%s'\n", sp->s_name);

--- 104,113 -----
  	int useexist = (index(sp->s_flags, 'U') != NULL);
  
  	if (local && mode == PROC)
+ #ifdef AXIOM
+ 	{
+ 		fclose(ifp);
+ #endif
  		return;
  #ifdef AXIOM
  	}
***************
*** 100,105
  
  	if (local && mode == PROC)
  		return;
  #ifdef DEBUG
  	printf("Transmitting to '%s'\n", sp->s_name);
  #endif

--- 109,117 -----
  		fclose(ifp);
  #endif
  		return;
+ #ifdef AXIOM
+ 	}
+ #endif
  #ifdef DEBUG
  	printf("Transmitting to '%s'\n", sp->s_name);
  #endif
***************
*** 108,113
  			fprintf(stderr, "Bad header, not transmitting\n");
  			log("Bad header, not transmitting %s re %s to %s",
  				hh.ident, hh.title, sp->s_name);
  			return;
  		}
  		/* Taken out for obscure reasons - see the standard.

--- 120,128 -----
  			fprintf(stderr, "Bad header, not transmitting\n");
  			log("Bad header, not transmitting %s re %s to %s",
  				hh.ident, hh.title, sp->s_name);
+ #ifdef AXIOM
+ 			fclose(ifp);
+ #endif
  			return;
  		}
  		/* Taken out for obscure reasons - see the standard.
***************
*** 115,120
  		*/
  		if (hh.nbuf[0] == '\0') {
  			printf("Article not subscribed to by %s\n", sp->s_name);
  			return;
  		}
  		sprintf(TRANS, "%s/trXXXXXX", SPOOL);

--- 130,138 -----
  		*/
  		if (hh.nbuf[0] == '\0') {
  			printf("Article not subscribed to by %s\n", sp->s_name);
+ #ifdef AXIOM
+ 			fclose(ifp);
+ #endif
  			return;
  		}
  		sprintf(TRANS, "%s/trXXXXXX", SPOOL);
***************
*** 139,144
  		if (ofp == NULL)
  			xerror("Cannot append to %s", sp->s_xmit);
  		fprintf(ofp, "%s\n", firstbufname);
  		fclose(ofp);
  		return;
  	}

--- 157,165 -----
  		if (ofp == NULL)
  			xerror("Cannot append to %s", sp->s_xmit);
  		fprintf(ofp, "%s\n", firstbufname);
+ #ifdef AXIOM
+ 		fclose(ifp);
+ #endif
  		fclose(ofp);
  		return;
  	}
***************
*** 151,156
  			sprintf(bfr, UXMIT, sp->s_name, firstbufname);
  		else
  			sprintf(bfr, sp->s_xmit, firstbufname);
  	} else
  #endif
  	{

--- 172,180 -----
  			sprintf(bfr, UXMIT, sp->s_name, firstbufname);
  		else
  			sprintf(bfr, sp->s_xmit, firstbufname);
+ #ifdef AXIOM
+ 		fclose(ifp);
+ #endif
  	} else
  #endif
  	{
***************
*** 165,170
  		fclose(ifp);
  		fclose(ofp);
  		if (*sp->s_xmit == '\0')
  			sprintf(bfr, DFTXMIT, sp->s_name, TRANS);
  		else
  			sprintf(bfr, "(%s) < %s", sp->s_xmit, TRANS);

--- 189,206 -----
  		fclose(ifp);
  		fclose(ofp);
  		if (*sp->s_xmit == '\0')
+ #ifdef AXIOM
+ 			/*	There needs to to be a define for uux
+ 				without the - flag and the < %s.
+ 				Without this fix uucp sends the article
+ 				over the wires with 2 set of input
+ 				(one from the - and one from the < %s).
+ 			*/
+ 			if (noshell)
+ 				sprintf(bfr, EFTXMIT, sp->s_name);
+ 			else
+ 				sprintf(bfr, DFTXMIT, sp->s_name, TRANS);
+ #else
  			sprintf(bfr, DFTXMIT, sp->s_name, TRANS);
  #endif
  		else
***************
*** 166,171
  		fclose(ofp);
  		if (*sp->s_xmit == '\0')
  			sprintf(bfr, DFTXMIT, sp->s_name, TRANS);
  		else
  			sprintf(bfr, "(%s) < %s", sp->s_xmit, TRANS);
  	}

--- 202,208 -----
  				sprintf(bfr, DFTXMIT, sp->s_name, TRANS);
  #else
  			sprintf(bfr, DFTXMIT, sp->s_name, TRANS);
+ #endif
  		else
  			sprintf(bfr, "(%s) < %s", sp->s_xmit, TRANS);
  	}
***************
*** 177,182
  		else {
  			close(0);
  			open(TRANS, 0);
  			ptr = sp->s_xmit;
  			for (pid = 0; pid < 19; pid++) {
  				while (isspace(*ptr))

--- 214,232 -----
  		else {
  			close(0);
  			open(TRANS, 0);
+ #ifdef AXIOM
+ 			/*	The code works fine if the command is
+ 				just one program with no arguments, but
+ 				otherwise it passes the whole string (args
+ 				as well) to the execv as a path.  The
+ 				problems comes with the S flag and a
+ 				supplied command, hence the if statement
+ 				to allow for when no command is supplied.
+ 			*/
+ 			if (*sp->s_xmit == '\0')		/* need bfp? */
+ 				ptr = bfr;
+ 			else
+ #endif
  			ptr = sp->s_xmit;
  			for (pid = 0; pid < 19; pid++) {
  				while (isspace(*ptr))
***************
*** 188,193
  					break;
  			}
  			argv[++pid] = 0;
  			execv(sp->s_xmit, argv);
  			xerror("Can't execv\n");
  		}

--- 238,246 -----
  					break;
  			}
  			argv[++pid] = 0;
+ #ifdef AXIOM
+ 			execv(argv[0], argv);
+ #else
  			execv(sp->s_xmit, argv);
  #endif
  			xerror("Can't execv\n");
***************
*** 189,194
  			}
  			argv[++pid] = 0;
  			execv(sp->s_xmit, argv);
  			xerror("Can't execv\n");
  		}
  	} else

--- 242,248 -----
  			execv(argv[0], argv);
  #else
  			execv(sp->s_xmit, argv);
+ #endif
  			xerror("Can't execv\n");
  		}
  	} else
-- 
	--steve kramer
	{allegra,genrad,ihnp4,utzoo,philabs,uw-beaver}!linus!axiom!smk	(UUCP)
	linus!axiom!smk@mitre-bedford					(MIL)