<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/run-command.h, branch v2.8.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.8.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.8.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2016-03-04T21:46:30Z</updated>
<entry>
<title>Merge branch 'sb/submodule-parallel-fetch'</title>
<updated>2016-03-04T21:46:30Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-03-04T21:46:30Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=bbe90e7950456bf1bb1ab17a9ee626f6fad7a7c6'/>
<id>urn:sha1:bbe90e7950456bf1bb1ab17a9ee626f6fad7a7c6</id>
<content type='text'>
Simplify the two callback functions that are triggered when the
child process terminates to avoid misuse of the child-process
structure that has already been cleaned up.

* sb/submodule-parallel-fetch:
  run-command: do not pass child process data into callbacks
</content>
</entry>
<entry>
<title>run-command: do not pass child process data into callbacks</title>
<updated>2016-03-01T17:42:01Z</updated>
<author>
<name>Stefan Beller</name>
<email>sbeller@google.com</email>
</author>
<published>2016-02-29T21:57:06Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=2a73b3dad09ef162eb5917e9e0d01d7c306f6b35'/>
<id>urn:sha1:2a73b3dad09ef162eb5917e9e0d01d7c306f6b35</id>
<content type='text'>
The expected way to pass data into the callback is to pass them via
the customizable callback pointer. The error reporting in
default_{start_failure, task_finished} is not user friendly enough, that
we want to encourage using the child data for such purposes.

Furthermore the struct child data is cleaned by the run-command API,
before we access them in the callbacks, leading to use-after-free
situations.

Signed-off-by: Stefan Beller &lt;sbeller@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'jk/epipe-in-async'</title>
<updated>2016-02-26T21:37:26Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-02-26T21:37:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=8ef250c55908d1c752267ea4a05e0a421a729723'/>
<id>urn:sha1:8ef250c55908d1c752267ea4a05e0a421a729723</id>
<content type='text'>
Handling of errors while writing into our internal asynchronous
process has been made more robust, which reduces flakiness in our
tests.

* jk/epipe-in-async:
  t5504: handle expected output from SIGPIPE death
  test_must_fail: report number of unexpected signal
  fetch-pack: ignore SIGPIPE in sideband demuxer
  write_or_die: handle EPIPE in async threads
</content>
</entry>
<entry>
<title>write_or_die: handle EPIPE in async threads</title>
<updated>2016-02-25T21:51:45Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2016-02-24T07:40:16Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=9658846ce3d379b9ff8010a2ed326fcafc10eb82'/>
<id>urn:sha1:9658846ce3d379b9ff8010a2ed326fcafc10eb82</id>
<content type='text'>
When write_or_die() sees EPIPE, it treats it specially by
converting it into a SIGPIPE death. We obviously cannot
ignore it, as the write has failed and the caller expects us
to die. But likewise, we cannot just call die(), because
printing any message at all would be a nuisance during
normal operations.

However, this is a problem if write_or_die() is called from
a thread. Our raised signal ends up killing the whole
process, when logically we just need to kill the thread
(after all, if we are ignoring SIGPIPE, there is good reason
to think that the main thread is expecting to handle it).

Inside an async thread, the die() code already does the
right thing, because we use our custom die_async() routine,
which calls pthread_join(). So ideally we would piggy-back
on that, and simply call:

  die_quietly_with_code(141);

or similar. But refactoring the die code to do this is
surprisingly non-trivial. The die_routines themselves handle
both printing and the decision of the exit code. Every one
of them would have to be modified to take new parameters for
the code, and to tell us to be quiet.

Instead, we can just teach write_or_die() to check for the
async case and handle it specially. We do have to build an
interface to abstract the async exit, but it's simple and
self-contained. If we had many call-sites that wanted to do
this die_quietly_with_code(), this approach wouldn't scale
as well, but we don't. This is the only place where do this
weird exit trick.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>run-command: add an asynchronous parallel child processor</title>
<updated>2015-12-16T20:06:08Z</updated>
<author>
<name>Stefan Beller</name>
<email>sbeller@google.com</email>
</author>
<published>2015-12-16T00:04:10Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c553c72eed64b5f7316ce227f6d5d783eae6f2ed'/>
<id>urn:sha1:c553c72eed64b5f7316ce227f6d5d783eae6f2ed</id>
<content type='text'>
This allows to run external commands in parallel with ordered output
on stderr.

If we run external commands in parallel we cannot pipe the output directly
to the our stdout/err as it would mix up. So each process's output will
flow through a pipe, which we buffer. One subprocess can be directly
piped to out stdout/err for a low latency feedback to the user.

Example:
Let's assume we have 5 submodules A,B,C,D,E and each fetch takes a
different amount of time as the different submodules vary in size, then
the output of fetches in sequential order might look like this:

 time --&gt;
 output: |---A---| |-B-| |-------C-------| |-D-| |-E-|

When we schedule these submodules into maximal two parallel processes,
a schedule and sample output over time may look like this:

process 1: |---A---| |-D-| |-E-|

process 2: |-B-| |-------C-------|

output:    |---A---|B|---C-------|DE

So A will be perceived as it would run normally in the single child
version. As B has finished by the time A is done, we can dump its whole
progress buffer on stderr, such that it looks like it finished in no
time. Once that is done, C is determined to be the visible child and
its progress will be reported in real time.

So this way of output is really good for human consumption, as it only
changes the timing, not the actual output.

For machine consumption the output needs to be prepared in the tasks,
by either having a prefix per line or per block to indicate whose tasks
output is displayed, because the output order may not follow the
original sequential ordering:

 |----A----| |--B--| |-C-|

will be scheduled to be all parallel:

process 1: |----A----|
process 2: |--B--|
process 3: |-C-|
output:    |----A----|CB

This happens because C finished before B did, so it will be queued for
output before B.

To detect when a child has finished executing, we check interleaved
with other actions (such as checking the liveliness of children or
starting new processes) whether the stderr pipe still exists. Once a
child closed its stderr stream, we assume it is terminating very soon,
and use `finish_command()` from the single external process execution
interface to collect the exit status.

By maintaining the strong assumption of stderr being open until the
very end of a child process, we can avoid other hassle such as an
implementation using `waitpid(-1)`, which is not implemented in Windows.

Signed-off-by: Stefan Beller &lt;sbeller@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'rs/daemon-plug-child-leak'</title>
<updated>2015-11-03T23:13:12Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-11-03T23:13:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c3c592ef95ee21833e2214fb9068889dcac220c9'/>
<id>urn:sha1:c3c592ef95ee21833e2214fb9068889dcac220c9</id>
<content type='text'>
"git daemon" uses "run_command()" without "finish_command()", so it
needs to release resources itself, which it forgot to do.

* rs/daemon-plug-child-leak:
  daemon: plug memory leak
  run-command: factor out child_process_clear()
</content>
</entry>
<entry>
<title>run-command: factor out child_process_clear()</title>
<updated>2015-11-02T23:01:00Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2015-10-24T12:11:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=2d71608ec0b6d098ed7c8c914fb7004b28349995'/>
<id>urn:sha1:2d71608ec0b6d098ed7c8c914fb7004b28349995</id>
<content type='text'>
Avoid duplication by moving the code to release allocated memory for
arguments and environment to its own function, child_process_clear().
Export it to provide a counterpart to child_process_init().

Signed-off-by: Rene Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'ti/glibc-stdio-mutex-from-signal-handler'</title>
<updated>2015-10-07T20:38:16Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-10-07T20:38:16Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=2b72dbbcf3a1d6c6813db2c13afaa1d0d8585f7b'/>
<id>urn:sha1:2b72dbbcf3a1d6c6813db2c13afaa1d0d8585f7b</id>
<content type='text'>
Allocation related functions and stdio are unsafe things to call
inside a signal handler, and indeed killing the pager can cause
glibc to deadlock waiting on allocation mutex as our signal handler
tries to free() some data structures in wait_for_pager().  Reduce
these unsafe calls.

* ti/glibc-stdio-mutex-from-signal-handler:
  pager: don't use unsafe functions in signal handlers
</content>
</entry>
<entry>
<title>Merge branch 'jk/async-pkt-line'</title>
<updated>2015-10-05T19:30:09Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-10-05T19:30:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=88bad58d3860a8e0cf6499951e24311d15bc63f0'/>
<id>urn:sha1:88bad58d3860a8e0cf6499951e24311d15bc63f0</id>
<content type='text'>
The debugging infrastructure for pkt-line based communication has
been improved to mark the side-band communication specifically.

* jk/async-pkt-line:
  pkt-line: show packets in async processes as "sideband"
  run-command: provide in_async query function
</content>
</entry>
<entry>
<title>pager: don't use unsafe functions in signal handlers</title>
<updated>2015-09-04T21:57:51Z</updated>
<author>
<name>Takashi Iwai</name>
<email>tiwai@suse.de</email>
</author>
<published>2015-09-04T09:35:57Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=507d7804c0b094889cd20f23ad9a48e2b76791f3'/>
<id>urn:sha1:507d7804c0b094889cd20f23ad9a48e2b76791f3</id>
<content type='text'>
Since the commit a3da8821208d (pager: do wait_for_pager on signal
death), we call wait_for_pager() in the pager's signal handler.  The
recent bug report revealed that this causes a deadlock in glibc at
aborting "git log" [*1*].  When this happens, git process is left
unterminated, and it can't be killed by SIGTERM but only by SIGKILL.

The problem is that wait_for_pager() function does more than waiting
for pager process's termination, but it does cleanups and printing
errors.  Unfortunately, the functions that may be used in a signal
handler are very limited [*2*].  Particularly, malloc(), free() and the
variants can't be used in a signal handler because they take a mutex
internally in glibc.  This was the cause of the deadlock above.  Other
than the direct calls of malloc/free, many functions calling
malloc/free can't be used.  strerror() is such one, either.

Also the usage of fflush() and printf() in a signal handler is bad,
although it seems working so far.  In a safer side, we should avoid
them, too.

This patch tries to reduce the calls of such functions in signal
handlers.  wait_for_signal() takes a flag and avoids the unsafe
calls.   Also, finish_command_in_signal() is introduced for the
same reason.  There the free() calls are removed, and only waits for
the children without whining at errors.

[*1*] https://bugzilla.opensuse.org/show_bug.cgi?id=942297
[*2*] http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03

Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Reviewed-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
