[PATCH 3 of 7] chgserver: change random state after fork

Jun Wu quark at fb.com
Sun Apr 3 22:30:50 EDT 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1459731597 -3600
#      Mon Apr 04 01:59:57 2016 +0100
# Node ID 5296c1133b689149193119442b9c7a1c723a421e
# Parent  ffe771bf6fa7d5a81a9c9335f28c23688775fc2c
chgserver: change random state after fork

Before this patch, extensions expecting a different random state per command
will break since the chg request handler will inherit a same random state
from the parent daemon process.

This patch addresses the issue by calling random.seed() after fork.

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -45,6 +45,7 @@
 import gc
 import inspect
 import os
+import random
 import re
 import struct
 import sys
@@ -544,6 +545,9 @@
         # process pass kernel "is_current_pgrp_orphaned" check so signals like
         # SIGTSTP, SIGTTIN, SIGTTOU are not ignored.
         os.setpgid(0, 0)
+        # change random state otherwise forked request handlers would have a
+        # same state inherited from parent.
+        random.seed()
         ui = self.server.ui
         repo = self.server.repo
         sv = None


More information about the Mercurial-devel mailing list