Index: trunk/src/sh_files.c
===================================================================
--- trunk/src/sh_files.c	(revision 364)
+++ trunk/src/sh_files.c	(revision 365)
@@ -283,9 +283,7 @@
 static int        sh_files_pushdir   (int class, const char * str_s);
 static int        sh_files_pushfile  (int class, const char * str_s);
-static int        sh_files_checkdir  (int class, int rdepth, char * dirName,
+static int        sh_files_checkdir  (int class, unsigned long check_mask, 
+				      int rdepth, char * dirName,
 				      char * relativeName);
-static ShFileType sh_files_filecheck (int class, char * dirName, 
-				      char * fileName, int * reported,
-				      int rsrcflag);
 
 static long MaxRecursionLevel = 0;
@@ -356,10 +354,11 @@
 #endif
 	      sl_strlcpy(pstr, sh_hash_getpolicy(ptr->class), sizeof(pstr));
-	      sh_error_handle ((-1),  FIL__, __LINE__, 0, MSG_FI_CHK, pstr, tmp);
+	      sh_error_handle ((-1),  FIL__, __LINE__, 0, 
+			       MSG_FI_CHK, pstr, tmp);
 	    }
 
 	  BREAKEXIT(sh_files_filecheck);
 	  tmp_reported = ptr->is_reported; /* fix aliasing warning */ 
-	  status = sh_files_filecheck (ptr->class, dir, file, 
+	  status = sh_files_filecheck (ptr->class, ptr->check_mask, dir, file, 
 				       &tmp_reported, 0);
 	  ptr->is_reported = tmp_reported;
@@ -937,4 +936,5 @@
   char                  * name;
   int                     class;
+  unsigned long           check_mask;
   int                     rdepth;
   short                   type;
@@ -944,5 +944,6 @@
 static zAVLTree * zglobList   = NULL;
 
-static void sh_files_pushglob (int class, int type, const char * p, int rdepth)
+static void sh_files_pushglob (int class, int type, const char * p, int rdepth,
+			       unsigned long check_mask, int flag)
 {
   int     globstatus = -1;
@@ -970,4 +971,5 @@
 	  new_item_ptr->name           = fileName;
 	  new_item_ptr->class          = class;
+	  new_item_ptr->check_mask     = (flag == 0) ? sh_files_maskof(class) : check_mask;
 	  new_item_ptr->rdepth         = rdepth;
 	  new_item_ptr->type           = type;
@@ -1058,5 +1060,6 @@
     {
       sh_files_pushglob(testPattern->class, testPattern->type, 
-			testPattern->name, testPattern->rdepth);
+			testPattern->name, testPattern->rdepth,
+			testPattern->check_mask, 1);
     }
   SL_RET0(_("sh_files_check_globPatterns"));
@@ -1083,10 +1086,10 @@
 int sh_files_delglobstack ()
 {
-  SL_ENTER(_("sh_files_delfilestack"));
+  SL_ENTER(_("sh_files_delglobstack"));
 
   zAVLFreeTree (zglobList, free_globstack);
   zglobList = NULL;
 
-  SL_RETURN(0, _("sh_files_delfilestack"));
+  SL_RETURN(0, _("sh_files_delglobstack"));
 }
   
@@ -1190,5 +1193,5 @@
   else
     {
-      sh_files_pushglob (class, SH_LIST_FILE, p, 0);
+      sh_files_pushglob (class, SH_LIST_FILE, p, 0, 0, 0);
     }
 
@@ -1268,5 +1271,5 @@
 		{
 		  BREAKEXIT(sh_files_filecheck);
-		  sh_files_filecheck (dst_ptr->class,  ptr->name,  
+		  sh_files_filecheck (dst_ptr->class, dst_ptr->check_mask, ptr->name,  
 				      NULL,  &status, 0);
 		  dst_ptr->checked = S_TRUE;
@@ -1280,8 +1283,8 @@
 
 	  if (status == S_FALSE)
-	    sh_files_filecheck (ptr->class,  ptr->name,  NULL,  &status, 0);
+	    sh_files_filecheck (ptr->class,  ptr->check_mask, ptr->name,  NULL,  &status, 0);
 
 	  BREAKEXIT(sh_files_checkdir);
-	  status = sh_files_checkdir (ptr->class, ptr->rdepth, ptr->name, 
+	  status = sh_files_checkdir (ptr->class, ptr->check_mask, ptr->rdepth, ptr->name, 
 				      ptr->name);
 
@@ -1601,5 +1604,5 @@
   else
     {
-      sh_files_pushglob (class, which_dirList, tail, rdepth);
+      sh_files_pushglob (class, which_dirList, tail, rdepth, 0, 0);
     }
 #else  
@@ -1745,5 +1748,6 @@
 /* -- check a single directory and its content
  */
-static int sh_files_checkdir (int iclass, int idepth, char * iname, 
+static int sh_files_checkdir (int iclass, unsigned long check_mask, 
+			      int idepth, char * iname, 
 			      char * relativeName)
 {
@@ -1769,4 +1773,6 @@
   int             class_next;
   int             file_class_next;
+  unsigned long   check_mask_next;
+  unsigned long   file_check_mask_next;
 
   int             checked_flag  = S_FALSE;
@@ -1836,6 +1842,5 @@
       SL_RETURN((-1), _("sh_files_checkdir"));
     }
-    
-    
+
   /* ---- stat the directory ----
    */
@@ -1844,4 +1849,5 @@
   theFile->attr_string = NULL;
   theFile->link_path   = NULL;
+  theFile->check_mask  = check_mask;
 
   (void) relativeName;
@@ -1983,5 +1989,7 @@
     rdepth_next     = rdepth - 1;
     class_next      = class;
+    check_mask_next = check_mask;
     file_class_next = class;
+    file_check_mask_next = check_mask;
     checked_flag    = -1;
     cchecked_flag   = -1;
@@ -2000,4 +2008,5 @@
 	 */
 	file_class_next    = dst_ptr->class;
+	file_check_mask_next = dst_ptr->check_mask;
 	checked_flag       = dst_ptr->checked;
 	cchecked_flag      = dst_ptr->childs_checked;
@@ -2015,4 +2024,5 @@
 	     */
 	    file_class_next    = dst_ptr->class;
+	    file_check_mask_next = dst_ptr->check_mask;
 	    checked_flag       = dst_ptr->checked;
 	    cchecked_flag      = dst_ptr->childs_checked;
@@ -2029,4 +2039,5 @@
 	 */
 	file_class_next    = dst_ptr->class;
+	file_check_mask_next = dst_ptr->check_mask;
 	checked_flag       = dst_ptr->checked;
 	/* not set, hence always FALSE                   */
@@ -2065,5 +2076,5 @@
 	  dummy = dst_ptr->is_reported;
 
-	checkit = sh_files_filecheck (file_class_next, 
+	checkit = sh_files_filecheck (file_class_next, file_check_mask_next, 
 				      iname, 
 				      dirlist->sh_d_name,
@@ -2084,4 +2095,5 @@
       {
 	++theDir->NumDirs;
+
 	if (rdepth_next >= 0 && cchecked_flag != S_TRUE) 
 	  {
@@ -2103,4 +2115,5 @@
 		rdepth_next   = tmp_ptr->rdepth;
 		class_next    = tmp_ptr->class;
+		check_mask_next = tmp_ptr->check_mask;
 		/* 28. Aug 2001 reversed
 		 */
@@ -2120,4 +2133,5 @@
 		    rdepth_next   = tmp_ptr->rdepth;
 		    class_next    = tmp_ptr->class;
+		    check_mask_next = tmp_ptr->check_mask;
 		    /* 28. Aug 2001 reversed
 		     */
@@ -2127,7 +2141,7 @@
 	      }
 	    
-	    if (cchecked_flag == S_FALSE)
+	  if (cchecked_flag == S_FALSE)
 	      {
-		sh_files_checkdir (class_next, rdepth_next, tmpcat, 
+		sh_files_checkdir (class_next, check_mask_next, rdepth_next, tmpcat, 
 				   dirlist->sh_d_name);
 		tmp_ptr->childs_checked = S_TRUE;
@@ -2138,5 +2152,5 @@
 	      }
 	    else if (checked_flag == -1)
-	      sh_files_checkdir (class_next, rdepth_next, tmpcat, 
+	      sh_files_checkdir (class_next, check_mask_next, rdepth_next, tmpcat, 
 				 dirlist->sh_d_name);
 	    
@@ -2218,8 +2232,13 @@
 }
 
-static ShFileType sh_files_filecheck (int class, char * dirName, 
-				      char * infileName,
-				      int * reported, 
-				      int rsrcflag)
+static void * sh_dummy_fileName;
+static void * sh_dummy_tmpname;
+static void * sh_dummy_tmpdir;
+
+ShFileType sh_files_filecheck (int class, unsigned long check_mask,
+			       char * dirName, 
+			       char * infileName,
+			       int * reported, 
+			       int rsrcflag)
 {
   /* 28 Aug 2001 allow NULL fileName
@@ -2241,4 +2260,11 @@
   theFile  = SH_ALLOC(sizeof(file_type));
 
+  /* Take the address to keep gcc from putting it into a register. 
+   * Avoids the 'clobbered by longjmp' warning. 
+   */
+  sh_dummy_fileName = (void *) &fileName;
+  sh_dummy_tmpname  = (void *) &tmpname;
+  sh_dummy_tmpdir   = (void *) &tmpdir;
+
   BREAKEXIT(sh_derr);
 
@@ -2263,5 +2289,7 @@
   if (dirName == NULL /* || fileName == NULL */)
     {
+      SH_MUTEX_LOCK(mutex_thread_nolog);
       sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_NULL);
+      SH_MUTEX_UNLOCK(mutex_thread_nolog);
       SH_FREE(fullpath);
       SH_FREE(theFile);
@@ -2276,7 +2304,9 @@
 	{
 	  tmpname = sh_util_safe_name (fileName);
+	  SH_MUTEX_LOCK(mutex_thread_nolog);
 	  sh_error_handle (ShDFLevel[SH_ERR_T_NAME], FIL__, __LINE__, 0,
 			   MSG_FI_OBSC2,
 			   "", tmpname);
+	  SH_MUTEX_UNLOCK(mutex_thread_nolog);
 	  SH_FREE(tmpname);
 	}
@@ -2285,7 +2315,9 @@
 	  tmpdir  = sh_util_safe_name (dirName);
 	  tmpname = sh_util_safe_name (fileName);
+	  SH_MUTEX_LOCK(mutex_thread_nolog);
 	  sh_error_handle (ShDFLevel[SH_ERR_T_NAME], FIL__, __LINE__, 0,
 			   MSG_FI_OBSC2,
 			   tmpdir, tmpname);
+	  SH_MUTEX_UNLOCK(mutex_thread_nolog);
 	  SH_FREE(tmpname);
 	  SH_FREE(tmpdir);
@@ -2299,7 +2331,9 @@
       tmpdir  = sh_util_safe_name (dirName);
       tmpname = sh_util_safe_name (fileName);
+      SH_MUTEX_LOCK(mutex_thread_nolog);
       sh_error_handle (ShDFLevel[SH_ERR_T_FILE],  FIL__, __LINE__, 0,
 		       MSG_FI_2LONG2,
 		       tmpdir, tmpname);
+      SH_MUTEX_UNLOCK(mutex_thread_nolog);
       SH_FREE(tmpname);
       SH_FREE(tmpdir);
@@ -2313,5 +2347,5 @@
    */
   sl_strlcpy (theFile->fullpath, fullpath, PATH_MAX);
-  theFile->check_mask    = sh_files_maskof(class);
+  theFile->check_mask    = check_mask /* sh_files_maskof(class) */;
   theFile->file_reported = (*reported);
   theFile->attr_string   = NULL;
@@ -2347,6 +2381,8 @@
     {
       tmpname = sh_util_safe_name (fullpath); /* fixed in 1.5.4 */
+      SH_MUTEX_LOCK(mutex_thread_nolog);
       sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_CSUM,
 		       fileHash, tmpname);
+      SH_MUTEX_UNLOCK(mutex_thread_nolog);
       SH_FREE(tmpname);
     } 
@@ -2462,5 +2498,4 @@
   SL_RETURN((0),_("sh_files_fullpath"));
 }
-
 
 /* -----------------------------------
