[PATCH] hold_index_file_for_update should not unlink failed to open .lock files atexit
Set up atexit only if the .lock-file was opened successfully. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Alex Riesen committed
Oct 5, 2005 at 16:58 UTC
d6e548d61fa95b98e98b3c1e592a4d73aa308969
1 file changed
+6
-4
index.c
+6
-4
@@ -22,14 +22,16 @@ static void remove_lock_file_on_signal(int signo)
22
23
int hold_index_file_for_update(struct cache_file *cf, const char *path)
24
{
25
+ int fd;
26
sprintf(cf->lockfile, "%s.lock", path);
26
- cf->next = cache_file_list;
27
- cache_file_list = cf;
28
- if (!cf->next) {
27
+ fd = open(cf->lockfile, O_RDWR | O_CREAT | O_EXCL, 0666);
28
+ if (fd >=0 && !cf->next) {
29
+ cf->next = cache_file_list;
30
+ cache_file_list = cf;
31
signal(SIGINT, remove_lock_file_on_signal);
32
atexit(remove_lock_file);
33
}
32
- return open(cf->lockfile, O_RDWR | O_CREAT | O_EXCL, 0666);
34
+ return fd;
35
}
36
37
int commit_index_file(struct cache_file *cf)