From: Mike Hommey Date: Sun, 18 Aug 2019 10:28:16 +0000 (+0900) Subject: Bug 1574761 - Avoid race condition creating old-configure. r?build X-Git-Tag: archive/raspbian/68.6.0esr-1+rpi1^2~27 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=f7d420c27616b85bdbb7fbb286d8ce84e9b9b790;p=firefox-esr.git Bug 1574761 - Avoid race condition creating old-configure. r?build This is not something that happens under normal circumstances, but it can happen when you go fancy and run multiple configures in parallel with different objdirs, and old-configure doesn't exist in the first place ; then one configure may overwrite old-configure while another is starting to execute it, resulting in the latter nor executing old-configure completely. Differential Revision: https://phabricator.services.mozilla.com/D42428 Gbp-Pq: Topic fixes Gbp-Pq: Name Bug-1574761-Avoid-race-condition-creating-old-config.patch --- diff --git a/build/moz.configure/old.configure b/build/moz.configure/old.configure index 7286b23ce86..e8d4be4c2cd 100644 --- a/build/moz.configure/old.configure +++ b/build/moz.configure/old.configure @@ -88,6 +88,10 @@ def prepare_mozconfig(mozconfig): @imports(_from='os.path', _import='getmtime') @imports(_from='os.path', _import='exists') @imports(_from='mozbuild.shellutil', _import='quote') +@imports(_from='tempfile', _import='NamedTemporaryFile') +@imports(_from='os', _import='remove') +@imports(_from='os', _import='rename') +@imports(_from='__builtin__', _import='OSError') def prepare_configure(old_configure, mozconfig, autoconf, build_env, shell, old_configure_assignments, build_project): # os.path.abspath in the sandbox will ensure forward slashes on Windows, @@ -129,9 +133,20 @@ def prepare_configure(old_configure, mozconfig, autoconf, build_env, shell, # This could be done with a m4 macro, but it's way easier this way script = script.replace('>./config.log', '>>${CONFIG_LOG=./config.log}') - with open(old_configure, 'wb') as fh: + with NamedTemporaryFile(mode='wb', prefix=os.path.basename(old_configure), + dir=os.path.dirname(old_configure), delete=False) as fh: fh.write(script) + try: + rename(fh.name, old_configure) + except OSError: + try: + # Likely the file already existed (on Windows). Retry after removing it. + remove(old_configure) + rename(fh.name, old_configure) + except OSError: + die('Failed creating old-configure') + cmd = [shell, old_configure] with encoded_open('old-configure.vars', 'w') as out: log.debug('Injecting the following to old-configure:')