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

Yuya Nishihara yuya at tcha.org
Fri Oct 17 21:57:36 CDT 2014


On Fri, 17 Oct 2014 15:21:22 -0700, Pierre-Yves David wrote:
> On 10/17/2014 03:12 PM, Idan Kamara wrote:
> > On Fri, Oct 17, 2014 at 2:29 PM, Pierre-Yves David
> > <pierre-yves.david at ens-lyon.org> wrote:
> >> 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 believe the idea here is that a client connected to a socket mode server
> > wants a way to interrupt it by sending it a SIGINT, for which it needs its
> > pid.
> >
> > So the flow is:
> >
> > 1) client connects to server
> > 2) client runs command that hangs
> > 3) user interrupts hung client
> > 4) client sig handler can interrupt server since it now has its pid
> 
> I got the main goal. But there is soem fork business going on. Is there 
> a fork per connection of a fork per request ? if it is per connection I 
> asssumes we have to get the pid at connection time for later use,

A fork per connection.

So, the hello message will be better place.

On Fri, 17 Oct 2014 14:29:28 -0700, Pierre-Yves David wrote:
> > +    def getpid(self):
> > +        self.cresult.write(struct.pack('>i', os.getpid()))
> > +
> 
> geeh, binary return? Seems not in line with the current command server 
> architecture.

The return code of "runcommand" is int32_t.

Regards,


More information about the Mercurial-devel mailing list