[gentoo-portage-dev] [PATCH v2] env-update: change prelink to use /etc/prelink.conf.d/portage.conf

2013-05-12 Thread Mike Frysinger
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 vap...@gentoo.org
---
v2
- tweak prelink.conf update style

 pym/portage/util/env_update.py | 61 ++
 1 file changed, 38 insertions(+), 23 deletions(-)

diff --git a/pym/portage/util/env_update.py b/pym/portage/util/env_update.py
index 4c1fbf8..cf95467 100644
--- a/pym/portage/util/env_update.py
+++ b/pym/portage/util/env_update.py
@@ -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 

Re: [gentoo-portage-dev] [PATCH v2] env-update: change prelink to use /etc/prelink.conf.d/portage.conf

2013-05-12 Thread Zac Medico

On 05/12/2013 05:49 PM, Mike Frysinger wrote:

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 vap...@gentoo.org
---
v2
- tweak prelink.conf update style

  pym/portage/util/env_update.py | 61 ++
  1 file changed, 38 insertions(+), 23 deletions(-)


Looks good to me.
--
Thanks,
Zac