]> sourceware.org Git - glibc.git/commitdiff
support: Delete temporary files in LIFO order
authorFlorian Weimer <fweimer@redhat.com>
Mon, 8 May 2017 12:32:58 +0000 (14:32 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Mon, 8 May 2017 13:54:10 +0000 (15:54 +0200)
This is required to remove temporary directories which contain
temporary files.  Previously, FIFO order meant that directory
removal was attempted when the directory still contained files,
which meant that temporary directory cleanup was essentially
unsupported.

ChangeLog
support/temp_file.c

index 4f09eeca9fc4525070ef55aeb99d22e8e71dba47..603587bc803f33d0d0647961d80940d3878d2d91 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2017-05-08  Florian Weimer  <fweimer@redhat.com>
+
+       Delete temporary files in LIFO order.
+       * support/temp_file.c (struct temp_name_list): Replace q member
+       with next.
+       (add_temp_file): Add new file to front of linked list.
+       (support_delete_temp_files): Use next member.
+       (support_print_temp_files): Likewise.
+
 2017-05-08  Florian Weimer  <fweimer@redhat.com>
 
        * sysdeps/unix/sysv/linux/Makefile (sysdep_headers): Remove
index 5950aec06b628080dd7373775db0b3cd9707448e..50cbae606bb60d10dfccb2d19928634cdb7a88ff 100644 (file)
@@ -25,7 +25,6 @@
 #include <support/support.h>
 
 #include <paths.h>
-#include <search.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -33,7 +32,7 @@
 /* List of temporary files.  */
 static struct temp_name_list
 {
-  struct qelem q;
+  struct temp_name_list *next;
   char *name;
 } *temp_name_list;
 
@@ -50,10 +49,8 @@ add_temp_file (const char *name)
   if (newname != NULL)
     {
       newp->name = newname;
-      if (temp_name_list == NULL)
-       temp_name_list = (struct temp_name_list *) &newp->q;
-      else
-       insque (newp, temp_name_list);
+      newp->next = temp_name_list;
+      temp_name_list = newp;
     }
   else
     free (newp);
@@ -105,8 +102,7 @@ support_delete_temp_files (void)
       (void) remove (temp_name_list->name);
       free (temp_name_list->name);
 
-      struct temp_name_list *next
-       = (struct temp_name_list *) temp_name_list->q.q_forw;
+      struct temp_name_list *next = temp_name_list->next;
       free (temp_name_list);
       temp_name_list = next;
     }
@@ -119,9 +115,7 @@ support_print_temp_files (FILE *f)
     {
       struct temp_name_list *n;
       fprintf (f, "temp_files=(\n");
-      for (n = temp_name_list;
-           n != NULL;
-           n = (struct temp_name_list *) n->q.q_forw)
+      for (n = temp_name_list; n != NULL; n = n->next)
         fprintf (f, "  '%s'\n", n->name);
       fprintf (f, ")\n");
     }
This page took 0.148352 seconds and 5 git commands to generate.