# HG changeset patch # User Brendan Cully # Date 2008-12-01 21:38:26 # Node ID fca9947652ce5625f92f993913ece9ac6effc326 # Parent 79d1bb737c16b343e33be7cd7e22dcc4e7bfab0b inotify: close most file descriptors when autostarting Otherwise, operations that autostart while talking to an SSH repository prevent SSH stderr from closing normally. This causes hangs at the end of hg clone or hg pull -u. diff --git a/hgext/inotify/server.py b/hgext/inotify/server.py --- a/hgext/inotify/server.py +++ b/hgext/inotify/server.py @@ -708,6 +708,26 @@ class Master(object): timeobj.handle_timeout() def start(ui, repo): + def closefds(ignore): + # (from python bug #1177468) + # close all inherited file descriptors + # Python 2.4.1 and later use /dev/urandom to seed the random module's RNG + # a file descriptor is kept internally as os._urandomfd (created on demand + # the first time os.urandom() is called), and should not be closed + try: + os.urandom(4) + urandom_fd = getattr(os, '_urandomfd', None) + except AttributeError: + urandom_fd = None + ignore.append(urandom_fd) + for fd in range(3, 256): + if fd in ignore: + continue + try: + os.close(fd) + except OSError: + pass + m = Master(ui, repo) sys.stdout.flush() sys.stderr.flush() @@ -716,6 +736,7 @@ def start(ui, repo): if pid: return pid + closefds([m.server.fileno(), m.watcher.fileno()]) os.setsid() fd = os.open('/dev/null', os.O_RDONLY)