]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(zaptemp): Warn if a temporary file is not removed.
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 13 Nov 2004 04:45:58 +0000 (04:45 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 13 Nov 2004 04:45:58 +0000 (04:45 +0000)
Prune unnecessary accesses to volatile locations, and take some
code out of the critical section that didn't need to be in it.

src/sort.c

index 3b6cfb09b51fd5d3bc1844d1227924bf9f002ff8..006411253279d42e75a3e16f8fddd3904520d064 100644 (file)
@@ -514,30 +514,34 @@ add_temp_dir (char const *dir)
   temp_dirs[temp_dir_count++] = dir;
 }
 
-/* Search through the list of temporary files for NAME;
-   remove it if it is found on the list. */
+/* Remove NAME from the list of temporary files.  */
 
 static void
 zaptemp (const char *name)
 {
   struct tempnode *volatile *pnode;
   struct tempnode *node;
+  struct tempnode *next;
   sigset_t oldset;
+  int unlink_status;
+  int unlink_errno = 0;
 
-  for (pnode = &temphead; (node = *pnode); pnode = &node->next)
-    if (node->name == name)
-      {
-       /* Unlink the temporary file in a critical section, to avoid races.  */
-       struct tempnode *t = node->next;
-       sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
-       unlink (name);
-       *pnode = t;
-       sigprocmask (SIG_SETMASK, &oldset, NULL);
-       if (! t)
-         temptail = pnode;
-       free (node);
-       break;
-      }
+  for (pnode = &temphead; (node = *pnode)->name != name; pnode = &node->next)
+    continue;
+
+  /* Unlink the temporary file in a critical section to avoid races.  */
+  next = node->next;
+  sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
+  unlink_status = unlink (name);
+  unlink_errno = errno;
+  *pnode = next;
+  sigprocmask (SIG_SETMASK, &oldset, NULL);
+
+  if (unlink_status != 0)
+    error (0, unlink_errno, "warning: cannot remove: %s", name);
+  if (! next)
+    temptail = pnode;
+  free (node);
 }
 
 #if HAVE_NL_LANGINFO