Commit Graph

85 Commits

Author SHA1 Message Date
Jun Wu
02fcca0577 zeroconf: do not crash if socket being read is closed by another thread
In zeroconf/__init__.py, there is:

    server = Zeroconf.Zeroconf(ip)
    l = listener()
    Zeroconf.ServiceBrowser(server, "_hg._tcp.local.", l)
    time.sleep(1)
    server.close()

`server.close()` closes the underlying socket while the `ServiceBrowser` may
still have a background thread reading the socket. There could be a race
condition where the reading thread reads the closed socket, resulting in
EBADF crash. This patch catches the exception.

This makes test-paths.t pass with chg.

Differential Revision: https://phab.mercurial-scm.org/D919
2017-10-02 20:23:25 -07:00
Boris Feld
01eaec495b configitems: register the 'web.description' config 2017-06-30 03:45:43 +02:00
Pierre-Yves David
d997c3083a zeroconf: blindly forward extra argument to the core config method
The new default value handling is simpler if we let the original function handle
everything.
2017-07-01 21:57:17 +02:00
Simon Farnsworth
8a0451d60e zeroconf: fail nicely on IPv6 only system
zeroconf only knows how to deal with IPv4; I develop on a system where the only
IPv4 address is 127.0.0.1.

Teach zeroconf to ignore IPv6 addresses when looking for plausible IPv4
connectivity.
2017-02-08 08:08:41 -08:00
Augie Fackler
4e1c384d0a extensions: change magic "shipped with hg" string
I've caught multiple extensions in the wild lying about being
'internal', so it's time to move the goalposts on people. Goalpost
moving will continue until third party extensions stop trying to
defeat the system.
2016-08-23 11:26:08 -04:00
Martin von Zweigbergk
4da3e7135f zeroconf: remove leftover camelcase identifier
00820e3ad90f (zeroconf: remove camelcase in identifiers, 2016-03-01)
forgot one occurrence of "numAuthorities", which makes test-paths.t
fail for me. I don't even know what zeroconf is, but this patch seems
obviously correct and it fixes the failing test case.
2016-03-11 15:40:58 -08:00
timeless
7846832020 zeroconf: replace reduce+add with itertools.chain 2016-03-01 10:18:47 +00:00
timeless
a2c7933e41 zeroconf: replace has_key with in 2016-03-01 10:22:10 +00:00
timeless
a36c36a4d9 zeroconf: compare singleton using is 2016-03-01 09:59:58 +00:00
timeless
9c4fb14309 zeroconf: remove camelcase in identifiers 2016-03-01 09:57:45 +00:00
Augie Fackler
d41a070262 zeroconf: import ui as uimod per test-check-module-imports 2016-03-01 13:48:25 -05:00
timeless
bc17264706 zeroconf: remove whitespace around = for named parameters 2016-03-01 09:49:38 +00:00
timeless
dc63708974 zeroconf: del is not a function 2016-03-01 09:44:32 +00:00
timeless
d663c817be zeroconf: add whitespace around operator 2016-03-01 09:48:11 +00:00
timeless
b24249e75c zeroconf: wrap long lines 2016-03-01 09:33:39 +00:00
timeless
c72c0f2737 zeroconf: drop tabs 2016-03-01 08:53:40 +00:00
timeless
d76d9e277e zeroconf: omit semicolons 2016-03-01 08:48:10 +00:00
timeless
c202bff77a zeroconf: use absolute_import 2016-03-01 08:42:46 +00:00
timeless
1f9922ecf6 zeroconf: use print function 2016-03-01 07:17:32 +00:00
Danek Duvall
867f873d72 zeroconf: fix crash in "hg paths" when zeroconf server is up
Running "hg paths" with zeroconf enabled and when a zeroconf server is up
and running gives a traceback with "ValueError: rawloc must be defined".
This is because zeroconf needs to wrap ui.configsuboptions(), introduced in
9f74e4935618.
2016-02-25 10:01:59 -08:00
Danek Duvall
61164678ff zeroconf: fix setsockopt() call on Solaris to send payload of correct length
The zeroconf extension has been broken on Solaris since the beginning, but
no one noticed until the testsuite started poking it after changeset
30423fb50191, when it started running "hg paths" with the extension
enabled.

Solaris requires that, for IP_MULTICAST_{TTL,LOOP}, the argument passed in
be of length 1.  With the original code here, it gets passed in as an int
-- length 4 -- and so the system call fails with EINVAL.  Thankfully,
Python's socket.setsockopt() allows you to pass in a string instead of an
integer, and it passes that string to libc's setsockopt() with the correct
value and length.
2016-02-24 22:22:18 -08:00
Yuya Nishihara
61b45241f5 zeroconf: forward all arguments passed to ui.configitems() wrapper
cf6cc5344afa added 'ignoresub' argument to ui.configitems(), but zeroconf
wrapper wasn't updated. It caused the following crash:

  Traceback (most recent call last):
    File "bin/hg", line 43, in <module>
      mercurial.dispatch.run()
    File "lib/python/mercurial/dispatch.py", line 54, in run
      sys.exit((dispatch(request(sys.argv[1:])) or 0) & 255)
    File "lib/python/mercurial/dispatch.py", line 120, in dispatch
      ret = _runcatch(req)
    File "lib/python/mercurial/dispatch.py", line 191, in _runcatch
      return _dispatch(req)
    File "lib/python/mercurial/dispatch.py", line 924, in _dispatch
      cmdpats, cmdoptions)
    File "lib/python/mercurial/dispatch.py", line 681, in runcommand
      ret = _runcommand(ui, options, cmd, d)
    File "lib/python/mercurial/extensions.py", line 195, in closure
      return func(*(args + a), **kw)
    File "lib/python/hgext/zeroconf/__init__.py", line 180, in cleanupafterdispatch
      return orig(ui, options, cmd, cmdfunc)
    File "lib/python/mercurial/dispatch.py", line 1055, in _runcommand
      return checkargs()
    File "lib/python/mercurial/dispatch.py", line 1015, in checkargs
      return cmdfunc()
    File "lib/python/mercurial/dispatch.py", line 921, in <lambda>
      d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
    File "lib/python/mercurial/util.py", line 991, in check
      return func(*args, **kwargs)
    File "lib/python/mercurial/commands.py", line 5405, in paths
      pathitems = sorted(ui.paths.iteritems())
    File "lib/python/mercurial/util.py", line 723, in __get__
      result = self.func(obj)
    File "lib/python/mercurial/ui.py", line 619, in paths
      return paths(self)
    File "lib/python/mercurial/ui.py", line 1099, in __init__
      for name, loc in ui.configitems('paths', ignoresub=True):
    File "lib/python/mercurial/extensions.py", line 195, in closure
      return func(*(args + a), **kw)
  TypeError: configitems() got an unexpected keyword argument 'ignoresub'

We have no test coverage for zeroconf, so I've added a minimal test that
could reproduce this problem.
2016-02-10 22:53:17 +09:00
Gregory Szorc
e2e4daeff4 zeroconf: access repo on hgweb_mod properly (issue5036)
hgweb_mod.hgweb.repo disappeared in 4d6522c4ac11 (hg: establish
a cache for localrepository instances) and the code for accessing repo
instances from hgweb was later refactored to go through a cache-aware
context manager.

Adapt zeroconf to access the repo instance via the new API.
2016-01-17 20:37:29 -08:00
timeless
ebb1d48658 cleanup: remove superfluous space after space after equals (python) 2015-12-31 08:16:59 +00:00
Augie Fackler
f95a6caba1 extensions: document that testedwith = 'internal' is special
Extension authors (notably at companies using hg) have been
cargo-culting the `testedwith = 'internal'` bit from hg's own
extensions, which then defeats our "file bugs over here" logic in
dispatch. Let's be more aggressive about trying to give extension
authors a hint about what testedwith should say.
2015-04-28 16:44:37 -04:00
Benoit Boissinot
e1a55dc93c zeroconf: use port from server instead of picking port from config (issue3746)
In order to get the port, wrap create server instead of
hgweb_mod/hgwebdir_mod.
2012-12-30 19:19:52 +01:00
Mads Kiilerich
5e3dc3e383 avoid using abbreviations that look like spelling errors 2012-08-27 23:14:27 +02:00
Mads Kiilerich
520076e707 delete some dead comments and docstrings 2012-08-21 02:41:20 +02:00
Mads Kiilerich
2372d51b68 fix wording and not-completely-trivial spelling errors and bad docstrings 2012-08-15 22:39:18 +02:00
Mads Kiilerich
2f4504e446 fix trivial spelling errors 2012-08-15 22:38:42 +02:00
Augie Fackler
96d44b39f7 hgext: mark all first-party extensions as such 2012-05-15 14:37:49 -05:00
Brodie Rao
c577fac135 cleanup: replace naked excepts with more specific ones 2012-05-12 16:02:45 +02:00
Brodie Rao
d6a6abf2b0 cleanup: eradicate long lines 2012-05-12 15:54:54 +02:00
Martin Geisler
d8334151e6 Remove FSF mailing address from GPL headers
The GPLv3 FAQ suggests to upgrade by

  [...] replace all your existing v2 license notices (usually at the
  top of each file) with the new recommended text available on the GNU
  licenses howto. It's more future-proof because it no longer includes
  the FSF's postal mailing address.

This removes the postal address, but leaves the version number at 2+.
2012-01-06 16:27:13 +01:00
Martin Geisler
af8a35e078 check-code: flag 0/1 used as constant Boolean expression 2011-06-01 12:38:46 +02:00
Matt Mackall
e941b69730 merge with stable 2011-05-01 06:06:59 -05:00
Nicolas Dumazet
892f3cacb5 zeroconf: notify the Zeroconf threads when hg exits
Zeroconf launches two threads in the background, and they wait on
Condition objects to exit. We need to call Zeroconf.close() to
release those conditions so that threads can gracefully exit.

This means that an interrupt on the hg process will now gracefully
propagate to the Zeroconf children, fixing that bug which did not
allow us to kill an `hg serve` process.
2011-04-30 19:36:59 +02:00
Augie Fackler
9398f9dfcc Zeroconf: catch both ValueError and KeyError in get()
This prevents a traceback during discovery of available hosts.
2011-04-30 07:30:38 -05:00
Matt Mackall
24e0621116 zeroconf: clean up naked exceptions 2011-04-13 12:57:24 -05:00
Brodie Rao
d1905b7d87 mail/hgweb: support service names for ports (issue2350)
This adds util.getport(port) which tries to parse port as an int, and
failing that, looks it up using socket.getservbyname(). Thus, the
following will work:

    [smtp]
    port = submission

    [web]
    port = http

This does not apply to ports in URLs used in clone, pull, etc.
2010-08-28 12:31:07 -04:00
Martin Geisler
7b12009341 zeroconf: small fixes in docstring
Use reST role for consistency, import small part of Debian's
proposed_upstream__correct-zeroconf-doc patch from

  http://svn.debian.org/viewsvn/python-apps/packages/mercurial/trunk/debian/patches/
2010-07-03 01:56:09 +02:00
Javi Merino
9da23a6f37 zeroconf: Use BadDomainName exception instead of string exceptions
String exceptions no longer work in python 2.6. Use exception classes
instead.
2010-06-23 10:45:53 +02:00
Renato Cunha
b35e385443 hgext/zeroconf/__init__.py: Separate relative and absolute imports.
2to3 complains when relative and absolute imports are mixed, this fix just
separates them on the zeroconf extension. According to 2to3, the other modules
are fine.
2010-06-14 16:56:20 -03:00
Matt Mackall
7032c8dbda zeroconf: handle string hgweb config args 2010-04-26 11:03:40 -05:00
Matt Mackall
3fea1c3bdd hgweb: make baseui parameter non-positional 2010-04-26 11:03:40 -05:00
Brendan Cully
9f7576938c zeroconf: suppress traceback during shutdown
If the read thred is in select when the main thread is in close, the main
thread may close the socket between select and read, generating a noisy
traceback. This can be ignored if the shutdown flag is set.
2010-02-19 16:50:47 -08:00
Brendan Cully
5551943cd9 zeroconf: use DNS length field to safely skip unknown record types 2010-02-08 00:01:08 +01:00
Brendan Cully
d5437ba5b0 zeroconf: better fix for readName error
Stop parsing when an unknown type is seen, since it is impossible
to resynchronize on the stream.
2010-02-07 19:39:29 +01:00
Brendan Cully
182305d033 zeroconf: try utf-16 decoding if utf-8 fails 2010-02-07 18:37:14 +01:00
Henrik Stuart
4a12117ba9 zeroconf: do not try to encode encoded strings (issue1942) 2010-02-06 17:31:54 +01:00