Package: debian-goodies Version: 0.59 Severity: wishlist Tags: patch It would be useful if checkrestart had the ability to add more blacklist patterns. The attached patch adds a -b parameter which does this.
-- Tollef Fog Heen UNIX is user friendly, it's just picky about who its friends are
diff -Nur debian-goodies-0.59/checkrestart ../debian-goodies-0.59/checkrestart --- debian-goodies-0.59/checkrestart 2011-10-25 00:17:42.000000000 +0200 +++ ../debian-goodies-0.59/checkrestart 2011-11-18 12:49:41.030287448 +0100 @@ -68,11 +68,12 @@ lc_all_c_env = os.environ lc_all_c_env['LC_ALL'] = 'C' - + blacklistFiles = [] + blacklist = [] # Process options try: - opts, args = getopt.getopt(sys.argv[1:], "hvpa", ["help", "verbose", "packages", "all"]) + opts, args = getopt.getopt(sys.argv[1:], "hvpab:", ["help", "verbose", "packages", "all", "blacklist"]) except getopt.GetoptError, err: # print help information and exit: print str(err) # will print something like "option -x not recognized" @@ -98,9 +99,18 @@ elif o in ("-a", "--all"): allFiles = True onlyPackageFiles = False + elif o in ("-b", "--blacklist"): + blacklistFiles.append(a) + onlyPackageFiles = False else: assert False, "unhandled option" + for f in blacklistFiles: + for line in file(f, "r"): + if line.startswith("#"): + continue + blacklist.append(re.compile(line.strip())) + # Start checking if find_cmd('lsof') == 1: @@ -114,7 +124,7 @@ # TODO - This does not work yet: # toRestart = psdelcheck() - toRestart = lsofcheck() + toRestart = lsofcheck(blacklist = blacklist) print "Found %d processes using old versions of upgraded files" % len(toRestart) @@ -226,7 +236,7 @@ for process in package.processes: print "\t%s\t%s" % (process.pid,process.program) -def lsofcheck(): +def lsofcheck(blacklist = None): processes = {} for line in os.popen('lsof +XL -F nf').readlines(): @@ -254,7 +264,7 @@ # Save the descriptor for later comparison process.descriptors.append(data) - toRestart = filter(lambda process: process.needsRestart(), + toRestart = filter(lambda process: process.needsRestart(blacklist), processes.values()) return toRestart @@ -262,12 +272,16 @@ # Returns: # - 0 (NO) for known locations of files which might be deleted # - 1 (YES) for valid deleted files we are interested in -def isdeletedFile (f): +def isdeletedFile (f, blacklist = None): global lc_all_c_env if allFiles: return 1 + if blacklist: + for p in blacklist: + if p.search(f): + return 0 # We don't care about log files if f.startswith('/var/log/'): return 0 @@ -466,9 +480,9 @@ # Returns: # - 0 if there is no need to restart the process # - 1 if the process needs to be restarted - def needsRestart(self): + def needsRestart(self, blacklist = None): for f in self.files: - if isdeletedFile(f): + if isdeletedFile(f, blacklist): return 1 for f in self.links: if f == 0: diff -Nur debian-goodies-0.59/checkrestart.1 ../debian-goodies-0.59/checkrestart.1 --- debian-goodies-0.59/checkrestart.1 2011-10-09 23:06:17.000000000 +0200 +++ ../debian-goodies-0.59/checkrestart.1 2011-11-18 13:01:28.609617122 +0100 @@ -57,6 +57,12 @@ .I -p option. +.TP +.BI -b file, --blacklist=file +Read a blacklist of regular expressions from +.I file. +Any files matching the patterns will be ignored. + .SH EXIT STATUS The program will exit with error (1) if a non-root user tries to run it. Otherwise,