summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-11-13 04:45:58 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-11-13 04:45:58 +0000
commitaf6bd870f428e0d094e9743a40852181fad928b5 (patch)
tree762a010807d8e0258cb9f927aac24314fa74cf3a /src
parent1b2e96f8302bb0eb80c30ec27ab13d4d0f1a7912 (diff)
downloadcoreutils-af6bd870f428e0d094e9743a40852181fad928b5.tar.xz
(zaptemp): Warn if a temporary file is not removed.
Prune unnecessary accesses to volatile locations, and take some code out of the critical section that didn't need to be in it.
Diffstat (limited to 'src')
-rw-r--r--src/sort.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/sort.c b/src/sort.c
index 3b6cfb09b..006411253 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -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