# fix potential deadlock in create_one_file

2 messages from 2006-01-05 to 2006-01-06. Participants: Alex Riesen, Junio C Hamano.
Thread: https://gitlist.dev/t/2971

## Alex Riesen, 2006-01-05 09:00

Subject: fix potential deadlock in create_one_file
Message-ID: <81b0412b0601050100v519e76c8u11f4d484f9d28e0a@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0601050100v519e76c8u11f4d484f9d28e0a%40mail.gmail.com

```
It can happen if the temporary file already exists (i.e. after a panic
and reboot).

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>


Subject: [PATCH] fix potential deadlock in create_one_file.

It can happen if the temporary file already exists.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>


---

 apply.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

f7ac9127638a013d0f1d60e02a06fde10909824c
diff --git a/apply.c b/apply.c
index d5e7bfd..ff3782b 100644
--- a/apply.c
+++ b/apply.c
@@ -1635,7 +1635,8 @@ static void create_one_file(const char *
 			}
 			if (errno != EEXIST)
 				break;
-		}			
+			++nr;
+		}
 	}
 	die("unable to write file %s mode %o", path, mode);
 }
-- 
1.0.GIT

```

## Junio C Hamano, 2006-01-06 22:38

Subject: Re: fix potential deadlock in create_one_file
Message-ID: <7vpsn5q8x6.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vpsn5q8x6.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <81b0412b0601050100v519e76c8u11f4d484f9d28e0a@mail.gmail.com>

```
Alex Riesen <raa.lkml@gmail.com> writes:

> It can happen if the temporary file already exists (i.e. after a panic
> and reboot).

We use pid here and using somebody else's pid feels wrong but
that is only for collision avoidance, mktemp(3) is no better,
and neither tmpfile(3) nor mkstemp(3) are usable for directories
anyway, so your patch as is would be the best solution.

Thanks.

```
