httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From willem.vanp...@philips.com
Subject Fix: Proxy garbage collection under Windows NT
Date Wed, 01 Mar 2000 17:49:51 GMT
The patch below fixes the proxy garbage collection routine under Windows NT.
Most of the credits for this fix go to Klaus Mueller and Ben Kummer, who fixed
it in version 1.3.3, although the changes never made it into the production code.
(reference: bugs.apache.org, PR #3640)

I re-applied Klaus's fix to the 1.3.12 code and fixed a (probably harmless) bug
(Klaus forgot to add a continue statement to the if(stat()) block).

Further, I noticed that for the TPF platform some code had been added to address
this same issue that had now become obsolete.

Last, I saw a chunk of redundant code in the OS/2 block. By rearranging a couple
of #if lines this redundant code could also be deleted, which should make the code
easier to understand and maintain. Side effect is that when the directory is not 
empty, add_long61() is called under OS/2, which was not the case in the old code.
As far as I understand the code, this is how it should be.


Tested on:
- Windows NT 4.0 Service Pack 6a (Intel)
- Compaq Tru64 Unix 4.0f (Alpha)


Willem van Pelt

Philips Digital Networks - Digital Transmission Systems
Building OAN, room 1.22   Tel: +31-40-27 32564
PO Box 80002              Fax: +31-40-27 36661
5600 JB  Eindhoven, NL


diff -rc apache_1.3.12.org/src/modules/proxy/proxy_cache.c apache_1.3.12/src/modules/proxy/proxy_cache.c
*** apache_1.3.12.org/src/modules/proxy/proxy_cache.c	Thu Dec  9 00:02:43 1999
--- apache_1.3.12/src/modules/proxy/proxy_cache.c	Wed Mar  1 17:49:38 2000
***************
*** 441,455 ****
  	    continue;
  	sprintf(filename, "%s%s", cachedir, ent->d_name);
  	Explain1("GC Examining file %s", filename);
! /* is it a temporary file? */
  	if (strncmp(ent->d_name, "tmp", 3) == 0) {
! /* then stat it to see how old it is; delete temporary files > 1 day old */
! 	    if (stat(filename, &buf) == -1) {
! 		if (errno != ENOENT)
! 		    ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
! 				 "proxy gc: stat(%s)", filename);
! 	    }
! 	    else if (garbage_now != -1 && buf.st_atime < garbage_now - SEC_ONE_DAY &&
  		     buf.st_mtime < garbage_now - SEC_ONE_DAY) {
  		Explain1("GC unlink %s", filename);
  		ap_log_error(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, r->server,
--- 441,457 ----
  	    continue;
  	sprintf(filename, "%s%s", cachedir, ent->d_name);
  	Explain1("GC Examining file %s", filename);
! 	/* stat the file to get type and date */
! 	if (stat(filename, &buf) == -1) {
! 	    if (errno != ENOENT)
! 		ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
! 			     "proxy gc: stat(%s)", filename);
! 	    continue;
! 	}
! 	/* is it a temporary file? */
  	if (strncmp(ent->d_name, "tmp", 3) == 0) {
! 	    /* delete temporary files > 1 day old */
! 	    if (garbage_now != -1 && buf.st_atime < garbage_now - SEC_ONE_DAY &&
  		     buf.st_mtime < garbage_now - SEC_ONE_DAY) {
  		Explain1("GC unlink %s", filename);
  		ap_log_error(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, r->server,
***************
*** 467,485 ****
  	/* FIXME: Shouldn't any unexpected files be deleted? */
  	/*      if (strlen(ent->d_name) != HASH_LEN) continue; */
  
- /* under OS/2 use dirent's d_attr to identify a diretory */
- /* under TPF use stat to identify a directory */
- #if defined(OS2) || defined(TPF)
  /* is it a directory? */
! #ifdef OS2
  	if (ent->d_attr & A_DIR) {
! #elif defined(TPF)
!     if (stat(filename, &buf) == -1) {
!         if (errno != ENOENT)
!             ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
!                  "proxy gc: stat(%s)", filename);
!     }
!     if (S_ISDIR(buf.st_mode)) {
  #endif
  	    char newcachedir[HUGE_STRING_LEN];
  	    ap_snprintf(newcachedir, sizeof(newcachedir),
--- 469,480 ----
  	/* FIXME: Shouldn't any unexpected files be deleted? */
  	/*      if (strlen(ent->d_name) != HASH_LEN) continue; */
  
  /* is it a directory? */
! #if defined(OS2)
! /* under OS/2 use dirent's d_attr to identify a diretory */
  	if (ent->d_attr & A_DIR) {
! #else
! 	if (S_ISDIR(buf.st_mode)) {
  #endif
  	    char newcachedir[HUGE_STRING_LEN];
  	    ap_snprintf(newcachedir, sizeof(newcachedir),
***************
*** 493,504 ****
  		rmdir(newcachedir);
  #endif
  		--nfiles;
  	    }
  	    continue;
  	}
- #endif
  
! /* read the file */
  	fd = open(filename, O_RDONLY | O_BINARY);
  	if (fd == -1) {
  	    if (errno != ENOENT)
--- 488,501 ----
  		rmdir(newcachedir);
  #endif
  		--nfiles;
+ 	    } else {
+ 		/* Directory is not empty. Account for its size: */
+ 		add_long61(&curbytes, ROUNDUP2BLOCKS(buf.st_size));
  	    }
  	    continue;
  	}
  
! 	/* read the file */
  	fd = open(filename, O_RDONLY | O_BINARY);
  	if (fd == -1) {
  	    if (errno != ENOENT)
***************
*** 506,541 ****
  			     "proxy gc: open(%s)", filename);
  	    continue;
  	}
- 	if (fstat(fd, &buf) == -1) {
- 	    ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
- 			 "proxy gc: fstat(%s)", filename);
- 	    close(fd);
- 	    continue;
- 	}
- 
- /* In OS/2 and TPF this has already been done above */
- #if !defined(OS2) && !defined(TPF)
- 	if (S_ISDIR(buf.st_mode)) {
- 	    char newcachedir[HUGE_STRING_LEN];
- 	    close(fd);
- 	    ap_snprintf(newcachedir, sizeof(newcachedir),
- 			"%s%s/", cachesubdir, ent->d_name);
- 	    if (!sub_garbage_coll(r, files, cachebasedir, newcachedir)) {
- 		ap_snprintf(newcachedir, sizeof(newcachedir),
- 			    "%s%s", cachedir, ent->d_name);
- #if TESTING
- 		fprintf(stderr, "Would remove directory %s\n", newcachedir);
- #else
- 		rmdir(newcachedir);
- #endif
- 		--nfiles;
- 	    } else {
- 		/* Directory is not empty. Account for its size: */
- 		add_long61(&curbytes, ROUNDUP2BLOCKS(buf.st_size));
- 	    }
- 	    continue;
- 	}
- #endif
  
  	i = read(fd, line, 26);
  	close(fd);
--- 503,508 ----



Mime
View raw message