[PATCH 2 of 2 V2] commandserver: update comment about setpgid

Jun Wu quark at fb.com
Mon Jul 18 15:04:48 UTC 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1468853948 -3600
#      Mon Jul 18 15:59:08 2016 +0100
# Node ID 474ce833d35dbe14d3e3f804d1df5fd063734833
# Parent  c782f543300c7cf3b52d64dfbf4f5b9e3878e1c7
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 474ce833d35d
commandserver: update comment about setpgid

Now setpgid has 2 main purposes: better handling for terminal-generated
SIGTSTP, SIGINT, and process-exit-generated SIGHUP. Update the comment to
explain things more clearly.

diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -343,9 +343,17 @@ class pipeservice(object):
             _restoreio(ui, fin, fout)
 
 def _initworkerprocess():
-    # use a different process group from the master process, making this
-    # process pass kernel "is_current_pgrp_orphaned" check so signals like
-    # SIGTSTP, SIGTTIN, SIGTTOU are not ignored.
+    # use a different process group from the master process, in order to:
+    # 1. make the current process group no longer "orphaned" (because the
+    #    parent of this process is in a different process group while
+    #    remains in a same session)
+    #    according to POSIX 2.2.2.52, orphaned process group will ignore
+    #    terminal-generated stop signals like SIGTSTP (Ctrl+Z), which will
+    #    cause trouble for things like ncurses.
+    # 2. the client can use kill(-pgid, sig) to simulate terminal-generated
+    #    SIGINT (Ctrl+C) and process-exit-generated SIGHUP. our child
+    #    processes like ssh will be killed properly, without affecting
+    #    unrelated processes.
     os.setpgid(0, 0)
     # change random state otherwise forked request handlers would have a
     # same state inherited from parent.



More information about the Mercurial-devel mailing list