* [gentoo-portage-dev] [PATCH] env-update: change prelink to use /etc/prelink.conf.d/portage.conf
@ 2013-05-11 19:45 Mike Frysinger
2013-05-11 22:45 ` Zac Medico
2013-05-13 0:49 ` [gentoo-portage-dev] [PATCH v2] " Mike Frysinger
0 siblings, 2 replies; 5+ messages in thread
From: Mike Frysinger @ 2013-05-11 19:45 UTC (permalink / raw
To: gentoo-portage-dev
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 | 57 +++++++++++++++++++++++++-----------------
1 file changed, 34 insertions(+), 23 deletions(-)
diff --git a/pym/portage/util/env_update.py b/pym/portage/util/env_update.py
index 4c1fbf8..8dc6348 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,20 @@ 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')
+ if os.path.exists(prelink_conf):
+ if open(prelink_conf).readline() == '# 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()
+
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]
--
1.8.2.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] env-update: change prelink to use /etc/prelink.conf.d/portage.conf
2013-05-11 19:45 [gentoo-portage-dev] [PATCH] env-update: change prelink to use /etc/prelink.conf.d/portage.conf Mike Frysinger
@ 2013-05-11 22:45 ` Zac Medico
2013-05-12 4:00 ` Zac Medico
2013-05-13 0:49 ` [gentoo-portage-dev] [PATCH v2] " Mike Frysinger
1 sibling, 1 reply; 5+ messages in thread
From: Zac Medico @ 2013-05-11 22:45 UTC (permalink / raw
To: gentoo-portage-dev
On Sat, May 11, 2013 at 12:45 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> + # 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')
> + if os.path.exists(prelink_conf):
> + if open(prelink_conf).readline() == '# prelink.conf autogenerated by env-update; make all changes to\n':
I would do it like this:
with open(prelink_conf, 'rb') as f:
if f.readline() == b'# prelink.conf autogenerated by
env-update; make all changes to\n':
The "with" block prevents resource warning messages with python3, and
using binary mode side-steps potential unicode decode errors.
Other than that, the patch looks good to me.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] env-update: change prelink to use /etc/prelink.conf.d/portage.conf
2013-05-11 22:45 ` Zac Medico
@ 2013-05-12 4:00 ` Zac Medico
0 siblings, 0 replies; 5+ messages in thread
From: Zac Medico @ 2013-05-12 4:00 UTC (permalink / raw
To: gentoo-portage-dev
Also, it's better to handle ENOENT from open than to use
os.path.exists() first (no race condition that way).
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gentoo-portage-dev] [PATCH v2] env-update: change prelink to use /etc/prelink.conf.d/portage.conf
2013-05-11 19:45 [gentoo-portage-dev] [PATCH] env-update: change prelink to use /etc/prelink.conf.d/portage.conf Mike Frysinger
2013-05-11 22:45 ` Zac Medico
@ 2013-05-13 0:49 ` Mike Frysinger
2013-05-13 5:46 ` Zac Medico
1 sibling, 1 reply; 5+ messages in thread
From: Mike Frysinger @ 2013-05-13 0:49 UTC (permalink / raw
To: gentoo-portage-dev
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>
---
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 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]
--
1.8.2.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [gentoo-portage-dev] [PATCH v2] env-update: change prelink to use /etc/prelink.conf.d/portage.conf
2013-05-13 0:49 ` [gentoo-portage-dev] [PATCH v2] " Mike Frysinger
@ 2013-05-13 5:46 ` Zac Medico
0 siblings, 0 replies; 5+ messages in thread
From: Zac Medico @ 2013-05-13 5:46 UTC (permalink / raw
To: gentoo-portage-dev
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 <vapier@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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-05-13 5:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-11 19:45 [gentoo-portage-dev] [PATCH] env-update: change prelink to use /etc/prelink.conf.d/portage.conf Mike Frysinger
2013-05-11 22:45 ` Zac Medico
2013-05-12 4:00 ` Zac Medico
2013-05-13 0:49 ` [gentoo-portage-dev] [PATCH v2] " Mike Frysinger
2013-05-13 5:46 ` Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox