env-update: change prelink to use /etc/prelink.conf.d/portage.conf
authorMike Frysinger <vapier@gentoo.org>
Sat, 11 May 2013 19:31:48 +0000 (15:31 -0400)
committerMike Frysinger <vapier@gentoo.org>
Mon, 13 May 2013 00:47:27 +0000 (20:47 -0400)
Newer prelinks can support /etc/prelink.conf.d/ files.  So that prelink
can install /etc/prelink.conf and manage it itself, have env-update only
write /etc/prelink.conf.d/portage.conf instead of clobbering the main
/etc/prelink.conf file.

This should be backwards compatible as portage will conditionally change
/etc/prelink.conf to use the new /etc/prelink.conf.d/ too.

URL: http://bugs.gentoo.org/266855
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
pym/portage/util/env_update.py

index 4c1fbf8915f6ed9c677e28c2cce2397156deb0aa..cf95467af3c0ce0abaffac3fed7882d83fe91df4 100644 (file)
@@ -194,20 +194,35 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
                        myfd.write(x + "\n")
                myfd.close()
 
+       potential_lib_dirs = set()
+       for lib_dir_glob in ('usr/lib*', 'lib*'):
+               x = os.path.join(eroot, lib_dir_glob)
+               for y in glob.glob(_unicode_encode(x,
+                       encoding=_encodings['fs'], errors='strict')):
+                       try:
+                               y = _unicode_decode(y,
+                                       encoding=_encodings['fs'], errors='strict')
+                       except UnicodeDecodeError:
+                               continue
+                       if os.path.basename(y) != 'libexec':
+                               potential_lib_dirs.add(y[len(eroot):])
+
        # Update prelink.conf if we are prelink-enabled
        if prelink_capable:
-               newprelink = atomic_ofstream(os.path.join(
-                       eroot, "etc", "prelink.conf"))
+               prelink_d = os.path.join(eroot, 'etc', 'prelink.conf.d')
+               if not os.path.isdir(prelink_d):
+                       os.makedirs(prelink_d)
+               newprelink = atomic_ofstream(os.path.join(prelink_d, 'portage.conf'))
                newprelink.write("# prelink.conf autogenerated by env-update; make all changes to\n")
                newprelink.write("# contents of /etc/env.d directory\n")
 
-               for x in ["/bin","/sbin","/usr/bin","/usr/sbin","/lib","/usr/lib"]:
-                       newprelink.write("-l %s\n" % (x,));
-               prelink_paths = []
-               prelink_paths += specials.get("LDPATH", [])
-               prelink_paths += specials.get("PATH", [])
-               prelink_paths += specials.get("PRELINK_PATH", [])
-               prelink_path_mask = specials.get("PRELINK_PATH_MASK", [])
+               for x in sorted(potential_lib_dirs) + ['bin', 'sbin']:
+                       newprelink.write('-l /%s\n' % (x,));
+               prelink_paths = set()
+               prelink_paths |= set(specials.get('LDPATH', []))
+               prelink_paths |= set(specials.get('PATH', []))
+               prelink_paths |= set(specials.get('PRELINK_PATH', []))
+               prelink_path_mask = specials.get('PRELINK_PATH_MASK', [])
                for x in prelink_paths:
                        if not x:
                                continue
@@ -228,24 +243,24 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
                        newprelink.write("-b %s\n" % (x,))
                newprelink.close()
 
+               # Migration code path.  If /etc/prelink.conf was generated by us, then
+               # point it to the new stuff until the prelink package re-installs.
+               prelink_conf = os.path.join(eroot, 'etc', 'prelink.conf')
+               try:
+                       with open(prelink_conf, 'rb') as f:
+                               if f.readline() == b'# prelink.conf autogenerated by env-update; make all changes to\n':
+                                       f = atomic_ofstream(prelink_conf)
+                                       f.write('-c /etc/prelink.conf.d/*.conf\n')
+                                       f.close()
+               except IOError as e:
+                       if e.errno != errno.ENOENT:
+                               raise
+
        current_time = long(time.time())
        mtime_changed = False
 
-       potential_lib_dirs = []
-       for lib_dir_glob in ['usr/lib*', 'lib*']:
-               x = os.path.join(eroot, lib_dir_glob)
-               for y in glob.glob(_unicode_encode(x,
-                       encoding=_encodings['fs'], errors='strict')):
-                       try:
-                               y = _unicode_decode(y,
-                                       encoding=_encodings['fs'], errors='strict')
-                       except UnicodeDecodeError:
-                               continue
-                       if os.path.basename(y) != "libexec":
-                               potential_lib_dirs.append(y[len(eroot):])
-
        lib_dirs = set()
-       for lib_dir in set(specials["LDPATH"] + potential_lib_dirs):
+       for lib_dir in set(specials['LDPATH']) | potential_lib_dirs:
                x = os.path.join(eroot, lib_dir.lstrip(os.sep))
                try:
                        newldpathtime = os.stat(x)[stat.ST_MTIME]