Workaround for glibc > 2.33 breaking web engine

This commit is contained in:
Kovid Goyal 2022-04-25 15:30:10 +05:30
parent 93961cb8ab
commit f4b034f60e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -399,6 +399,26 @@ def is_widescreen():
return _is_widescreen
def disable_webengine_sandbox_if_needed():
# See https://sourceware.org/glibc/wiki/Glibc%20Timeline
if not isfrozen or iswindows or ismacos or QT_VERSION >= 0x60000:
return
import ctypes
libc = ctypes.CDLL(None)
try:
f = libc.gnu_get_libc_version
except AttributeError:
return
f.restype = ctypes.c_char_p
ver = f().decode('ascii')
q = tuple(map(int, ver.split('.')))
if q >= (2, 34):
setattr(disable_webengine_sandbox_if_needed, 'done', True)
setattr(disable_webengine_sandbox_if_needed, 'orig_val', os.environ.get('QTWEBENGINE_DISABLE_SANDBOX'))
print('Disabling Qt WebEngine sandbox as version of glibc on this system will break it', file=sys.stderr)
os.environ['QTWEBENGINE_DISABLE_SANDBOX'] = '1'
def extension(path):
return os.path.splitext(path)[1][1:].lower()
@ -925,6 +945,7 @@ class Application(QApplication):
def __init__(self, args, force_calibre_style=False, override_program_name=None, headless=False, color_prefs=gprefs, windows_app_uid=None):
self.ignore_palette_changes = False
disable_webengine_sandbox_if_needed()
QNetworkProxyFactory.setUseSystemConfiguration(True)
# Allow import of webengine after construction of QApplication on new
# enough PyQt
@ -1301,6 +1322,8 @@ def sanitize_env_vars():
else:
env_vars = {}
if getattr(disable_webengine_sandbox_if_needed, 'done', False):
env_vars['QTWEBENGINE_DISABLE_SANDBOX'] = None
originals = {x:os.environ.get(x, '') for x in env_vars}
changed = {x:False for x in env_vars}
for var, suffix in iteritems(env_vars):
@ -1313,6 +1336,8 @@ def sanitize_env_vars():
del os.environ[var]
changed[var] = True
if getattr(disable_webengine_sandbox_if_needed, 'orig_val', False):
os.environ['QTWEBENGINE_DISABLE_SANDBOX'] = disable_webengine_sandbox_if_needed.orig_val
try:
yield
finally: