<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/pager.c, branch v2.6.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.6.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.6.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2015-10-16T21:32:41Z</updated>
<entry>
<title>Merge branch 'ti/glibc-stdio-mutex-from-signal-handler' into maint</title>
<updated>2015-10-16T21:32:41Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-10-16T21:32:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=267ebf6c84eb4437c219c16848678b090b4af6e2'/>
<id>urn:sha1:267ebf6c84eb4437c219c16848678b090b4af6e2</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>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>
<entry>
<title>Merge branch 'jk/fix-alias-pager-config-key-warnings'</title>
<updated>2015-08-31T22:38:57Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-08-31T22:38:57Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=7b7c10bf5e38ca8fe06ab80b073408e1dc6761d7'/>
<id>urn:sha1:7b7c10bf5e38ca8fe06ab80b073408e1dc6761d7</id>
<content type='text'>
Because the configuration system does not allow "alias.0foo" and
"pager.0foo" as the configuration key, the user cannot use '0foo'
as a custom command name anyway, but "git 0foo" tried to look these
keys up and emitted useless warnings before saying '0foo is not a
git command'.  These warning messages have been squelched.

* jk/fix-alias-pager-config-key-warnings:
  config: silence warnings for command names with invalid keys
</content>
</entry>
<entry>
<title>config: silence warnings for command names with invalid keys</title>
<updated>2015-08-24T15:52:23Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2015-08-24T06:11:33Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=9e9de18f1ad39901a8f0c67f0af70d66d427e326'/>
<id>urn:sha1:9e9de18f1ad39901a8f0c67f0af70d66d427e326</id>
<content type='text'>
When we are running the git command "foo", we may have to
look up the config keys "pager.foo" and "alias.foo". These
config schemes are mis-designed, as the command names can be
anything, but the config syntax has some restrictions. For
example:

  $ git foo_bar
  error: invalid key: pager.foo_bar
  error: invalid key: alias.foo_bar
  git: 'foo_bar' is not a git command. See 'git --help'.

You cannot name an alias with an underscore. And if you have
an external command with one, you cannot configure its
pager.

In the long run, we may develop a different config scheme
for these features. But in the near term (and because we'll
need to support the existing scheme indefinitely), we should
at least squelch the error messages shown above.

These errors come from git_config_parse_key. Ideally we
would pass a "quiet" flag to the config machinery, but there
are many layers between the pager code and the key parsing.
Passing a flag through all of those would be an invasive
change.

Instead, let's provide a config function to report on
whether a key is syntactically valid, and have the pager and
alias code skip lookup for bogus keys. We can build this
easily around the existing git_config_parse_key, with two
minor modifications:

  1. We now handle a NULL store_key, to validate but not
     write out the normalized key.

  2. We accept a "quiet" flag to avoid writing to stderr.
     This doesn't need to be a full-blown public "flags"
     field, because we can make the existing implementation
     a static helper function, keeping the mess contained
     inside config.c.

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>Merge branch 'jc/unexport-git-pager-in-use-in-pager'</title>
<updated>2015-07-13T21:00:27Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-07-13T21:00:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=6cf7eef384968e9886e9d2eba440974c66908aa6'/>
<id>urn:sha1:6cf7eef384968e9886e9d2eba440974c66908aa6</id>
<content type='text'>
When you say "!&lt;ENTER&gt;" while running say "git log", you'd confuse
yourself in the resulting shell, that may look as if you took
control back to the original shell you spawned "git log" from but
that isn't what is happening.  To that new shell, we leaked
GIT_PAGER_IN_USE environment variable that was meant as a local
communication between the original "Git" and subprocesses that was
spawned by it after we launched the pager, which caused many
"interesting" things to happen, e.g. "git diff | cat" still paints
its output in color by default.

Stop leaking that environment variable to the pager's half of the
fork; we only need it on "Git" side when we spawn the pager.

* jc/unexport-git-pager-in-use-in-pager:
  pager: do not leak "GIT_PAGER_IN_USE" to the pager
</content>
</entry>
<entry>
<title>pager: do not leak "GIT_PAGER_IN_USE" to the pager</title>
<updated>2015-07-04T01:07:21Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-07-03T17:18:45Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=124b51909dab82151dff8ae8fd3a588a8846c7ac'/>
<id>urn:sha1:124b51909dab82151dff8ae8fd3a588a8846c7ac</id>
<content type='text'>
Since 2e6c012e (setup_pager: set GIT_PAGER_IN_USE, 2011-08-17), we
export GIT_PAGER_IN_USE so that a process that becomes the upstream
of the spawned pager can still tell that we have spawned the pager
and decide to do colored output even when its output no longer goes
to a terminal (i.e. isatty(1)).

But we forgot to clear it from the enviornment of the spawned pager.

This is not a problem in a sane world, but if you have a handful of
thousands Git users in your organization, somebody is bound to do
strange things, e.g. typing "!&lt;ENTER&gt;" instead of 'q' to get control
back from $LESS.  GIT_PAGER_IN_USE is still set in that subshell
spawned by "less", and all sorts of interesting things starts
happening, e.g. "git diff | cat" starts coloring its output.

We can clear the environment variable in the half of the fork that
runs the pager to avoid the confusion.

Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
Acked-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'jk/decimal-width-for-uintmax'</title>
<updated>2015-02-18T19:45:02Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-02-18T19:45:02Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=ca00db08da414b3f6bd9481a51fdbb4b6836719c'/>
<id>urn:sha1:ca00db08da414b3f6bd9481a51fdbb4b6836719c</id>
<content type='text'>
We didn't format an integer that wouldn't fit in "int" but in
"uintmax_t" correctly.

* jk/decimal-width-for-uintmax:
  decimal_width: avoid integer overflow
</content>
</entry>
<entry>
<title>decimal_width: avoid integer overflow</title>
<updated>2015-02-05T20:38:35Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2015-02-05T08:14:19Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d306f3d3513c62342fec4e31457766f2473f9e9a'/>
<id>urn:sha1:d306f3d3513c62342fec4e31457766f2473f9e9a</id>
<content type='text'>
The decimal_width function originally appeared in blame.c as
"lineno_width", and was designed for calculating the
print-width of small-ish integer values (line numbers in
text files). In ec7ff5b, it was made into a reusable
function, and in dc801e7, we started using it to align
diffstats.

Binary files in a diffstat show byte counts rather than line
numbers, meaning they can be quite large (e.g., consider
adding or removing a 2GB file). decimal_width is not up to
the challenge for two reasons:

  1. It takes the value as an "int", whereas large files may
     easily surpass this. The value may be truncated, in
     which case we will produce an incorrect value.

  2. It counts "up" by repeatedly multiplying another
     integer by 10 until it surpasses the value.  This can
     cause an infinite loop when the value is close to the
     largest representable integer.

     For example, consider using a 32-bit signed integer,
     and a value of 2,140,000,000 (just shy of 2^31-1).
     We will count up and eventually see that 1,000,000,000
     is smaller than our value. The next step would be to
     multiply by 10 and see that 10,000,000,000 is too
     large, ending the loop. But we can't represent that
     value, and we have signed overflow.

     This is technically undefined behavior, but a common
     behavior is to lose the high bits, in which case our
     iterator will certainly be less than the number. So
     we'll keep multiplying, overflow again, and so on.

This patch changes the argument to a uintmax_t (the same
type we use to store the diffstat information for binary
filese), and counts "down" by repeatedly dividing our value
by 10.

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>use env_array member of struct child_process</title>
<updated>2014-10-19T22:26:34Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2014-10-19T11:14:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=a915459097b72da9cc058172a54029352b684b0f'/>
<id>urn:sha1:a915459097b72da9cc058172a54029352b684b0f</id>
<content type='text'>
Convert users of struct child_process to using the managed env_array for
specifying environment variables instead of supplying an array on the
stack or bringing their own argv_array.  This shortens and simplifies
the code and ensures automatically that the allocated memory is freed
after use.

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 'rs/child-process-init'</title>
<updated>2014-09-11T17:33:27Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2014-09-11T17:33:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=825fd93767510895a98ad7f12e3c1af3e40e367b'/>
<id>urn:sha1:825fd93767510895a98ad7f12e3c1af3e40e367b</id>
<content type='text'>
Code clean-up.

* rs/child-process-init:
  run-command: inline prepare_run_command_v_opt()
  run-command: call run_command_v_opt_cd_env() instead of duplicating it
  run-command: introduce child_process_init()
  run-command: introduce CHILD_PROCESS_INIT
</content>
</entry>
</feed>
