@@ -18,7 +18,7 @@ struct tmp_objdir {
1818
1919/*
2020 * Allow only one tmp_objdir at a time in a running process, which simplifies
21- * our signal/ atexit cleanup routines. It's doubtful callers will ever need
21+ * our atexit cleanup routines. It's doubtful callers will ever need
2222 * more than one, and we can expand later if so. You can have many such
2323 * tmp_objdirs simultaneously in many processes, of course.
2424 */
@@ -31,7 +31,7 @@ static void tmp_objdir_free(struct tmp_objdir *t)
3131 free (t );
3232}
3333
34- static int tmp_objdir_destroy_1 (struct tmp_objdir * t , int on_signal )
34+ int tmp_objdir_destroy (struct tmp_objdir * t )
3535{
3636 int err ;
3737
@@ -41,44 +41,21 @@ static int tmp_objdir_destroy_1(struct tmp_objdir *t, int on_signal)
4141 if (t == the_tmp_objdir )
4242 the_tmp_objdir = NULL ;
4343
44- if (! on_signal && t -> prev_odb )
44+ if (t -> prev_odb )
4545 restore_primary_odb (t -> prev_odb , t -> path .buf );
4646
47- /*
48- * This may use malloc via strbuf_grow(), but we should
49- * have pre-grown t->path sufficiently so that this
50- * doesn't happen in practice.
51- */
5247 err = remove_dir_recursively (& t -> path , 0 );
5348
54- /*
55- * When we are cleaning up due to a signal, we won't bother
56- * freeing memory; it may cause a deadlock if the signal
57- * arrived while libc's allocator lock is held.
58- */
59- if (!on_signal )
60- tmp_objdir_free (t );
49+ tmp_objdir_free (t );
6150
6251 return err ;
6352}
6453
65- int tmp_objdir_destroy (struct tmp_objdir * t )
66- {
67- return tmp_objdir_destroy_1 (t , 0 );
68- }
69-
7054static void remove_tmp_objdir (void )
7155{
7256 tmp_objdir_destroy (the_tmp_objdir );
7357}
7458
75- static void remove_tmp_objdir_on_signal (int signo )
76- {
77- tmp_objdir_destroy_1 (the_tmp_objdir , 1 );
78- sigchain_pop (signo );
79- raise (signo );
80- }
81-
8259void tmp_objdir_discard_objects (struct tmp_objdir * t )
8360{
8461 remove_dir_recursively (& t -> path , REMOVE_DIR_KEEP_TOPLEVEL );
@@ -152,14 +129,6 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
152129 */
153130 strbuf_addf (& t -> path , "%s/tmp_objdir-%s-XXXXXX" , get_object_directory (), prefix );
154131
155- /*
156- * Grow the strbuf beyond any filename we expect to be placed in it.
157- * If tmp_objdir_destroy() is called by a signal handler, then
158- * we should be able to use the strbuf to remove files without
159- * having to call malloc.
160- */
161- strbuf_grow (& t -> path , 1024 );
162-
163132 if (!mkdtemp (t -> path .buf )) {
164133 /* free, not destroy, as we never touched the filesystem */
165134 tmp_objdir_free (t );
@@ -169,7 +138,6 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
169138 the_tmp_objdir = t ;
170139 if (!installed_handlers ) {
171140 atexit (remove_tmp_objdir );
172- sigchain_push_common (remove_tmp_objdir_on_signal );
173141 installed_handlers ++ ;
174142 }
175143
0 commit comments