[PATCH] cmdserver: add command to get pid of server handling current connection

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Oct 17 16:29:28 CDT 2014



On 10/17/2014 08:39 AM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1413556690 -32400
> #      Fri Oct 17 23:38:10 2014 +0900
> # Node ID 1b432767e0829aba65a8f63bdcdb3bb9cabbce4f
> # Parent  840be5ca03e1db16ba994e55597771c418166c97
> cmdserver: add command to get pid of server handling current connection
>
> Since unix-mode server forks child process per request, client cannot know
> the pid of the server, which is necessary to send SIGINT for example.
>
> Though Linux has getsockopt(SO_PEERCRED), it cannot be used because the server
> fork()s after accept().  So commandserver should provide "getpid" command.

I'm not super excited about this, but I can see why this is necessary.

I've a bit confused about how you get:

(1) the child processing your request to reply to the same one
(2) the child processing your request to reply to this as it is blocked 
replying to the request.

I've technical feedback on the patch itself.

> diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
> --- a/mercurial/commandserver.py
> +++ b/mercurial/commandserver.py
> @@ -212,6 +212,9 @@ class server(object):
>           """ writes the current encoding to the result channel """
>           self.cresult.write(encoding.encoding)
>
> +    def getpid(self):
> +        self.cresult.write(struct.pack('>i', os.getpid()))
> +

geeh, binary return? Seems not in line with the current command server 
architecture. Can we use ascii instead? (eg question: How is a bash 
script talking to command server expected to handle this binary encoded 
integer?)

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list