Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/
Date: Sun, 30 Dec 2012 09:36:21
Message-Id: 1356859990.7ebb2f54877edb28621c33e380f8777b1b1dc201.zmedico@gentoo
1 commit: 7ebb2f54877edb28621c33e380f8777b1b1dc201
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Sun Dec 30 09:33:10 2012 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Sun Dec 30 09:33:10 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=7ebb2f54
7
8 Use ctypes in subprocess for bug #448858.
9
10 Isolate ctypes usage in a subprocess, in order to avoid potential
11 problems with stale cached libraries as described in bug #448858,
12 comment #14 (also see http://bugs.python.org/issue14597).
13
14 ---
15 pym/portage/dbapi/_SyncfsProcess.py | 53 +++++++++++++++++++++++++++++++++++
16 pym/portage/dbapi/vartree.py | 47 +++++++++---------------------
17 2 files changed, 67 insertions(+), 33 deletions(-)
18
19 diff --git a/pym/portage/dbapi/_SyncfsProcess.py b/pym/portage/dbapi/_SyncfsProcess.py
20 new file mode 100644
21 index 0000000..7518214
22 --- /dev/null
23 +++ b/pym/portage/dbapi/_SyncfsProcess.py
24 @@ -0,0 +1,53 @@
25 +# Copyright 2012 Gentoo Foundation
26 +# Distributed under the terms of the GNU General Public License v2
27 +
28 +from portage import os
29 +from portage.util._ctypes import find_library, LoadLibrary
30 +from portage.util._async.ForkProcess import ForkProcess
31 +
32 +class SyncfsProcess(ForkProcess):
33 + """
34 + Isolate ctypes usage in a subprocess, in order to avoid
35 + potential problems with stale cached libraries as
36 + described in bug #448858, comment #14 (also see
37 + http://bugs.python.org/issue14597).
38 + """
39 +
40 + __slots__ = ('paths',)
41 +
42 + @staticmethod
43 + def _get_syncfs():
44 +
45 + filename = find_library("c")
46 + if filename is not None:
47 + library = LoadLibrary(filename)
48 + if library is not None:
49 + try:
50 + return library.syncfs
51 + except AttributeError:
52 + pass
53 +
54 + return None
55 +
56 + def _run(self):
57 +
58 + syncfs_failed = False
59 + syncfs = self._get_syncfs()
60 +
61 + if syncfs is not None:
62 + for path in self.paths:
63 + try:
64 + fd = os.open(path, os.O_RDONLY)
65 + except OSError:
66 + pass
67 + else:
68 + try:
69 + if syncfs(fd) != 0:
70 + # Happens with PyPy (bug #446610)
71 + syncfs_failed = True
72 + finally:
73 + os.close(fd)
74 +
75 + if syncfs is None or syncfs_failed:
76 + return 1
77 + return os.EX_OK
78
79 diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
80 index 840e796..7a930e5 100644
81 --- a/pym/portage/dbapi/vartree.py
82 +++ b/pym/portage/dbapi/vartree.py
83 @@ -11,6 +11,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
84 'portage.data:portage_gid,portage_uid,secpass',
85 'portage.dbapi.dep_expand:dep_expand',
86 'portage.dbapi._MergeProcess:MergeProcess',
87 + 'portage.dbapi._SyncfsProcess:SyncfsProcess',
88 'portage.dep:dep_getkey,isjustname,isvalidatom,match_from_list,' + \
89 'use_reduce,_get_slot_re,_slot_separator,_repo_separator',
90 'portage.eapi:_get_eapi_attrs',
91 @@ -29,7 +30,6 @@ portage.proxy.lazyimport.lazyimport(globals(),
92 'portage.util.env_update:env_update',
93 'portage.util.listdir:dircache,listdir',
94 'portage.util.movefile:movefile',
95 - 'portage.util._ctypes:find_library,LoadLibrary',
96 'portage.util._dyn_libs.PreservedLibsRegistry:PreservedLibsRegistry',
97 'portage.util._dyn_libs.LinkageMapELF:LinkageMapELF@LinkageMap',
98 'portage.util._async.SchedulerInterface:SchedulerInterface',
99 @@ -4731,28 +4731,22 @@ class dblink(object):
100 "merge-sync" not in self.settings.features:
101 return
102
103 - syncfs_failed = False
104 - syncfs = _get_syncfs()
105 + returncode = None
106 + if platform.system() == "Linux":
107
108 - if syncfs is not None:
109 + paths = []
110 for path in self._device_path_map.values():
111 - if path is False:
112 - continue
113 - try:
114 - fd = os.open(path, os.O_RDONLY)
115 - except OSError:
116 - pass
117 - else:
118 - try:
119 - if syncfs(fd) != 0:
120 - # Happens with PyPy (bug #446610)
121 - syncfs_failed = True
122 - except OSError:
123 - pass
124 - finally:
125 - os.close(fd)
126 + if path is not False:
127 + paths.append(path)
128 + paths = tuple(paths)
129 +
130 + proc = SyncfsProcess(paths=paths,
131 + scheduler=(self._scheduler or
132 + SchedulerInterface(EventLoop(main=False))))
133 + proc.start()
134 + returncode = proc.wait()
135
136 - if syncfs is None or syncfs_failed:
137 + if returncode is None or returncode != os.EX_OK:
138 try:
139 proc = subprocess.Popen(["sync"])
140 except EnvironmentError:
141 @@ -4938,19 +4932,6 @@ class dblink(object):
142 finally:
143 self.unlockdb()
144
145 -def _get_syncfs():
146 - if platform.system() == "Linux":
147 - filename = find_library("c")
148 - if filename is not None:
149 - library = LoadLibrary(filename)
150 - if library is not None:
151 - try:
152 - return library.syncfs
153 - except AttributeError:
154 - pass
155 -
156 - return None
157 -
158 def merge(mycat, mypkg, pkgloc, infloc,
159 myroot=None, settings=None, myebuild=None,
160 mytree=None, mydbapi=None, vartree=None, prev_mtimes=None, blockers=None,