Patchwork D7615: procutil: try and avoid angering CoreFoundation on macOS

login
register
mail settings
Submitter phabricator
Date Dec. 17, 2019, 12:56 p.m.
Message ID <d06acdac25c7ad9f8a976aa1bb3984c7@localhost.localdomain>
Download mbox | patch
Permalink /patch/43915/
State Not Applicable
Headers show

Comments

phabricator - Dec. 17, 2019, 12:56 p.m.
Closed by commit rHGa89381e04c58: procutil: try and avoid angering CoreFoundation on macOS (authored by durin42).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7615?vs=18755&id=18807

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7615/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7615

AFFECTED FILES
  mercurial/utils/procutil.py

CHANGE DETAILS




To: durin42, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -423,7 +423,10 @@ 
     return rc
 
 
-def gui():
+_is_gui = None
+
+
+def _gui():
     '''Are we running in a GUI?'''
     if pycompat.isdarwin:
         if b'SSH_CONNECTION' in encoding.environ:
@@ -439,6 +442,13 @@ 
         return pycompat.iswindows or encoding.environ.get(b"DISPLAY")
 
 
+def gui():
+    global _is_gui
+    if _is_gui is None:
+        _is_gui = _gui()
+    return _is_gui
+
+
 def hgcmd():
     """Return the command used to execute current hg
 
@@ -583,6 +593,11 @@ 
         `Subprocess.wait` function for the spawned process.  This is mostly
         useful for developers that need to make sure the spawned process
         finished before a certain point. (eg: writing test)'''
+        if pycompat.isdarwin:
+            # avoid crash in CoreFoundation in case another thread
+            # calls gui() while we're calling fork().
+            gui()
+
         # double-fork to completely detach from the parent process
         # based on http://code.activestate.com/recipes/278731
         if record_wait is None: