Репозиторий ALT Linux backports/2.4
Последнее обновление: 9 июля 2008 | Пакетов: 497 | Посещений: 1574416
 поиск   регистрация   авторизация 
 
Группа :: Система/Серверы
Пакет: pdnsd

 Главная   Изменения   Спек   Патчи   Загрузить   Bugs and FR 

Патч: pdnsd-1.2-alt-cache.patch


--- pdnsd-1.2/src/cache.c-	2004-10-13 21:49:04 +0000
+++ pdnsd-1.2/src/cache.c	2004-10-13 21:59:53 +0000
@@ -1027,6 +1027,9 @@ static void purge_cache(long sz, int laz
         log_warn("%s encountered while reading %s from disk cache file.", \
         ferror(f)?"Error":feof(f)?"EOF":"Incomplete item",item)
 
+static FILE *f;
+#define FCLOSE(f) fclose(f),f=NULL
+
 /*
  * Load cache from disk and rebuild the hash tables.
  */
@@ -1037,13 +1040,12 @@ void read_disk_cache()
 	int dtsz=512;
 	unsigned char *data;
 	unsigned long cnt;
-	FILE *f;
 
 	char path[strlen(global.cache_dir)+sizeof("/pdnsd.cache")];
 
 	stpcpy(stpcpy(path,global.cache_dir),"/pdnsd.cache");
 
-	if (!(f=fopen(path,"r"))) {
+	if (!(f=fopen(path,"r+"))) {
 		log_warn("Could not open disk cache file %s: %s",path,strerror(errno));
 		return;
 	}
@@ -1157,7 +1159,6 @@ void read_disk_cache()
 	}
 #ifdef DEBUG_HASH
 	free(data);
-	fclose(f);
 	dumphash();
 	goto sort_return;
 #else
@@ -1168,7 +1169,6 @@ void read_disk_cache()
 	free_cent(&ce  DBG0);
  free_data_fclose:
 	free(data);
-	fclose(f);
 #ifdef DEBUG_HASH
  sort_return:
 #endif
@@ -1189,13 +1189,12 @@ void read_disk_cache()
  free_data_fclose_exit:
 	free(data);
  fclose_exit:
-	fclose(f);
 	log_error("Out of memory in reading cache file. Exiting.");
 	pdnsd_exit();
 }
 
 /* write an rr to the file f */
-static int write_rrset(int tp, rr_set_t *rrs, FILE *f)
+static int write_rrset(int tp, rr_set_t *rrs)
 {
 	rr_bucket_t *rr;
 	rr_fset_t sh;
@@ -1244,7 +1243,6 @@ void write_disk_cache()
 	dns_cent_t *le;
 	unsigned long en=0;
 	dns_hash_pos_t pos;
-	FILE *f;
 	unsigned long num_rrs_errs=0;
 #	define MAX_NUM_RRS_ERRS 10
 
@@ -1267,8 +1265,8 @@ void write_disk_cache()
 		goto lock_failed;
 	}
 
-	if (!(f=fopen(path,"w"))) {
-		log_warn("Could not open disk cache file %s: %s",path,strerror(errno));
+	if (fseek(f,0,SEEK_SET)) {
+		log_warn("Could not write disk cache file %s: %s",path,strerror(errno));
 		goto softunlock_return;
 	}
 
@@ -1341,13 +1339,13 @@ void write_disk_cache()
 			for (j=0;j<T_NUM;j++) {
 				rr_set_t *rrset=le->rr[j];
 				if(rrset && !(rrset->flags&CF_LOCAL)) {
-					if(!write_rrset(j+T_MIN,rrset,f))
+					if(!write_rrset(j+T_MIN,rrset))
 						goto fclose_unlock;
 				}
 			}
 		}
 	}
-	if(fclose(f)) {
+	if(FCLOSE(f)) {
 		log_error("Could not close cache file %s after writing cache: %s", path,strerror(errno));
 	}
 	softunlock_cache_r();
@@ -1355,7 +1353,7 @@ void write_disk_cache()
 	return;
 
  fclose_unlock:
-	fclose(f);
+	FCLOSE(f);
  softunlock_return:
 	softunlock_cache_r();
 	return;
 
design & coding: Vladimir Lettiev aka crux © 2004-2005