[PATCH v5] Handle atexit list internaly for unthreaded builds

2014-10-18 Thread Etienne Buira
Wrap atexit()s calls on unthreaded builds to handle callback list
internally.

This is needed because on unthreaded builds, asyncs inherits parent's
atexit() list, that gets run as soon as the async exit()s (and again at
the end of async's parent process). That led to remove temporary files
too early.

Also remove a by-atexit-callback guard against this kind of issue in
clone.c, as this patch makes it redundant.

Fixes test 5537 (temporary shallow file vanished before unpack-objects
could open it)

BTW remove an unused variable in shallow.c.

Helped-by: Duy Nguyen pclo...@gmail.com
Helped-by: Andreas Schwab sch...@linux-m68k.org
Helped-by: Junio C Hamano gits...@pobox.com
Signed-off-by: Etienne Buira etienne.bu...@gmail.com
---
 builtin/clone.c   |  5 -
 git-compat-util.h |  5 +
 run-command.c | 40 
 shallow.c |  7 ++-
 4 files changed, 47 insertions(+), 10 deletions(-)

V5: update commit message

diff --git a/builtin/clone.c b/builtin/clone.c
index bbd169c..e122f33 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -390,7 +390,6 @@ static void clone_local(const char *src_repo, const char 
*dest_repo)
 
 static const char *junk_work_tree;
 static const char *junk_git_dir;
-static pid_t junk_pid;
 static enum {
JUNK_LEAVE_NONE,
JUNK_LEAVE_REPO,
@@ -417,8 +416,6 @@ static void remove_junk(void)
break;
}
 
-   if (getpid() != junk_pid)
-   return;
if (junk_git_dir) {
strbuf_addstr(sb, junk_git_dir);
remove_dir_recursively(sb, 0);
@@ -758,8 +755,6 @@ int cmd_clone(int argc, const char **argv, const char 
*prefix)
struct refspec *refspec;
const char *fetch_pattern;
 
-   junk_pid = getpid();
-
packet_trace_identity(clone);
argc = parse_options(argc, argv, prefix, builtin_clone_options,
 builtin_clone_usage, 0);
diff --git a/git-compat-util.h b/git-compat-util.h
index f587749..6dd63dd 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -577,6 +577,11 @@ int inet_pton(int af, const char *src, void *dst);
 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
 #endif
 
+#ifdef NO_PTHREADS
+#define atexit git_atexit
+extern int git_atexit(void (*handler)(void));
+#endif
+
 extern void release_pack_memory(size_t);
 
 typedef void (*try_to_free_t)(size_t);
diff --git a/run-command.c b/run-command.c
index 35a3ebf..0f9a9b0 100644
--- a/run-command.c
+++ b/run-command.c
@@ -624,6 +624,45 @@ static int async_die_is_recursing(void)
return ret != NULL;
 }
 
+#else
+
+static struct {
+   void (**handlers)(void);
+   size_t nr;
+   size_t alloc;
+} git_atexit_hdlrs;
+
+static int git_atexit_installed;
+
+static void git_atexit_dispatch()
+{
+   size_t i;
+
+   for (i=git_atexit_hdlrs.nr ; i ; i--)
+   git_atexit_hdlrs.handlers[i-1]();
+}
+
+static void git_atexit_clear()
+{
+   free(git_atexit_hdlrs.handlers);
+   memset(git_atexit_hdlrs, 0, sizeof(git_atexit_hdlrs));
+   git_atexit_installed = 0;
+}
+
+#undef atexit
+int git_atexit(void (*handler)(void))
+{
+   ALLOC_GROW(git_atexit_hdlrs.handlers, git_atexit_hdlrs.nr + 1, 
git_atexit_hdlrs.alloc);
+   git_atexit_hdlrs.handlers[git_atexit_hdlrs.nr++] = handler;
+   if (!git_atexit_installed) {
+   if (atexit(git_atexit_dispatch))
+   return -1;
+   git_atexit_installed = 1;
+   }
+   return 0;
+}
+#define atexit git_atexit
+
 #endif
 
 int start_async(struct async *async)
@@ -682,6 +721,7 @@ int start_async(struct async *async)
close(fdin[1]);
if (need_out)
close(fdout[0]);
+   git_atexit_clear();
exit(!!async-proc(proc_in, proc_out, async-data));
}
 
diff --git a/shallow.c b/shallow.c
index de07709..f067811 100644
--- a/shallow.c
+++ b/shallow.c
@@ -226,7 +226,6 @@ static void remove_temporary_shallow_on_signal(int signo)
 
 const char *setup_temporary_shallow(const struct sha1_array *extra)
 {
-   static int installed_handler;
struct strbuf sb = STRBUF_INIT;
int fd;
 
@@ -237,10 +236,8 @@ const char *setup_temporary_shallow(const struct 
sha1_array *extra)
strbuf_addstr(temporary_shallow, git_path(shallow_XX));
fd = xmkstemp(temporary_shallow.buf);
 
-   if (!installed_handler) {
-   atexit(remove_temporary_shallow);
-   
sigchain_push_common(remove_temporary_shallow_on_signal);
-   }
+   atexit(remove_temporary_shallow);
+   sigchain_push_common(remove_temporary_shallow_on_signal);
 
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
die_errno(failed to write to %s,
-- 
2.0.4

--
To unsubscribe from this list: send the line

Re: [PATCH 2/2] Remove spurious 'no threads support' warnings

2014-10-14 Thread Etienne Buira
On Mon, Oct 13, 2014 at 9:54 PM, Junio C Hamano gits...@pobox.com wrote:
 Etienne Buira etienne.bu...@gmail.com writes:

 Threads count being defaulted to 0 (autodetect), and --disable-pthreads
 build checking that thread count==1, there were spurious warnings about
 threads being ignored, despite not specified on command line/conf.

 Fixes tests 5521 and 5526 that were broken in --disable-pthreads builds
 because of those warnings.

 Signed-off-by: Etienne Buira etienne.bu...@gmail.com
 ---

 I am not sure if this is the right fix.

 Shouldn't a --threads=0 from the command line (when there is a
 pack.threads configuration hardcoding some number to override it)
 give a chance to the auto detection codepath to ask online_cpus()
 and receive 1 on NO_PTHREADS build to avoid triggering the same
 warning you are squelching with this patch?

 That is, something like this instead, perhaps?

Indeed, your patch is better.

 -- 8 --
 Subject: [PATCH] pack-objects: set number of threads before checking and 
 warning

 Under NO_PTHREADS build, we warn when delta_search_threads is not
 set to 1, because that is the only sensible value on a single
 threaded build.

 However, the auto detection that kicks in when that variable is set
 to 0 (e.g. there is no configuration variable or command line option,
 or an explicit --threads=0 is given from the command line to override
 the pack.threads configuration to force auto-detection) was not done
 before the condition to issue this warning was tested.

 Move the auto-detection code and place it at an appropriate spot.

 Signed-off-by: Junio C Hamano gits...@pobox.com
 ---
  builtin/pack-objects.c | 6 --
  thread-utils.h | 4 
  2 files changed, 8 insertions(+), 2 deletions(-)

 diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
 index d391934..a715237 100644
 --- a/builtin/pack-objects.c
 +++ b/builtin/pack-objects.c
 @@ -1972,8 +1972,6 @@ static void ll_find_deltas(struct object_entry **list, 
 unsigned list_size,

 init_threaded_search();

 -   if (!delta_search_threads)  /* --threads=0 means autodetect */
 -   delta_search_threads = online_cpus();
 if (delta_search_threads = 1) {
 find_deltas(list, list_size, window, depth, processed);
 cleanup_threaded_search();
 @@ -2685,6 +2683,10 @@ int cmd_pack_objects(int argc, const char **argv, 
 const char *prefix)
 pack_compression_level = Z_DEFAULT_COMPRESSION;
 else if (pack_compression_level  0 || pack_compression_level  
 Z_BEST_COMPRESSION)
 die(bad pack compression level %d, pack_compression_level);
 +
 +   if (!delta_search_threads)  /* --threads=0 means autodetect */
 +   delta_search_threads = online_cpus();
 +
  #ifdef NO_PTHREADS
 if (delta_search_threads != 1)
 warning(no threads support, ignoring --threads);
 diff --git a/thread-utils.h b/thread-utils.h
 index 6fb98c3..d9a769d 100644
 --- a/thread-utils.h
 +++ b/thread-utils.h
 @@ -7,5 +7,9 @@
  extern int online_cpus(void);
  extern int init_recursive_mutex(pthread_mutex_t*);

 +#else
 +
 +#define online_cpus() 1
 +
  #endif
  #endif /* THREAD_COMPAT_H */
 --
 2.1.2-468-g1a77c5b

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] Handle atexit list internaly for unthreaded builds

2014-10-14 Thread Etienne Buira
On Mon, Oct 13, 2014 at 10:00 PM, Junio C Hamano gits...@pobox.com wrote:
 Etienne Buira etienne.bu...@gmail.com writes:

 Wrap atexit()s calls on unthreaded builds to handle callback list
 internally.

 This is needed because on unthreaded builds, asyncs inherits parent's
 atexit() list, that gets run as soon as the async exit()s (and again at
 the end of the parent process). That led to remove temporary and lock
 files too early.

 ... that does not explain what you did to builtin/clone.c at all.
 Care to enlighten us, please?

Checking current pid against the one that registered the atexit()
routine (what builtin/clone.c currently does) is another way to guard
against the same issue, but it needs to store a pid for each atexit()
call whenever code called after might use async.
From what I've seen, two out of all atexit() calls were guarded like that:
- builtin/clone.c:cmd_clone
- lockfile.c:lock_file (overlooked it at first, would you mind to
s/temporary and lock files/temporary files/ the commit message if no
other round is needed? I'll do it otherwise).

So the changes in builtin/clone.c are just there because the patch
makes this check redundant (still needed in lockfile.c, as it loops
over a list that might refer to parent process's lockfiles).

 Fixes test 5537 (temporary shallow file vanished before unpack-objects
 could open it)

 V4: fix bogus preprocessor directives

 Please do not write this V4: line in the log message.  People who
 read git log output and find this description would not know
 anything about the previous faulty ones.  Putting it _after_ the
 three-dash line below will help the reviewers a lot.


 Thanks-to: Duy Nguyen pclo...@gmail.com
 Thanks-to: Andreas Schwab sch...@linux-m68k.org

 Usually we spell these Helped-by:  instead.

 Signed-off-by: Etienne Buira etienne.bu...@gmail.com
 ---

 Thanks.

  builtin/clone.c   |  5 -
  git-compat-util.h |  5 +
  run-command.c | 40 
  shallow.c |  7 ++-
  4 files changed, 47 insertions(+), 10 deletions(-)

 diff --git a/builtin/clone.c b/builtin/clone.c
 index bbd169c..e122f33 100644
 --- a/builtin/clone.c
 +++ b/builtin/clone.c
 @@ -390,7 +390,6 @@ static void clone_local(const char *src_repo, const char 
 *dest_repo)

  static const char *junk_work_tree;
  static const char *junk_git_dir;
 -static pid_t junk_pid;
  static enum {
   JUNK_LEAVE_NONE,
   JUNK_LEAVE_REPO,
 @@ -417,8 +416,6 @@ static void remove_junk(void)
   break;
   }

 - if (getpid() != junk_pid)
 - return;
   if (junk_git_dir) {
   strbuf_addstr(sb, junk_git_dir);
   remove_dir_recursively(sb, 0);
 @@ -758,8 +755,6 @@ int cmd_clone(int argc, const char **argv, const char 
 *prefix)
   struct refspec *refspec;
   const char *fetch_pattern;

 - junk_pid = getpid();
 -
   packet_trace_identity(clone);
   argc = parse_options(argc, argv, prefix, builtin_clone_options,
builtin_clone_usage, 0);
 diff --git a/git-compat-util.h b/git-compat-util.h
 index f587749..6dd63dd 100644
 --- a/git-compat-util.h
 +++ b/git-compat-util.h
 @@ -577,6 +577,11 @@ int inet_pton(int af, const char *src, void *dst);
  const char *inet_ntop(int af, const void *src, char *dst, size_t size);
  #endif

 +#ifdef NO_PTHREADS
 +#define atexit git_atexit
 +extern int git_atexit(void (*handler)(void));
 +#endif
 +
  extern void release_pack_memory(size_t);

  typedef void (*try_to_free_t)(size_t);
 diff --git a/run-command.c b/run-command.c
 index 35a3ebf..0f9a9b0 100644
 --- a/run-command.c
 +++ b/run-command.c
 @@ -624,6 +624,45 @@ static int async_die_is_recursing(void)
   return ret != NULL;
  }

 +#else
 +
 +static struct {
 + void (**handlers)(void);
 + size_t nr;
 + size_t alloc;
 +} git_atexit_hdlrs;
 +
 +static int git_atexit_installed;
 +
 +static void git_atexit_dispatch()
 +{
 + size_t i;
 +
 + for (i=git_atexit_hdlrs.nr ; i ; i--)
 + git_atexit_hdlrs.handlers[i-1]();
 +}
 +
 +static void git_atexit_clear()
 +{
 + free(git_atexit_hdlrs.handlers);
 + memset(git_atexit_hdlrs, 0, sizeof(git_atexit_hdlrs));
 + git_atexit_installed = 0;
 +}
 +
 +#undef atexit
 +int git_atexit(void (*handler)(void))
 +{
 + ALLOC_GROW(git_atexit_hdlrs.handlers, git_atexit_hdlrs.nr + 1, 
 git_atexit_hdlrs.alloc);
 + git_atexit_hdlrs.handlers[git_atexit_hdlrs.nr++] = handler;
 + if (!git_atexit_installed) {
 + if (atexit(git_atexit_dispatch))
 + return -1;
 + git_atexit_installed = 1;
 + }
 + return 0;
 +}
 +#define atexit git_atexit
 +
  #endif

  int start_async(struct async *async)
 @@ -682,6 +721,7 @@ int start_async(struct async *async)
   close(fdin[1]);
   if (need_out)
   close(fdout[0]);
 + git_atexit_clear();
   exit(!!async-proc(proc_in

Re: [PATCH v2] Handle atexit list internaly for unthreaded builds

2014-10-13 Thread Etienne Buira
On Mon, Oct 13, 2014 at 2:56 AM, Duy Nguyen pclo...@gmail.com wrote:
 On Sun, Oct 12, 2014 at 4:09 PM, Etienne Buira etienne.bu...@gmail.com 
 wrote:
  Replace atexit()s calls with cmd_atexit that is atexit() on threaded
  builds, but handles the callbacks list internally for unthreaded builds.
 
 Maybe hide this in git-compat-util.h and #define atexit(x)
 cmd_atexit(x)?

Updated.

 cmd_ is usually for commands' main functions. Maybe
 rename it to git_atexit().

Indeed, renamed. Thank you.

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] Handle atexit list internaly for unthreaded builds

2014-10-13 Thread Etienne Buira
Wrap atexit()s calls on unthreaded builds to handle callback list
internally.

This is needed because on unthreaded builds, asyncs inherits parent's
atexit() list, that gets run as soon as the async exit()s (and again at
the end of the parent process). That led to remove temporary and lock
files too early.

Fixes test 5537 (temporary shallow file vanished before unpack-objects
could open it)

V2: remove an obvious mistake
V3: wrap, rename and add define in git-compat-util.h

Thanks-to: Duy Nguyen pclo...@gmail.com
Signed-off-by: Etienne Buira etienne.bu...@gmail.com
---
 builtin/clone.c   |  5 -
 git-compat-util.h |  5 +
 run-command.c | 42 ++
 shallow.c |  7 ++-
 4 files changed, 49 insertions(+), 10 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index bbd169c..e122f33 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -390,7 +390,6 @@ static void clone_local(const char *src_repo, const char 
*dest_repo)
 
 static const char *junk_work_tree;
 static const char *junk_git_dir;
-static pid_t junk_pid;
 static enum {
JUNK_LEAVE_NONE,
JUNK_LEAVE_REPO,
@@ -417,8 +416,6 @@ static void remove_junk(void)
break;
}
 
-   if (getpid() != junk_pid)
-   return;
if (junk_git_dir) {
strbuf_addstr(sb, junk_git_dir);
remove_dir_recursively(sb, 0);
@@ -758,8 +755,6 @@ int cmd_clone(int argc, const char **argv, const char 
*prefix)
struct refspec *refspec;
const char *fetch_pattern;
 
-   junk_pid = getpid();
-
packet_trace_identity(clone);
argc = parse_options(argc, argv, prefix, builtin_clone_options,
 builtin_clone_usage, 0);
diff --git a/git-compat-util.h b/git-compat-util.h
index f587749..6dd63dd 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -577,6 +577,11 @@ int inet_pton(int af, const char *src, void *dst);
 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
 #endif
 
+#ifdef NO_PTHREADS
+#define atexit git_atexit
+extern int git_atexit(void (*handler)(void));
+#endif
+
 extern void release_pack_memory(size_t);
 
 typedef void (*try_to_free_t)(size_t);
diff --git a/run-command.c b/run-command.c
index 35a3ebf..f8dc969 100644
--- a/run-command.c
+++ b/run-command.c
@@ -624,6 +624,47 @@ static int async_die_is_recursing(void)
return ret != NULL;
 }
 
+#else
+
+static struct {
+   void (**handlers)(void);
+   size_t nr;
+   size_t alloc;
+} git_atexit_hdlrs;
+
+static int git_atexit_installed;
+
+static void git_atexit_dispatch()
+{
+   size_t i;
+
+   for (i=git_atexit_hdlrs.nr ; i ; i--)
+   git_atexit_hdlrs.handlers[i-1]();
+}
+
+static void git_atexit_clear()
+{
+   free(git_atexit_hdlrs.handlers);
+   memset(git_atexit_hdlrs, 0, sizeof(git_atexit_hdlrs));
+   git_atexit_installed = 0;
+}
+
+#define tmp_atexit atexit
+#undef atexit
+int git_atexit(void (*handler)(void))
+{
+   ALLOC_GROW(git_atexit_hdlrs.handlers, git_atexit_hdlrs.nr + 1, 
git_atexit_hdlrs.alloc);
+   git_atexit_hdlrs.handlers[git_atexit_hdlrs.nr++] = handler;
+   if (!git_atexit_installed) {
+   if (atexit(git_atexit_dispatch))
+   return -1;
+   git_atexit_installed = 1;
+   }
+   return 0;
+}
+#define atexit tmp_atexit
+#undef tmp_atexit
+
 #endif
 
 int start_async(struct async *async)
@@ -682,6 +723,7 @@ int start_async(struct async *async)
close(fdin[1]);
if (need_out)
close(fdout[0]);
+   git_atexit_clear();
exit(!!async-proc(proc_in, proc_out, async-data));
}
 
diff --git a/shallow.c b/shallow.c
index de07709..f067811 100644
--- a/shallow.c
+++ b/shallow.c
@@ -226,7 +226,6 @@ static void remove_temporary_shallow_on_signal(int signo)
 
 const char *setup_temporary_shallow(const struct sha1_array *extra)
 {
-   static int installed_handler;
struct strbuf sb = STRBUF_INIT;
int fd;
 
@@ -237,10 +236,8 @@ const char *setup_temporary_shallow(const struct 
sha1_array *extra)
strbuf_addstr(temporary_shallow, git_path(shallow_XX));
fd = xmkstemp(temporary_shallow.buf);
 
-   if (!installed_handler) {
-   atexit(remove_temporary_shallow);
-   
sigchain_push_common(remove_temporary_shallow_on_signal);
-   }
+   atexit(remove_temporary_shallow);
+   sigchain_push_common(remove_temporary_shallow_on_signal);
 
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
die_errno(failed to write to %s,
-- 
2.0.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4] Handle atexit list internaly for unthreaded builds

2014-10-13 Thread Etienne Buira
Wrap atexit()s calls on unthreaded builds to handle callback list
internally.

This is needed because on unthreaded builds, asyncs inherits parent's
atexit() list, that gets run as soon as the async exit()s (and again at
the end of the parent process). That led to remove temporary and lock
files too early.

Fixes test 5537 (temporary shallow file vanished before unpack-objects
could open it)

V4: fix bogus preprocessor directives

Thanks-to: Duy Nguyen pclo...@gmail.com
Thanks-to: Andreas Schwab sch...@linux-m68k.org
Signed-off-by: Etienne Buira etienne.bu...@gmail.com
---
 builtin/clone.c   |  5 -
 git-compat-util.h |  5 +
 run-command.c | 40 
 shallow.c |  7 ++-
 4 files changed, 47 insertions(+), 10 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index bbd169c..e122f33 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -390,7 +390,6 @@ static void clone_local(const char *src_repo, const char 
*dest_repo)
 
 static const char *junk_work_tree;
 static const char *junk_git_dir;
-static pid_t junk_pid;
 static enum {
JUNK_LEAVE_NONE,
JUNK_LEAVE_REPO,
@@ -417,8 +416,6 @@ static void remove_junk(void)
break;
}
 
-   if (getpid() != junk_pid)
-   return;
if (junk_git_dir) {
strbuf_addstr(sb, junk_git_dir);
remove_dir_recursively(sb, 0);
@@ -758,8 +755,6 @@ int cmd_clone(int argc, const char **argv, const char 
*prefix)
struct refspec *refspec;
const char *fetch_pattern;
 
-   junk_pid = getpid();
-
packet_trace_identity(clone);
argc = parse_options(argc, argv, prefix, builtin_clone_options,
 builtin_clone_usage, 0);
diff --git a/git-compat-util.h b/git-compat-util.h
index f587749..6dd63dd 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -577,6 +577,11 @@ int inet_pton(int af, const char *src, void *dst);
 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
 #endif
 
+#ifdef NO_PTHREADS
+#define atexit git_atexit
+extern int git_atexit(void (*handler)(void));
+#endif
+
 extern void release_pack_memory(size_t);
 
 typedef void (*try_to_free_t)(size_t);
diff --git a/run-command.c b/run-command.c
index 35a3ebf..0f9a9b0 100644
--- a/run-command.c
+++ b/run-command.c
@@ -624,6 +624,45 @@ static int async_die_is_recursing(void)
return ret != NULL;
 }
 
+#else
+
+static struct {
+   void (**handlers)(void);
+   size_t nr;
+   size_t alloc;
+} git_atexit_hdlrs;
+
+static int git_atexit_installed;
+
+static void git_atexit_dispatch()
+{
+   size_t i;
+
+   for (i=git_atexit_hdlrs.nr ; i ; i--)
+   git_atexit_hdlrs.handlers[i-1]();
+}
+
+static void git_atexit_clear()
+{
+   free(git_atexit_hdlrs.handlers);
+   memset(git_atexit_hdlrs, 0, sizeof(git_atexit_hdlrs));
+   git_atexit_installed = 0;
+}
+
+#undef atexit
+int git_atexit(void (*handler)(void))
+{
+   ALLOC_GROW(git_atexit_hdlrs.handlers, git_atexit_hdlrs.nr + 1, 
git_atexit_hdlrs.alloc);
+   git_atexit_hdlrs.handlers[git_atexit_hdlrs.nr++] = handler;
+   if (!git_atexit_installed) {
+   if (atexit(git_atexit_dispatch))
+   return -1;
+   git_atexit_installed = 1;
+   }
+   return 0;
+}
+#define atexit git_atexit
+
 #endif
 
 int start_async(struct async *async)
@@ -682,6 +721,7 @@ int start_async(struct async *async)
close(fdin[1]);
if (need_out)
close(fdout[0]);
+   git_atexit_clear();
exit(!!async-proc(proc_in, proc_out, async-data));
}
 
diff --git a/shallow.c b/shallow.c
index de07709..f067811 100644
--- a/shallow.c
+++ b/shallow.c
@@ -226,7 +226,6 @@ static void remove_temporary_shallow_on_signal(int signo)
 
 const char *setup_temporary_shallow(const struct sha1_array *extra)
 {
-   static int installed_handler;
struct strbuf sb = STRBUF_INIT;
int fd;
 
@@ -237,10 +236,8 @@ const char *setup_temporary_shallow(const struct 
sha1_array *extra)
strbuf_addstr(temporary_shallow, git_path(shallow_XX));
fd = xmkstemp(temporary_shallow.buf);
 
-   if (!installed_handler) {
-   atexit(remove_temporary_shallow);
-   
sigchain_push_common(remove_temporary_shallow_on_signal);
-   }
+   atexit(remove_temporary_shallow);
+   sigchain_push_common(remove_temporary_shallow_on_signal);
 
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
die_errno(failed to write to %s,
-- 
2.0.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] Handle atexit list internaly fo unthreaded builds

2014-10-12 Thread Etienne Buira
Replace atexit()s calls with cmd_atexit that is atexit() on threaded
builds, but handles the callbacks list internally for unthreaded builds.

This is needed because on unthreaded builds, asyncs inherits parent's
atexit() list, that gets run as soon as the async exit()s (and again at
the end of the parent process). That led to remove temporary and lock
files too early.

Fixes test 5537 (temporary shallow file vanished before unpack-objects
could open it)

V2: remove an obvious mistake

Signed-off-by: Etienne Buira etienne.bu...@gmail.com
---
 builtin/clone.c |  7 +--
 builtin/fetch.c |  2 +-
 builtin/gc.c|  2 +-
 diff.c  |  2 +-
 lockfile.c  |  2 +-
 pager.c |  2 +-
 read-cache.c|  2 +-
 run-command.c   | 45 -
 shallow.c   |  7 ++-
 trace.c |  2 +-
 10 files changed, 54 insertions(+), 19 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index bbd169c..2992ac0 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -390,7 +390,6 @@ static void clone_local(const char *src_repo, const char 
*dest_repo)
 
 static const char *junk_work_tree;
 static const char *junk_git_dir;
-static pid_t junk_pid;
 static enum {
JUNK_LEAVE_NONE,
JUNK_LEAVE_REPO,
@@ -417,8 +416,6 @@ static void remove_junk(void)
break;
}
 
-   if (getpid() != junk_pid)
-   return;
if (junk_git_dir) {
strbuf_addstr(sb, junk_git_dir);
remove_dir_recursively(sb, 0);
@@ -758,8 +755,6 @@ int cmd_clone(int argc, const char **argv, const char 
*prefix)
struct refspec *refspec;
const char *fetch_pattern;
 
-   junk_pid = getpid();
-
packet_trace_identity(clone);
argc = parse_options(argc, argv, prefix, builtin_clone_options,
 builtin_clone_usage, 0);
@@ -843,7 +838,7 @@ int cmd_clone(int argc, const char **argv, const char 
*prefix)
set_git_work_tree(work_tree);
}
junk_git_dir = git_dir;
-   atexit(remove_junk);
+   cmd_atexit(remove_junk);
sigchain_push_common(remove_junk_on_signal);
 
if (safe_create_leading_directories_const(git_dir)  0)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 159fb7e..1e44d58 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1095,7 +1095,7 @@ static int fetch_one(struct remote *remote, int argc, 
const char **argv)
}
 
sigchain_push_common(unlock_pack_on_signal);
-   atexit(unlock_pack);
+   cmd_atexit(unlock_pack);
refspec = parse_fetch_refspec(ref_nr, refs);
exit_code = do_fetch(gtransport, refspec, ref_nr);
free_refspec(ref_nr, refspec);
diff --git a/builtin/gc.c b/builtin/gc.c
index 8d219d8..cf2defa 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -254,7 +254,7 @@ static const char *lock_repo_for_gc(int force, pid_t* 
ret_pid)
 
pidfile = git_pathdup(gc.pid);
sigchain_push_common(remove_pidfile_on_signal);
-   atexit(remove_pidfile);
+   cmd_atexit(remove_pidfile);
 
return NULL;
 }
diff --git a/diff.c b/diff.c
index 867f034..9c6ef9a 100644
--- a/diff.c
+++ b/diff.c
@@ -2833,7 +2833,7 @@ static struct diff_tempfile *prepare_temp_file(const char 
*name,
}
 
if (!remove_tempfile_installed) {
-   atexit(remove_tempfile);
+   cmd_atexit(remove_tempfile);
sigchain_push_common(remove_tempfile_on_signal);
remove_tempfile_installed = 1;
}
diff --git a/lockfile.c b/lockfile.c
index 2564a7f..ad0d1e2 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -141,7 +141,7 @@ static int lock_file(struct lock_file *lk, const char 
*path, int flags)
if (0 = lk-fd) {
if (!lock_file_list) {
sigchain_push_common(remove_lock_file_on_signal);
-   atexit(remove_lock_file);
+   cmd_atexit(remove_lock_file);
}
lk-owner = getpid();
if (!lk-on_list) {
diff --git a/pager.c b/pager.c
index 8b5cbc5..09ab2fa 100644
--- a/pager.c
+++ b/pager.c
@@ -102,7 +102,7 @@ void setup_pager(void)
 
/* this makes sure that the parent terminates after the pager */
sigchain_push_common(wait_for_pager_signal);
-   atexit(wait_for_pager);
+   cmd_atexit(wait_for_pager);
 }
 
 int pager_in_use(void)
diff --git a/read-cache.c b/read-cache.c
index 6f0057f..8b10c92 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2104,7 +2104,7 @@ static int write_shared_index(struct index_state *istate,
return do_write_locked_index(istate, lock, flags);
}
if (!installed_handler) {
-   atexit(remove_temporary_sharedindex);
+   cmd_atexit(remove_temporary_sharedindex);
sigchain_push_common(remove_temporary_sharedindex_on_signal);
}
move_cache_to_base_index(istate);
diff --git

[PATCH 1/2] fix compilation with --disable-pthreads

2014-10-11 Thread Etienne Buira
Signed-off-by: Etienne Buira etienne.bu...@gmail.com
---
 builtin/index-pack.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index eebf1a8..0f88f4b 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -185,6 +185,9 @@ static void cleanup_thread(void)
 #define deepest_delta_lock()
 #define deepest_delta_unlock()
 
+#define type_cas_lock()
+#define type_cas_unlock()
+
 #endif
 
 
-- 
1.8.5.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] Remove spurious 'no threads support' warnings

2014-10-11 Thread Etienne Buira
Threads count being defaulted to 0 (autodetect), and --disable-pthreads
build checking that thread count==1, there were spurious warnings about
threads being ignored, despite not specified on command line/conf.

Fixes tests 5521 and 5526 that were broken in --disable-pthreads builds
because of those warnings.

Signed-off-by: Etienne Buira etienne.bu...@gmail.com
---
 builtin/pack-objects.c | 2 +-
 thread-utils.h | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index b59f5d8..7b51453 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -51,7 +51,7 @@ static int progress = 1;
 static int window = 10;
 static unsigned long pack_size_limit;
 static int depth = 50;
-static int delta_search_threads;
+static int delta_search_threads = THREAD_COMPAT_DEFAULT_THREAD_NBR;
 static int pack_to_stdout;
 static int num_preferred_base;
 static struct progress *progress_state;
diff --git a/thread-utils.h b/thread-utils.h
index 6fb98c3..4f5e802 100644
--- a/thread-utils.h
+++ b/thread-utils.h
@@ -7,5 +7,8 @@
 extern int online_cpus(void);
 extern int init_recursive_mutex(pthread_mutex_t*);
 
+#define THREAD_COMPAT_DEFAULT_THREAD_NBR 0
+#else
+#define THREAD_COMPAT_DEFAULT_THREAD_NBR 1
 #endif
 #endif /* THREAD_COMPAT_H */
-- 
1.8.5.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Handle atexit list internaly fo unthreaded builds

2014-10-11 Thread Etienne Buira
Replace atexit()s calls with cmd_atexit that is atexit() on threaded
builds, but handles the callbacks list internally for unthreaded builds.

This is needed because on unthreaded builds, asyncs inherits parent's
atexit() list, that gets run as soon as the async exit()s (and again at
the end of the parent process). That led to remove temporary and lock
files too early.

Fixes test 5537 (temporary shallow file vanished before unpack-objects
could open it)

Signed-off-by: Etienne Buira etienne.bu...@gmail.com
---
 builtin/clone.c |  7 +--
 builtin/fetch.c |  2 +-
 builtin/gc.c|  2 +-
 diff.c  |  2 +-
 lockfile.c  |  2 +-
 pager.c |  2 +-
 read-cache.c|  2 +-
 run-command.c   | 45 -
 shallow.c   |  7 ++-
 trace.c |  2 +-
 10 files changed, 54 insertions(+), 19 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index bbd169c..2992ac0 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -390,7 +390,6 @@ static void clone_local(const char *src_repo, const char 
*dest_repo)
 
 static const char *junk_work_tree;
 static const char *junk_git_dir;
-static pid_t junk_pid;
 static enum {
JUNK_LEAVE_NONE,
JUNK_LEAVE_REPO,
@@ -417,8 +416,6 @@ static void remove_junk(void)
break;
}
 
-   if (getpid() != junk_pid)
-   return;
if (junk_git_dir) {
strbuf_addstr(sb, junk_git_dir);
remove_dir_recursively(sb, 0);
@@ -758,8 +755,6 @@ int cmd_clone(int argc, const char **argv, const char 
*prefix)
struct refspec *refspec;
const char *fetch_pattern;
 
-   junk_pid = getpid();
-
packet_trace_identity(clone);
argc = parse_options(argc, argv, prefix, builtin_clone_options,
 builtin_clone_usage, 0);
@@ -843,7 +838,7 @@ int cmd_clone(int argc, const char **argv, const char 
*prefix)
set_git_work_tree(work_tree);
}
junk_git_dir = git_dir;
-   atexit(remove_junk);
+   cmd_atexit(remove_junk);
sigchain_push_common(remove_junk_on_signal);
 
if (safe_create_leading_directories_const(git_dir)  0)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 159fb7e..1e44d58 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1095,7 +1095,7 @@ static int fetch_one(struct remote *remote, int argc, 
const char **argv)
}
 
sigchain_push_common(unlock_pack_on_signal);
-   atexit(unlock_pack);
+   cmd_atexit(unlock_pack);
refspec = parse_fetch_refspec(ref_nr, refs);
exit_code = do_fetch(gtransport, refspec, ref_nr);
free_refspec(ref_nr, refspec);
diff --git a/builtin/gc.c b/builtin/gc.c
index 8d219d8..cf2defa 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -254,7 +254,7 @@ static const char *lock_repo_for_gc(int force, pid_t* 
ret_pid)
 
pidfile = git_pathdup(gc.pid);
sigchain_push_common(remove_pidfile_on_signal);
-   atexit(remove_pidfile);
+   cmd_atexit(remove_pidfile);
 
return NULL;
 }
diff --git a/diff.c b/diff.c
index 867f034..9c6ef9a 100644
--- a/diff.c
+++ b/diff.c
@@ -2833,7 +2833,7 @@ static struct diff_tempfile *prepare_temp_file(const char 
*name,
}
 
if (!remove_tempfile_installed) {
-   atexit(remove_tempfile);
+   cmd_atexit(remove_tempfile);
sigchain_push_common(remove_tempfile_on_signal);
remove_tempfile_installed = 1;
}
diff --git a/lockfile.c b/lockfile.c
index 2564a7f..ad0d1e2 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -141,7 +141,7 @@ static int lock_file(struct lock_file *lk, const char 
*path, int flags)
if (0 = lk-fd) {
if (!lock_file_list) {
sigchain_push_common(remove_lock_file_on_signal);
-   atexit(remove_lock_file);
+   cmd_atexit(remove_lock_file);
}
lk-owner = getpid();
if (!lk-on_list) {
diff --git a/pager.c b/pager.c
index 8b5cbc5..09ab2fa 100644
--- a/pager.c
+++ b/pager.c
@@ -102,7 +102,7 @@ void setup_pager(void)
 
/* this makes sure that the parent terminates after the pager */
sigchain_push_common(wait_for_pager_signal);
-   atexit(wait_for_pager);
+   cmd_atexit(wait_for_pager);
 }
 
 int pager_in_use(void)
diff --git a/read-cache.c b/read-cache.c
index 6f0057f..8b10c92 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2104,7 +2104,7 @@ static int write_shared_index(struct index_state *istate,
return do_write_locked_index(istate, lock, flags);
}
if (!installed_handler) {
-   atexit(remove_temporary_sharedindex);
+   cmd_atexit(remove_temporary_sharedindex);
sigchain_push_common(remove_temporary_sharedindex_on_signal);
}
move_cache_to_base_index(istate);
diff --git a/run-command.c b/run-command.c