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

login
register
mail settings
Submitter Jun Wu
Date April 4, 2016, 2:30 a.m.
Message ID <5296c1133b6891491931.1459737050@x1c>
Download mbox | patch
Permalink /patch/14320/
State Accepted
Headers show

Comments

Jun Wu - April 4, 2016, 2:30 a.m.
# HG changeset patch
# User Jun Wu <quark@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.

Patch

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