[patch] munmap-before-rename, cygwin need
From: Yakov Lerner <hidden>
Date: 2016-06-15 22:42:25
I found that mmap() works on cygwin, but needs a patch. On Cygwin, rename() fails if target file has active mmap(). The patch below adds munmap() before rename(). If you excuse me for posting not in git-generated format (I did not yet completely make git working on my cygwin). I'm adding the copy as attachment, I'm afraid the mailer may interfere with spaces ? Yakov Lerner Makefile | 5 +++++ cache.h | 1 + index.c | 3 +++ read-cache.c | 14 ++++++++++++++
--- Makefile.000 2006-05-07 22:32:04.000000000 +0300
+++ Makefile 2006-05-07 22:30:38.000000000 +0300@@ -46,6 +46,9 @@# # Define NO_MMAP if you want to avoid mmap. # +# Define MUMNAP_BEFORE_RENAME if munmap() on target file is required +# before rename(). +# # Define WITH_OWN_SUBPROCESS_PY if you want to use with python 2.3. # # Define NO_IPV6 if you lack IPv6 support and getaddrinfo().
@@ -270,6 +273,8 @@# NO_MMAP = YesPlease NO_IPV6 = YesPlease X = .exe + MUMNAP_BEFORE_RENAME = YesPlease + NO_SOCKADDR_STORAGE = YesPlease endif ifeq ($(uname_S),FreeBSD) NEEDS_LIBICONV = YesPlease
--- cache.h.000 2006-05-02 11:35:50.000000000 +0300
+++ cache.h 2006-05-02 11:33:34.000000000 +0300@@ -140,6 +140,7 @@
/* Initialize and use the cache information */ extern int read_cache(void); +extern void unmap_cache(void); extern int write_cache(int newfd, struct cache_entry **cache, int entries); extern int cache_name_pos(const char *name, int namelen); #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */
--- read-cache.c.000 2006-05-07 22:33:42.000000000 +0300
+++ read-cache.c 2006-05-02 11:32:56.000000000 +0300@@ -513,6 +513,9 @@return 0;
}
+static void *mapaddr = MAP_FAILED;
+static unsigned long mapsize;
+
int read_cache(void)
{
int fd, i;@@ -541,6 +544,8 @@errno = EINVAL; if (size >= sizeof(struct cache_header) + 20) map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); + mapaddr = map; + mapsize = size; } close(fd); if (map == MAP_FAILED)
@@ -565,10 +570,19 @@
unmap:
munmap(map, size);
+ mapaddr = MAP_FAILED;
errno = EINVAL;
die("index file corrupt");
}
+void unmap_cache(void)
+{
+ if ( mapaddr != MAP_FAILED ) {
+ munmap(mapaddr, mapsize);
+ mapaddr = MAP_FAILED;
+ }
+}
+
#define WRITE_BUFFER_SIZE 8192
static unsigned char write_buffer[WRITE_BUFFER_SIZE];
static unsigned long write_buffer_len;--- index.c.000 2006-05-07 22:36:04.000000000 +0300
+++ index.c 2006-05-07 22:36:40.000000000 +0300@@ -43,6 +43,9 @@strcpy(indexfile, cf->lockfile); i = strlen(indexfile) - 5; /* .lock */ indexfile[i] = 0; +#ifdef MUMNAP_BEFORE_RENAME + unmap_cache(); +#endif i = rename(cf->lockfile, indexfile); cf->lockfile[0] = 0; return i;
Attachments
- patch-munmap-before-rename [text/plain] 2237 bytes · preview