From: Phillip Wood Date: Tue, 27 Sep 2022 09:18:32 GMT Subject: Re: [PATCH] tmp-objdir: do not opendir() when handling a signal Message-ID: <99c45b89-364f-4f77-7c1b-26231cc7455e@dunelm.org.uk> In-Reply-To: Hi John On 27/09/2022 00:53, John Cai via GitGitGadget wrote: > From: John Cai > > In the tmp-objdir api, tmp_objdir_create will create a temporary > directory but also register signal handlers responsible for removing > the directory's contents and the directory itself. However, the > function responsible for recursively removing the contents and > directory, remove_dir_recurse() calls opendir(3) and closedir(3). > This can be problematic because these functions allocate and free > memory, which are not async-signal-safe functions. This can lead to > deadlocks. > --- a/dir.h > +++ b/dir.h > @@ -498,6 +498,9 @@ int get_sparse_checkout_patterns(struct pattern_list *pl); > /* Remove the_original_cwd too */ > #define REMOVE_DIR_PURGE_ORIGINAL_CWD 0x08 > > +/* Indicates a signal is being handled */ > +#define REMOVE_DIR_SIGNAL 0x16 This is setting the bits for REMOVE_DIR_KEEP_NESTED_GIT and REMOVE_DIR_KEEP_TOPLEVEL is that intentional? (it looks like you've doubled 8 to 16 to get the next free bit but used a hex constant, the earlier constants use decimal) Best Wishes Phillip