yifengyou / rpms / yum

Forked from rpms/yum 3 years ago
Clone

Blame SOURCES/BZ-1458841-preload-shared-libs.patch

5e9bef
diff -up yum-3.4.3/cli.py.orig yum-3.4.3/cli.py
5e9bef
--- yum-3.4.3/cli.py.orig	2017-06-29 17:44:53.784522557 +0200
5e9bef
+++ yum-3.4.3/cli.py	2017-06-29 17:46:16.249149700 +0200
5e9bef
@@ -28,6 +28,7 @@ import logging
5e9bef
 import math
5e9bef
 from optparse import OptionParser,OptionGroup,SUPPRESS_HELP
5e9bef
 import rpm
5e9bef
+import ctypes
5e9bef
 
5e9bef
 from weakref import proxy as weakref
5e9bef
 
5e9bef
@@ -779,6 +780,38 @@ class YumBaseCli(yum.YumBase, output.Yum
5e9bef
         if self.conf.debuglevel < 2:
5e9bef
             cb.display.output = False
5e9bef
 
5e9bef
+        # Whenever we upgrade a shared library (and its dependencies) which the
5e9bef
+        # yum process itself may dlopen() post-transaction (e.g. in a plugin
5e9bef
+        # hook), we may end up in a situation where the upgraded library and
5e9bef
+        # the pre-transaction version of a library it depends on which is ABI
5e9bef
+        # incompatible are loaded in memory at the same time, leading to
5e9bef
+        # unpredictable behavior and possibly a crash.  Let's avoid that by
5e9bef
+        # preloading all such dynamically loaded libraries pre-transaction so
5e9bef
+        # that dlopen(), if called post-transaction, uses those instead of
5e9bef
+        # loading the newly installed versions.
5e9bef
+        preload = {
5e9bef
+            # Loaded by libcurl, see BZ#1458841
5e9bef
+            'nss-sysinit': ['libnsssysinit.so'],
5e9bef
+        }
5e9bef
+        for pkg in preload:
5e9bef
+            # Only preload the libs if the package is actually installed and we
5e9bef
+            # are changing it with the transaction
5e9bef
+            if not self.tsInfo.matchNaevr(name=pkg) or \
5e9bef
+                    not self.rpmdb.searchNevra(name=pkg):
5e9bef
+                continue
5e9bef
+            for lib in preload[pkg]:
5e9bef
+                try:
5e9bef
+                    ctypes.cdll.LoadLibrary(lib)
5e9bef
+                    self.verbose_logger.log(
5e9bef
+                        yum.logginglevels.DEBUG_4,
5e9bef
+                        _('Preloaded shared library %s') % lib
5e9bef
+                    )
5e9bef
+                except Exception as e:
5e9bef
+                    self.verbose_logger.log(
5e9bef
+                        yum.logginglevels.DEBUG_4,
5e9bef
+                        _('Could not preload shared library %s: %s') % (lib, e)
5e9bef
+                    )
5e9bef
+
5e9bef
         self.verbose_logger.log(yum.logginglevels.INFO_2, _('Running transaction'))
5e9bef
         resultobject = self.runTransaction(cb=cb)
5e9bef