From af6bd870f428e0d094e9743a40852181fad928b5 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 13 Nov 2004 04:45:58 +0000 Subject: (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. --- src/sort.c | 36 ++++++++++++++++++++---------------- 1 file 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 -- cgit v1.2.3-70-g09d2