67 | 67 |
|
68 | 68 |
lc_all_c_env = os.environ
|
69 | 69 |
lc_all_c_env['LC_ALL'] = 'C'
|
70 | |
|
|
70 |
blacklistFiles = []
|
|
71 |
blacklist = []
|
71 | 72 |
|
72 | 73 |
# Process options
|
73 | 74 |
try:
|
74 | |
opts, args = getopt.getopt(sys.argv[1:], "hvpa", ["help", "verbose", "packages", "all"])
|
|
75 |
opts, args = getopt.getopt(sys.argv[1:], "hvpab:", ["help", "verbose", "packages", "all", "blacklist"])
|
75 | 76 |
except getopt.GetoptError, err:
|
76 | 77 |
# print help information and exit:
|
77 | 78 |
print str(err) # will print something like "option -x not recognized"
|
|
97 | 98 |
elif o in ("-a", "--all"):
|
98 | 99 |
allFiles = True
|
99 | 100 |
onlyPackageFiles = False
|
|
101 |
elif o in ("-b", "--blacklist"):
|
|
102 |
blacklistFiles.append(a)
|
|
103 |
onlyPackageFiles = False
|
100 | 104 |
else:
|
101 | 105 |
assert False, "unhandled option"
|
|
106 |
|
|
107 |
for f in blacklistFiles:
|
|
108 |
for line in file(f, "r"):
|
|
109 |
if line.startswith("#"):
|
|
110 |
continue
|
|
111 |
blacklist.append(re.compile(line.strip()))
|
102 | 112 |
|
103 | 113 |
# Start checking
|
104 | 114 |
|
|
113 | 123 |
# TODO - This does not work yet:
|
114 | 124 |
# toRestart = psdelcheck()
|
115 | 125 |
|
116 | |
toRestart = lsofcheck()
|
|
126 |
toRestart = lsofcheck(blacklist = blacklist)
|
117 | 127 |
|
118 | 128 |
print "Found %d processes using old versions of upgraded files" % len(toRestart)
|
119 | 129 |
|
|
225 | 235 |
for process in package.processes:
|
226 | 236 |
print "\t%s\t%s" % (process.pid,process.program)
|
227 | 237 |
|
228 | |
def lsofcheck():
|
|
238 |
def lsofcheck(blacklist = None):
|
229 | 239 |
processes = {}
|
230 | 240 |
|
231 | 241 |
for line in os.popen('lsof +XL -F nf').readlines():
|
|
253 | 263 |
# Save the descriptor for later comparison
|
254 | 264 |
process.descriptors.append(data)
|
255 | 265 |
|
256 | |
toRestart = filter(lambda process: process.needsRestart(),
|
|
266 |
toRestart = filter(lambda process: process.needsRestart(blacklist),
|
257 | 267 |
processes.values())
|
258 | 268 |
return toRestart
|
259 | 269 |
|
|
261 | 271 |
# Returns:
|
262 | 272 |
# - 0 (NO) for known locations of files which might be deleted
|
263 | 273 |
# - 1 (YES) for valid deleted files we are interested in
|
264 | |
def isdeletedFile (f):
|
|
274 |
def isdeletedFile (f, blacklist = None):
|
265 | 275 |
|
266 | 276 |
global lc_all_c_env
|
267 | 277 |
|
268 | 278 |
if allFiles:
|
269 | 279 |
return 1
|
|
280 |
if blacklist:
|
|
281 |
for p in blacklist:
|
|
282 |
if p.search(f):
|
|
283 |
return 0
|
270 | 284 |
# We don't care about log files
|
271 | 285 |
if f.startswith('/var/log/'):
|
272 | 286 |
return 0
|
|
468 | 482 |
# Returns:
|
469 | 483 |
# - 0 if there is no need to restart the process
|
470 | 484 |
# - 1 if the process needs to be restarted
|
471 | |
def needsRestart(self):
|
|
485 |
def needsRestart(self, blacklist = None):
|
472 | 486 |
for f in self.files:
|
473 | |
if isdeletedFile(f):
|
|
487 |
if isdeletedFile(f, blacklist):
|
474 | 488 |
return 1
|
475 | 489 |
for f in self.links:
|
476 | 490 |
if f == 0:
|