[news.software.b] News 2.11.17 breaks "batch"

lmb@vicom.COM (Larry Blair) (01/28/89)

There is a major bug introduced by the 2.11.17 patches to batch.c.  The
"optimization" added to prevent having to do a full path lookup for each
file by doing a chdir(SPOOLDIR) can cause the site.work file not to be
properly updated when the batch exceeds the maximum size (because you
are not the correct directory).  I'm not sure if this will happen with
the distributed sendbatch, but it does happen with my script that calls
batch durectly.

I haven't tried to fix it yet; I just pulled the change.
-- 
Larry Blair   ames!vsi1!lmb   lmb@vicom.com

lmb@vicom.COM (Larry Blair) (01/28/89)

In article <1424@vsi1.COM> I wrote:
=There is a major bug introduced by the 2.11.17 patches to batch.c.
=I'm not sure if this will happen with
=the distributed sendbatch, but it does happen with my script that calls
=batch durectly.

Further checking shows that sendbatch uses a full path for the batch
file, so it won't fail this way.
-- 
Larry Blair   ames!vsi1!lmb   lmb@vicom.com

lmb@vicom.COM (Larry Blair) (01/28/89)

Here is a patch that fixes the problem with batch.  I only wrote it for
systems that have BSD4_2 or USG defined, since I don't know that a get
current directory function is available on other types.  This patch won't
hurt those systems, but they should be sure that the batch file name
given to batch is a full pathname (starts with a /).

*** batch.c.2.17	Fri Jan 27 16:22:19 1989
--- batch.c	Fri Jan 27 16:44:04 1989
***************
*** 42,47 ****
--- 42,48 ----
  
  #if defined(USG) || defined(BSD4_2)
  #include <fcntl.h>
+ char saved_dir[PATHLEN];
  #endif
  
  struct stat sbuf;
***************
*** 92,99 ****
  		exit(1);
  	}
  
  	if (chdir(SPOOLDIR) < 0) {
! 		logerror("chdir(%s): %s", workfile, sys_errlist[errno]);
  		exit(1);
  	}
  
--- 93,107 ----
  		exit(1);
  	}
  
+ #if defined(USG)
+ 	getcwd(saved_dir, PATHLEN);
+ #endif
+ #if defined(BSD4_2)
+ 	getwd(saved_dir);
+ #endif
+ 
  	if (chdir(SPOOLDIR) < 0) {
! 		logerror("chdir(%s): %s", SPOOLDIR, sys_errlist[errno]);
  		exit(1);
  	}
  
***************
*** 150,155 ****
--- 158,171 ----
  			break;
  		}
  	}
+ 
+ #if defined(USG) || defined(BSD4_2)
+ 	if (chdir(saved_dir) < 0) {
+ 		logerror("chdir(%s): %s", saved_dir, sys_errlist[errno]);
+ 		exit(1);
+ 	}
+ #endif
+ 
  	if (fdstatus != NULL) {		/* exceeded maxbytes */
  		char tmpfile[512];
  
-- 
Larry Blair   ames!vsi1!lmb   lmb@vicom.com

news@cipc1.Dayton.NCR.COM (News Administrator) (01/31/89)

In article <1424@vsi1.COM> lmb@vicom.COM (Larry Blair) writes:
>There is a major bug introduced by the 2.11.17 patches to batch.c.  The
>"optimization" added to prevent having to do a full path lookup for each
>file by doing a chdir(SPOOLDIR) can cause the site.work file not to be
>properly updated when the batch exceeds the maximum size (because you
>are not the correct directory).

Yes, I was just bitten by the same "feature".  The solution is to ensure the
first argument to batch is a full pathname ($LIBDIR/batch `pwd`/filename).



-- 
Tom Bertelson				"What's so funny 'bout
Tom.Bertelson@cipc1.Dayton.NCR.COM	 peace, love and understanding?"
...!uunet!ncrlnk!cipc1!tbertels			-- Elvis Costello