Codebase list debian-goodies / 3c50c6f
- Add excludepid option, which was missing. - Add more verbose messages and prepend all verbose messages with [DEBUG] Javier Fernandez-Sanguino 9 years ago
1 changed file(s) with 24 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
6565 return 1
6666
6767 def usage():
68 sys.stderr.write('usage: checkrestart [-vhpa] [-bblacklist] [-iignore]\n')
68 sys.stderr.write('usage: checkrestart [-vhpa] [ -b blacklist_file ] [ -i package_name ] [ -e pid ]\n')
6969
7070 def main():
7171 global lc_all_c_env, file_query_check
8484
8585 # Process options
8686 try:
87 opts, args = getopt.getopt(sys.argv[1:], "hvpab:i:n", ["help", "verbose", "packages", "all", "blacklist", "ignore", "nolsof"])
87 opts, args = getopt.getopt(sys.argv[1:], "hvpab:i:ne:", ["help", "verbose", "packages", "all", "blacklist", "ignore", "nolsof", "excludepid"])
8888 except getopt.GetoptError, err:
8989 # print help information and exit:
9090 print str(err) # will print something like "option -x not recognized"
142142 # Check if we have lsof, if not, use an alternative mechanism
143143 if not find_cmd('lsof') or not useLsof:
144144 if verbose and not find_cmd('lsof'):
145 print "Lsof is not available in the system. Using alternative mechanism."
145 print "[DEBUG] Lsof is not available in the system. Using alternative mechanism."
146146 toRestart = procfilescheck(blacklist = blacklist, excludepidlist = excludepidlist)
147147 else:
148148 toRestart = lsoffilescheck(blacklist = blacklist)
166166 #services Verbose information
167167 if verbose:
168168 for process in toRestart:
169 print "Process %s (PID: %d) " % (process.program, process.pid)
169 print "[DEBUG] Process %s (PID: %d) " % (process.program, process.pid)
170170 process.listDeleted()
171171
172172 packages = {}
173173 diverted = None
174174
175175 dpkgQuery = ["dpkg-query", "--search"] + programs.keys()
176 if verbose:
177 print "[DEBUG] Running:%s" % dpkgQuery
176178 dpkgProc = subprocess.Popen(dpkgQuery, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
177179 env = lc_all_c_env)
178 if verbose:
179 print "Running:%s" % dpkgQuery
180180 while True:
181181 line = dpkgProc.stdout.readline()
182182 if not line:
183183 break
184184 if verbose:
185 print "Reading line: %s" % line
185 print "[DEBUG] Reading line from dpkg-query: %s" % line
186186 if line.startswith('local diversion'):
187187 continue
188188 if not ':' in line:
206206 packages.setdefault(packagename,Package(packagename))
207207 try:
208208 packages[packagename].processes.extend(programs[program])
209 if verbose:
210 print "[DEBUG] Found package %s for program %s" % (packagename, program)
209211 except KeyError:
210212 sys.stderr.write ('checkrestart (program not found): %s: %s\n' % (packagename, program))
211213 sys.stdout.flush()
216218 # Remove the ignored packages from the list of packages
217219 if ignorelist:
218220 for i in ignorelist:
219 try:
220 del packages[i]
221 except KeyError:
222 continue
221 if i in packages:
222 if verbose:
223 print "[DEBUG] Removing %s from the package list (ignored)" % (i)
224 try:
225 del packages[i]
226 except KeyError:
227 continue
223228
224229 print "(%d distinct packages)" % len(packages)
225230
230235
231236 for package in packages.values():
232237 dpkgQuery = ["dpkg-query", "--listfiles", package.name]
238 if verbose:
239 print "[DEBUG] Running:%s" % dpkgQuery
233240 dpkgProc = subprocess.Popen(dpkgQuery, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
234241 env = lc_all_c_env)
235242 while True:
402409 file_in_package = False
403410 file_regexp = False
404411 if verbose:
405 print "Checking if file %s belongs to any package" % f
412 print "[DEBUG] Checking if file %s belongs to any package" % f
406413 # First check if the file exists
407414 if not os.path.exists(f):
408415 if ( f.startswith('/lib/') or f.startswith('/usr/lib/') ) and re.compile("\.so[\d.]+$"):
420427
421428 # If it exists, run dpkg-query
422429 dpkgQuery = ["dpkg-query", "--search", f ]
430 if verbose:
431 print "[DEBUG] Running:%s" % dpkgQuery
423432 dpkgProc = subprocess.Popen(dpkgQuery, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
424433 env = lc_all_c_env, close_fds=True)
425434 dpkgProc.wait()
426435 if verbose:
427 print "Running:%s" % dpkgQuery
436 print "[DEBUG] Running:%s" % dpkgQuery
428437 for line in dpkgProc.stdout.readlines():
429438 line = line.strip()
430439 if line.find('no path found matching pattern ' + f) > 0:
436445 break
437446
438447 if file_in_package and verbose:
439 print "YES: File belongs to package %s" % package
448 print "[DEBUG] YES: File belongs to package %s" % package
440449 if not file_in_package and verbose:
441 print "NO: File does not belongs to any package"
450 print "[DEBUG] NO: File does not belongs to any package"
442451 return file_in_package
443452
444453 # Tells if a file has to be considered a deleted file