2019-11-01 22:33:28 +03:00
|
|
|
# Portions Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2.
|
|
|
|
|
2015-12-23 16:23:56 +03:00
|
|
|
# chgserver.py - command server extension for cHg
|
|
|
|
#
|
|
|
|
# Copyright 2011 Yuya Nishihara <yuya@tcha.org>
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
|
2016-10-15 08:30:16 +03:00
|
|
|
"""command server extension for cHg
|
2015-12-23 16:23:56 +03:00
|
|
|
|
|
|
|
'S' channel (read/write)
|
|
|
|
propagate ui.system() request to client
|
|
|
|
|
|
|
|
'attachio' command
|
|
|
|
attach client's stdio passed by sendmsg()
|
|
|
|
|
|
|
|
'chdir' command
|
|
|
|
change current directory
|
|
|
|
|
|
|
|
'setenv' command
|
|
|
|
replace os.environ completely
|
|
|
|
|
2016-02-29 17:05:45 +03:00
|
|
|
'setumask' command
|
|
|
|
set umask
|
|
|
|
|
2016-03-05 16:56:59 +03:00
|
|
|
'validate' command
|
|
|
|
reload the config and check if the server is up to date
|
|
|
|
|
2016-02-29 17:05:45 +03:00
|
|
|
Config
|
|
|
|
------
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
[chgserver]
|
2017-02-17 10:10:47 +03:00
|
|
|
# how long (in seconds) should an idle chg server exit
|
|
|
|
idletimeout = 3600
|
|
|
|
|
|
|
|
# whether to skip config or env change checks
|
|
|
|
skiphash = False
|
2015-12-23 16:23:56 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2016-06-10 07:12:33 +03:00
|
|
|
import hashlib
|
2016-02-26 17:59:39 +03:00
|
|
|
import inspect
|
2015-12-23 16:23:56 +03:00
|
|
|
import os
|
|
|
|
import re
|
2017-04-30 21:08:27 +03:00
|
|
|
import socket
|
2015-12-23 16:23:56 +03:00
|
|
|
import struct
|
chgserver: auto exit after being idle for too long or lose the socket file
This is a part of the one server per config series. In multiple-server setup,
new server may be started for a temporary config change like in command line,
--config extensions.foo=bar.py. This may end up with a lot of not so useful
server processes. Other questions are about socket file and process management,
How to stop these processes? What if a new server wants to listen on a same
address, replacing the old one?
This patch introduces AutoExitMixIn, which will:
1. Exit after being idle for too long. So useless servers won't run forever.
2. Periodically check the ownership of socket file, exit if it is no longer
owned. This brings strong consistency between the filesystem and the
process, and handles some race conditions neatly.
Since rename is atomic, a new server can just have a same server address
with an old one and won't worry about how to make sure the old server is
killed, address conflict, service downtime issues.
The user can safely stop all servers by simply removing the socket files,
without worrying about outdated or accidentally removed pidfiles.
2016-02-24 21:42:59 +03:00
|
|
|
import time
|
2015-12-23 16:23:56 +03:00
|
|
|
|
2019-12-04 21:53:06 +03:00
|
|
|
# pyre-fixme[21]: Could not find `bindings`.
|
2020-01-09 22:49:48 +03:00
|
|
|
from bindings import commands, hgtime
|
2019-08-29 05:22:46 +03:00
|
|
|
|
|
|
|
from . import commandserver, encoding, error, extensions, pycompat, ui as uimod, util
|
2016-10-15 08:30:16 +03:00
|
|
|
from .i18n import _
|
2015-12-23 16:23:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
_log = commandserver.log
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2017-01-10 01:59:31 +03:00
|
|
|
def _newchgui(srcui, csystem, attachio):
|
2015-12-23 16:23:56 +03:00
|
|
|
class chgui(srcui.__class__):
|
|
|
|
def __init__(self, src=None):
|
|
|
|
super(chgui, self).__init__(src)
|
|
|
|
if src:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
self._csystem = getattr(src, "_csystem", csystem)
|
2015-12-23 16:23:56 +03:00
|
|
|
else:
|
|
|
|
self._csystem = csystem
|
|
|
|
|
2017-02-18 19:16:45 +03:00
|
|
|
def _runsystem(self, cmd, environ, cwd, out):
|
2016-03-17 21:27:48 +03:00
|
|
|
# fallback to the original system method if the output needs to be
|
|
|
|
# captured (to self._buffers), or the output stream is not stdout
|
|
|
|
# (e.g. stderr, cStringIO), because the chg client is not aware of
|
|
|
|
# these situations and will behave differently (write to stdout).
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if (
|
|
|
|
out is not self.fout
|
|
|
|
or not util.safehasattr(self.fout, "fileno")
|
|
|
|
or self.fout.fileno() != util.stdout.fileno()
|
|
|
|
):
|
2017-02-18 19:16:45 +03:00
|
|
|
return util.system(cmd, environ=environ, cwd=cwd, out=out)
|
2015-12-23 16:23:56 +03:00
|
|
|
self.flush()
|
2019-09-09 21:46:49 +03:00
|
|
|
return self._csystem.runsystem(cmd, util.shellenviron(environ), cwd)
|
2015-12-23 16:23:56 +03:00
|
|
|
|
2017-04-13 18:27:19 +03:00
|
|
|
def _runpager(self, cmd, env=None):
|
2019-09-09 21:46:49 +03:00
|
|
|
self._csystem.runpager(
|
2019-09-09 21:46:49 +03:00
|
|
|
cmd,
|
|
|
|
util.shellenviron(env),
|
|
|
|
redirectstderr=self.configbool("pager", "stderr"),
|
|
|
|
cmdtable={"attachio": attachio},
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
)
|
ui: defer setting pager related properties until the pager has spawned
When --pager=on is given, dispatch.py spawns a pager before setting up color.
If the pager failed to launch, ui.pageractive was left set to True, so color
configured itself based on 'color.pagermode'. A typical MSYS setting would be
'color.mode=auto, color.pagermode=ansi'. In the failure case, this would print
a warning, disable the pager, and then print the raw ANSI codes to the terminal.
Care needs to be taken, because it appears that leaving ui.pageractive=True was
the only thing that prevented an attempt at running the pager again from inside
the command. This results in a double warning message, so pager is simply
disabled on failure.
The ui config settings didn't need to be moved to fix this, but it seemed like
the right thing to do for consistency.
2017-03-26 04:12:00 +03:00
|
|
|
return True
|
2017-01-10 01:59:31 +03:00
|
|
|
|
2015-12-23 16:23:56 +03:00
|
|
|
return chgui(srcui)
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2015-12-23 16:23:56 +03:00
|
|
|
class channeledsystem(object):
|
2019-09-09 21:46:49 +03:00
|
|
|
"""Propagate ui.system() and ui._runpager() requests to the chg client"""
|
2015-12-23 16:23:56 +03:00
|
|
|
|
2019-09-09 21:46:49 +03:00
|
|
|
def __init__(self, in_, out):
|
2015-12-23 16:23:56 +03:00
|
|
|
self.in_ = in_
|
|
|
|
self.out = out
|
|
|
|
|
2019-09-09 21:46:49 +03:00
|
|
|
def _send_request(self, channel, args):
|
|
|
|
data = "\0".join(args) + "\0"
|
|
|
|
self.out.write(struct.pack(">cI", channel, len(data)))
|
2015-12-23 16:23:56 +03:00
|
|
|
self.out.write(data)
|
|
|
|
self.out.flush()
|
|
|
|
|
2019-09-09 21:46:49 +03:00
|
|
|
def _environ_to_args(self, environ):
|
|
|
|
return ["%s=%s" % (k, v) for k, v in environ.items()]
|
|
|
|
|
|
|
|
def runsystem(self, cmd, environ, cwd=None):
|
|
|
|
"""Send a request to run a system command.
|
|
|
|
|
|
|
|
This request type is sent with the 's' channel code.
|
|
|
|
The request contents are a series of null-terminated strings:
|
|
|
|
- the first string is the command string, to be run with "sh -c"
|
|
|
|
- the second string is the working directory to use for the command
|
|
|
|
- all remaining arguments are environment variables, all in the form
|
|
|
|
"name=value"
|
|
|
|
|
|
|
|
After sending a system request, the server waits for
|
|
|
|
|
|
|
|
exitcode length (unsigned int),
|
|
|
|
exitcode (int)"""
|
|
|
|
args = [util.quotecommand(cmd), os.path.abspath(cwd or ".")]
|
|
|
|
args.extend(self._environ_to_args(environ))
|
|
|
|
self._send_request("s", args)
|
|
|
|
|
|
|
|
length = self.in_.read(4)
|
|
|
|
length, = struct.unpack(">I", length)
|
|
|
|
if length != 4:
|
|
|
|
raise error.Abort(_("invalid response"))
|
|
|
|
rc, = struct.unpack(">i", self.in_.read(4))
|
|
|
|
return rc
|
|
|
|
|
2019-09-09 21:46:49 +03:00
|
|
|
def runpager(self, cmd, environ, redirectstderr, cmdtable):
|
2019-09-09 21:46:49 +03:00
|
|
|
"""Requests to run a pager command are sent using the 'p' channel code.
|
|
|
|
The request contents are a series of null-terminated strings:
|
|
|
|
- the first string is the pager command string, to be run with "sh -c"
|
|
|
|
- the second string indicates desired I/O redirection settings
|
|
|
|
- all remaining arguments are environment variables, all in the form
|
|
|
|
"name=value"
|
|
|
|
|
|
|
|
After sending a pager request the server repeatedly waits for a command name
|
|
|
|
ending with '\n' and executes it defined by cmdtable, or exits the loop if the
|
|
|
|
command name is empty.
|
|
|
|
"""
|
2019-09-09 21:46:49 +03:00
|
|
|
redirectsettings = "stderr" if redirectstderr else ""
|
2019-09-09 21:46:49 +03:00
|
|
|
args = [util.quotecommand(cmd), redirectsettings]
|
|
|
|
args.extend(self._environ_to_args(environ))
|
|
|
|
self._send_request("p", args)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
cmd = self.in_.readline()[:-1]
|
|
|
|
if not cmd:
|
|
|
|
break
|
|
|
|
if cmd in cmdtable:
|
|
|
|
_log("pager subcommand: %s" % cmd)
|
|
|
|
cmdtable[cmd]()
|
|
|
|
else:
|
|
|
|
raise error.Abort(_("unexpected command: %s") % cmd)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2015-12-23 16:23:56 +03:00
|
|
|
|
|
|
|
_iochannels = [
|
|
|
|
# server.ch, ui.fp, mode
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
("cin", "fin", pycompat.sysstr("rb")),
|
|
|
|
("cout", "fout", pycompat.sysstr("wb")),
|
|
|
|
("cerr", "ferr", pycompat.sysstr("wb")),
|
2015-12-23 16:23:56 +03:00
|
|
|
]
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2015-12-23 16:23:56 +03:00
|
|
|
class chgcmdserver(commandserver.server):
|
2019-08-29 05:22:46 +03:00
|
|
|
def __init__(self, ui, repo, fin, fout, sock, baseaddress):
|
2015-12-23 16:23:56 +03:00
|
|
|
super(chgcmdserver, self).__init__(
|
2019-09-09 21:46:49 +03:00
|
|
|
_newchgui(ui, channeledsystem(fin, fout), self.attachio), repo, fin, fout
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
)
|
2015-12-23 16:23:56 +03:00
|
|
|
self.clientsock = sock
|
|
|
|
self._oldios = [] # original (self.ch, ui.fp, fd) before "attachio"
|
2016-02-29 16:46:54 +03:00
|
|
|
self.baseaddress = baseaddress
|
2015-12-23 16:23:56 +03:00
|
|
|
|
|
|
|
def cleanup(self):
|
2016-05-21 09:18:23 +03:00
|
|
|
super(chgcmdserver, self).cleanup()
|
2015-12-23 16:23:56 +03:00
|
|
|
# dispatch._runcatch() does not flush outputs if exception is not
|
|
|
|
# handled by dispatch._dispatch()
|
|
|
|
self.ui.flush()
|
|
|
|
self._restoreio()
|
|
|
|
|
|
|
|
def attachio(self):
|
|
|
|
"""Attach to client's stdio passed via unix domain socket; all
|
|
|
|
channels except cresult will no longer be used
|
|
|
|
"""
|
|
|
|
# tell client to sendmsg() with 1-byte payload, which makes it
|
|
|
|
# distinctive from "attachio\n" command consumed by client.read()
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
self.clientsock.sendall(struct.pack(">cI", "I", 1))
|
2017-04-26 16:26:28 +03:00
|
|
|
clientfds = util.recvfds(self.clientsock.fileno())
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
_log("received fds: %r\n" % clientfds)
|
2015-12-23 16:23:56 +03:00
|
|
|
|
|
|
|
ui = self.ui
|
|
|
|
ui.flush()
|
|
|
|
first = self._saveio()
|
|
|
|
for fd, (cn, fn, mode) in zip(clientfds, _iochannels):
|
|
|
|
assert fd > 0
|
|
|
|
fp = getattr(ui, fn)
|
|
|
|
os.dup2(fd, fp.fileno())
|
|
|
|
os.close(fd)
|
|
|
|
if not first:
|
|
|
|
continue
|
|
|
|
# reset buffering mode when client is first attached. as we want
|
|
|
|
# to see output immediately on pager, the mode stays unchanged
|
|
|
|
# when client re-attached. ferr is unchanged because it should
|
|
|
|
# be unbuffered no matter if it is a tty or not.
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if fn == "ferr":
|
2015-12-23 16:23:56 +03:00
|
|
|
newfp = fp
|
|
|
|
else:
|
|
|
|
# make it line buffered explicitly because the default is
|
|
|
|
# decided on first write(), where fout could be a pager.
|
|
|
|
if fp.isatty():
|
|
|
|
bufsize = 1 # line buffered
|
|
|
|
else:
|
|
|
|
bufsize = -1 # system default
|
2019-09-27 19:43:34 +03:00
|
|
|
try:
|
|
|
|
newfp = util.fdopen(fp.fileno(), mode, bufsize)
|
|
|
|
except OSError:
|
|
|
|
# fdopen can fail with EINVAL. For example, run
|
|
|
|
# with nohup. Do not set buffer size in that case.
|
|
|
|
newfp = fp
|
2015-12-23 16:23:56 +03:00
|
|
|
setattr(ui, fn, newfp)
|
|
|
|
setattr(self, cn, newfp)
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
self.cresult.write(struct.pack(">i", len(clientfds)))
|
2015-12-23 16:23:56 +03:00
|
|
|
|
|
|
|
def _saveio(self):
|
|
|
|
if self._oldios:
|
|
|
|
return False
|
|
|
|
ui = self.ui
|
|
|
|
for cn, fn, _mode in _iochannels:
|
|
|
|
ch = getattr(self, cn)
|
|
|
|
fp = getattr(ui, fn)
|
|
|
|
fd = os.dup(fp.fileno())
|
|
|
|
self._oldios.append((ch, fp, fd))
|
|
|
|
return True
|
|
|
|
|
|
|
|
def _restoreio(self):
|
|
|
|
ui = self.ui
|
|
|
|
for (ch, fp, fd), (cn, fn, _mode) in zip(self._oldios, _iochannels):
|
|
|
|
newfp = getattr(ui, fn)
|
|
|
|
# close newfp while it's associated with client; otherwise it
|
|
|
|
# would be closed when newfp is deleted
|
|
|
|
if newfp is not fp:
|
|
|
|
newfp.close()
|
|
|
|
# restore original fd: fp is open again
|
|
|
|
os.dup2(fd, fp.fileno())
|
|
|
|
os.close(fd)
|
|
|
|
setattr(self, cn, ch)
|
|
|
|
setattr(ui, fn, fp)
|
|
|
|
del self._oldios[:]
|
|
|
|
|
|
|
|
def chdir(self):
|
|
|
|
"""Change current directory
|
|
|
|
|
|
|
|
Note that the behavior of --cwd option is bit different from this.
|
|
|
|
It does not affect --config parameter.
|
|
|
|
"""
|
2016-02-16 22:21:05 +03:00
|
|
|
path = self._readstr()
|
|
|
|
if not path:
|
2015-12-23 16:23:56 +03:00
|
|
|
return
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
_log("chdir to %r\n" % path)
|
2015-12-23 16:23:56 +03:00
|
|
|
os.chdir(path)
|
|
|
|
|
2016-02-15 17:28:17 +03:00
|
|
|
def setumask(self):
|
|
|
|
"""Change umask"""
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
mask = struct.unpack(">I", self._read(4))[0]
|
|
|
|
_log("setumask %r\n" % mask)
|
2016-02-15 17:28:17 +03:00
|
|
|
os.umask(mask)
|
|
|
|
|
2016-12-16 17:48:37 +03:00
|
|
|
def runcommand(self):
|
2019-09-27 05:09:49 +03:00
|
|
|
# Environment variables might change, reload env.
|
|
|
|
util._reloadenv()
|
2019-08-29 05:22:46 +03:00
|
|
|
args = self._readlist()
|
|
|
|
pycompat.sysargv[1:] = args
|
|
|
|
origui = uimod.ui
|
|
|
|
# Use the class patched by _newchgui so 'system' and 'pager' requests
|
|
|
|
# get forwarded to chg client
|
|
|
|
uimod.ui = self.ui.__class__
|
|
|
|
try:
|
|
|
|
ret = commands.run(
|
|
|
|
[pycompat.sysargv[0]] + args, self.ui.fin, self.ui.fout, self.ui.ferr
|
|
|
|
)
|
|
|
|
self.cresult.write(struct.pack(">i", int(ret & 255)))
|
|
|
|
finally:
|
|
|
|
uimod.ui = origui
|
2016-12-16 17:48:37 +03:00
|
|
|
|
2015-12-23 16:23:56 +03:00
|
|
|
def setenv(self):
|
|
|
|
"""Clear and update os.environ
|
|
|
|
|
|
|
|
Note that not all variables can make an effect on the running process.
|
|
|
|
"""
|
2016-02-16 22:21:05 +03:00
|
|
|
l = self._readlist()
|
2015-12-23 16:23:56 +03:00
|
|
|
try:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
newenv = dict(s.split("=", 1) for s in l if "=" in s)
|
2015-12-23 16:23:56 +03:00
|
|
|
except ValueError:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
raise ValueError("unexpected value in setenv request")
|
|
|
|
_log("setenv: %r\n" % sorted(newenv.keys()))
|
2016-12-17 23:16:39 +03:00
|
|
|
encoding.environ.clear()
|
|
|
|
encoding.environ.update(newenv)
|
2020-01-09 22:49:48 +03:00
|
|
|
# Apply $TZ changes.
|
|
|
|
hgtime.tzset()
|
2015-12-23 16:23:56 +03:00
|
|
|
|
|
|
|
capabilities = commandserver.server.capabilities.copy()
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
capabilities.update(
|
|
|
|
{
|
|
|
|
"attachio": attachio,
|
|
|
|
"chdir": chdir,
|
|
|
|
"runcommand": runcommand,
|
|
|
|
"setenv": setenv,
|
|
|
|
"setumask": setumask,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
if util.safehasattr(util, "setprocname"):
|
2015-12-23 16:23:56 +03:00
|
|
|
|
2017-01-11 02:36:48 +03:00
|
|
|
def setprocname(self):
|
|
|
|
"""Change process title"""
|
|
|
|
name = self._readstr()
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
_log("setprocname: %r\n" % name)
|
2017-04-26 16:26:28 +03:00
|
|
|
util.setprocname(name)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2019-12-04 21:53:06 +03:00
|
|
|
# pyre-fixme[16]: `chgcmdserver` has no attribute `setprocname`.
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
capabilities["setprocname"] = setprocname
|
|
|
|
|
2017-01-11 02:36:48 +03:00
|
|
|
|
chgserver: auto exit after being idle for too long or lose the socket file
This is a part of the one server per config series. In multiple-server setup,
new server may be started for a temporary config change like in command line,
--config extensions.foo=bar.py. This may end up with a lot of not so useful
server processes. Other questions are about socket file and process management,
How to stop these processes? What if a new server wants to listen on a same
address, replacing the old one?
This patch introduces AutoExitMixIn, which will:
1. Exit after being idle for too long. So useless servers won't run forever.
2. Periodically check the ownership of socket file, exit if it is no longer
owned. This brings strong consistency between the filesystem and the
process, and handles some race conditions neatly.
Since rename is atomic, a new server can just have a same server address
with an old one and won't worry about how to make sure the old server is
killed, address conflict, service downtime issues.
The user can safely stop all servers by simply removing the socket files,
without worrying about outdated or accidentally removed pidfiles.
2016-02-24 21:42:59 +03:00
|
|
|
def _tempaddress(address):
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
return "%s.%d.tmp" % (address, os.getpid())
|
|
|
|
|
chgserver: auto exit after being idle for too long or lose the socket file
This is a part of the one server per config series. In multiple-server setup,
new server may be started for a temporary config change like in command line,
--config extensions.foo=bar.py. This may end up with a lot of not so useful
server processes. Other questions are about socket file and process management,
How to stop these processes? What if a new server wants to listen on a same
address, replacing the old one?
This patch introduces AutoExitMixIn, which will:
1. Exit after being idle for too long. So useless servers won't run forever.
2. Periodically check the ownership of socket file, exit if it is no longer
owned. This brings strong consistency between the filesystem and the
process, and handles some race conditions neatly.
Since rename is atomic, a new server can just have a same server address
with an old one and won't worry about how to make sure the old server is
killed, address conflict, service downtime issues.
The user can safely stop all servers by simply removing the socket files,
without worrying about outdated or accidentally removed pidfiles.
2016-02-24 21:42:59 +03:00
|
|
|
|
2019-08-29 05:22:46 +03:00
|
|
|
def _realaddress(address):
|
2016-12-20 01:07:41 +03:00
|
|
|
# if the basename of address contains '.', use only the left part. this
|
|
|
|
# makes it possible for the client to pass 'server.tmp$PID' and follow by
|
|
|
|
# an atomic rename to avoid locking when spawning new servers.
|
|
|
|
dirname, basename = os.path.split(address)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
basename = basename.split(".", 1)[0]
|
2019-08-29 05:22:46 +03:00
|
|
|
return os.path.join(dirname, basename)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2016-03-02 13:10:06 +03:00
|
|
|
|
2016-05-22 07:36:37 +03:00
|
|
|
class chgunixservicehandler(object):
|
|
|
|
"""Set of operations for chg services"""
|
|
|
|
|
|
|
|
pollinterval = 1 # [sec]
|
|
|
|
|
|
|
|
def __init__(self, ui):
|
|
|
|
self.ui = ui
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
self._idletimeout = ui.configint("chgserver", "idletimeout")
|
2016-05-21 12:16:39 +03:00
|
|
|
self._lastactive = time.time()
|
2016-05-22 07:36:37 +03:00
|
|
|
|
|
|
|
def bindsocket(self, sock, address):
|
2019-08-29 05:22:46 +03:00
|
|
|
self._baseaddress = address
|
|
|
|
self._realaddress = _realaddress(address)
|
2016-05-22 07:36:37 +03:00
|
|
|
self._bind(sock)
|
2016-05-22 07:08:30 +03:00
|
|
|
self._createsymlink()
|
2017-04-30 21:21:05 +03:00
|
|
|
# no "listening at" message should be printed to simulate hg behavior
|
2016-05-22 07:08:30 +03:00
|
|
|
|
2016-05-22 07:36:37 +03:00
|
|
|
def _bind(self, sock):
|
chgserver: auto exit after being idle for too long or lose the socket file
This is a part of the one server per config series. In multiple-server setup,
new server may be started for a temporary config change like in command line,
--config extensions.foo=bar.py. This may end up with a lot of not so useful
server processes. Other questions are about socket file and process management,
How to stop these processes? What if a new server wants to listen on a same
address, replacing the old one?
This patch introduces AutoExitMixIn, which will:
1. Exit after being idle for too long. So useless servers won't run forever.
2. Periodically check the ownership of socket file, exit if it is no longer
owned. This brings strong consistency between the filesystem and the
process, and handles some race conditions neatly.
Since rename is atomic, a new server can just have a same server address
with an old one and won't worry about how to make sure the old server is
killed, address conflict, service downtime issues.
The user can safely stop all servers by simply removing the socket files,
without worrying about outdated or accidentally removed pidfiles.
2016-02-24 21:42:59 +03:00
|
|
|
# use a unique temp address so we can stat the file and do ownership
|
|
|
|
# check later
|
2016-05-21 12:16:39 +03:00
|
|
|
tempaddress = _tempaddress(self._realaddress)
|
2016-05-22 07:36:37 +03:00
|
|
|
util.bindunixsocket(sock, tempaddress)
|
2019-12-10 00:09:25 +03:00
|
|
|
self._socketstat = util.stat(tempaddress)
|
2017-04-30 21:08:27 +03:00
|
|
|
sock.listen(socket.SOMAXCONN)
|
2016-05-21 10:42:59 +03:00
|
|
|
# rename will replace the old socket file if exists atomically. the
|
|
|
|
# old server will detect ownership change and exit.
|
2016-05-21 12:16:39 +03:00
|
|
|
util.rename(tempaddress, self._realaddress)
|
chgserver: auto exit after being idle for too long or lose the socket file
This is a part of the one server per config series. In multiple-server setup,
new server may be started for a temporary config change like in command line,
--config extensions.foo=bar.py. This may end up with a lot of not so useful
server processes. Other questions are about socket file and process management,
How to stop these processes? What if a new server wants to listen on a same
address, replacing the old one?
This patch introduces AutoExitMixIn, which will:
1. Exit after being idle for too long. So useless servers won't run forever.
2. Periodically check the ownership of socket file, exit if it is no longer
owned. This brings strong consistency between the filesystem and the
process, and handles some race conditions neatly.
Since rename is atomic, a new server can just have a same server address
with an old one and won't worry about how to make sure the old server is
killed, address conflict, service downtime issues.
The user can safely stop all servers by simply removing the socket files,
without worrying about outdated or accidentally removed pidfiles.
2016-02-24 21:42:59 +03:00
|
|
|
|
2016-05-22 08:05:34 +03:00
|
|
|
def _createsymlink(self):
|
2016-05-21 12:16:39 +03:00
|
|
|
if self._baseaddress == self._realaddress:
|
2016-05-22 08:05:34 +03:00
|
|
|
return
|
2016-05-21 12:16:39 +03:00
|
|
|
tempaddress = _tempaddress(self._baseaddress)
|
|
|
|
os.symlink(os.path.basename(self._realaddress), tempaddress)
|
|
|
|
util.rename(tempaddress, self._baseaddress)
|
2016-05-22 08:05:34 +03:00
|
|
|
|
2016-05-21 12:16:39 +03:00
|
|
|
def _issocketowner(self):
|
chgserver: auto exit after being idle for too long or lose the socket file
This is a part of the one server per config series. In multiple-server setup,
new server may be started for a temporary config change like in command line,
--config extensions.foo=bar.py. This may end up with a lot of not so useful
server processes. Other questions are about socket file and process management,
How to stop these processes? What if a new server wants to listen on a same
address, replacing the old one?
This patch introduces AutoExitMixIn, which will:
1. Exit after being idle for too long. So useless servers won't run forever.
2. Periodically check the ownership of socket file, exit if it is no longer
owned. This brings strong consistency between the filesystem and the
process, and handles some race conditions neatly.
Since rename is atomic, a new server can just have a same server address
with an old one and won't worry about how to make sure the old server is
killed, address conflict, service downtime issues.
The user can safely stop all servers by simply removing the socket files,
without worrying about outdated or accidentally removed pidfiles.
2016-02-24 21:42:59 +03:00
|
|
|
try:
|
2019-12-10 00:09:25 +03:00
|
|
|
stat = util.stat(self._realaddress)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
return (
|
|
|
|
stat.st_ino == self._socketstat.st_ino
|
|
|
|
and stat.st_mtime == self._socketstat.st_mtime
|
|
|
|
)
|
chgserver: auto exit after being idle for too long or lose the socket file
This is a part of the one server per config series. In multiple-server setup,
new server may be started for a temporary config change like in command line,
--config extensions.foo=bar.py. This may end up with a lot of not so useful
server processes. Other questions are about socket file and process management,
How to stop these processes? What if a new server wants to listen on a same
address, replacing the old one?
This patch introduces AutoExitMixIn, which will:
1. Exit after being idle for too long. So useless servers won't run forever.
2. Periodically check the ownership of socket file, exit if it is no longer
owned. This brings strong consistency between the filesystem and the
process, and handles some race conditions neatly.
Since rename is atomic, a new server can just have a same server address
with an old one and won't worry about how to make sure the old server is
killed, address conflict, service downtime issues.
The user can safely stop all servers by simply removing the socket files,
without worrying about outdated or accidentally removed pidfiles.
2016-02-24 21:42:59 +03:00
|
|
|
except OSError:
|
|
|
|
return False
|
|
|
|
|
2016-05-22 07:36:37 +03:00
|
|
|
def unlinksocket(self, address):
|
2016-05-21 12:16:39 +03:00
|
|
|
if not self._issocketowner():
|
chgserver: auto exit after being idle for too long or lose the socket file
This is a part of the one server per config series. In multiple-server setup,
new server may be started for a temporary config change like in command line,
--config extensions.foo=bar.py. This may end up with a lot of not so useful
server processes. Other questions are about socket file and process management,
How to stop these processes? What if a new server wants to listen on a same
address, replacing the old one?
This patch introduces AutoExitMixIn, which will:
1. Exit after being idle for too long. So useless servers won't run forever.
2. Periodically check the ownership of socket file, exit if it is no longer
owned. This brings strong consistency between the filesystem and the
process, and handles some race conditions neatly.
Since rename is atomic, a new server can just have a same server address
with an old one and won't worry about how to make sure the old server is
killed, address conflict, service downtime issues.
The user can safely stop all servers by simply removing the socket files,
without worrying about outdated or accidentally removed pidfiles.
2016-02-24 21:42:59 +03:00
|
|
|
return
|
|
|
|
# it is possible to have a race condition here that we may
|
|
|
|
# remove another server's socket file. but that's okay
|
|
|
|
# since that server will detect and exit automatically and
|
|
|
|
# the client will start a new server on demand.
|
2017-03-21 16:50:28 +03:00
|
|
|
util.tryunlink(self._realaddress)
|
chgserver: auto exit after being idle for too long or lose the socket file
This is a part of the one server per config series. In multiple-server setup,
new server may be started for a temporary config change like in command line,
--config extensions.foo=bar.py. This may end up with a lot of not so useful
server processes. Other questions are about socket file and process management,
How to stop these processes? What if a new server wants to listen on a same
address, replacing the old one?
This patch introduces AutoExitMixIn, which will:
1. Exit after being idle for too long. So useless servers won't run forever.
2. Periodically check the ownership of socket file, exit if it is no longer
owned. This brings strong consistency between the filesystem and the
process, and handles some race conditions neatly.
Since rename is atomic, a new server can just have a same server address
with an old one and won't worry about how to make sure the old server is
killed, address conflict, service downtime issues.
The user can safely stop all servers by simply removing the socket files,
without worrying about outdated or accidentally removed pidfiles.
2016-02-24 21:42:59 +03:00
|
|
|
|
2016-05-22 08:05:34 +03:00
|
|
|
def shouldexit(self):
|
2016-05-21 12:16:39 +03:00
|
|
|
if not self._issocketowner():
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
self.ui.debug("%s is not owned, exiting.\n" % self._realaddress)
|
2016-05-22 08:05:34 +03:00
|
|
|
return True
|
2016-05-21 12:16:39 +03:00
|
|
|
if time.time() - self._lastactive > self._idletimeout:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
self.ui.debug("being idle too long. exiting.\n")
|
2016-05-22 08:05:34 +03:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def newconnection(self):
|
2016-05-21 12:16:39 +03:00
|
|
|
self._lastactive = time.time()
|
2016-05-22 08:05:34 +03:00
|
|
|
|
2016-05-22 07:36:37 +03:00
|
|
|
def createcmdserver(self, repo, conn, fin, fout):
|
2019-08-29 05:22:46 +03:00
|
|
|
return chgcmdserver(self.ui, repo, fin, fout, conn, self._baseaddress)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
chgserver: auto exit after being idle for too long or lose the socket file
This is a part of the one server per config series. In multiple-server setup,
new server may be started for a temporary config change like in command line,
--config extensions.foo=bar.py. This may end up with a lot of not so useful
server processes. Other questions are about socket file and process management,
How to stop these processes? What if a new server wants to listen on a same
address, replacing the old one?
This patch introduces AutoExitMixIn, which will:
1. Exit after being idle for too long. So useless servers won't run forever.
2. Periodically check the ownership of socket file, exit if it is no longer
owned. This brings strong consistency between the filesystem and the
process, and handles some race conditions neatly.
Since rename is atomic, a new server can just have a same server address
with an old one and won't worry about how to make sure the old server is
killed, address conflict, service downtime issues.
The user can safely stop all servers by simply removing the socket files,
without worrying about outdated or accidentally removed pidfiles.
2016-02-24 21:42:59 +03:00
|
|
|
|
2016-05-22 07:13:04 +03:00
|
|
|
def chgunixservice(ui, repo, opts):
|
2017-08-16 20:44:06 +03:00
|
|
|
# CHGINTERNALMARK is set by chg client. It is an indication of things are
|
|
|
|
# started by chg so other code can do things accordingly, like disabling
|
|
|
|
# demandimport or detecting chg client started by chg client. When executed
|
|
|
|
# here, CHGINTERNALMARK is no longer useful and hence dropped to make
|
|
|
|
# environ cleaner.
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if "CHGINTERNALMARK" in encoding.environ:
|
|
|
|
del encoding.environ["CHGINTERNALMARK"]
|
2016-10-15 08:24:29 +03:00
|
|
|
|
2016-05-22 07:13:04 +03:00
|
|
|
if repo:
|
2016-10-18 00:16:55 +03:00
|
|
|
# one chgserver can serve multiple repos. drop repo information
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
ui.setconfig("bundle", "mainreporoot", "", "repo")
|
2016-05-22 07:36:37 +03:00
|
|
|
h = chgunixservicehandler(ui)
|
|
|
|
return commandserver.unixforkingservice(ui, repo=None, opts=opts, handler=h)
|