killdaemons: prevent killing all user processes by bad pid file
authorYuya Nishihara <yuya@tcha.org>
Thu, 18 Aug 2016 18:43:48 +0900
changeset 29811 4ddfb730789d
parent 29810 ceff91dea404
child 29812 01f036f0e40b
killdaemons: prevent killing all user processes by bad pid file When I was fixing the test-gpg issue, I noticed gpg-connect-agent could print "-1" as a server pid if command was wrong. I'm not pretty sure but nobody would want to kill their running applications by mistake.
tests/killdaemons.py
--- a/tests/killdaemons.py	Wed Aug 17 20:56:12 2016 +0900
+++ b/tests/killdaemons.py	Thu Aug 18 18:43:48 2016 +0900
@@ -82,7 +82,11 @@
         for line in fp:
             try:
                 pid = int(line)
+                if pid <= 0:
+                    raise ValueError
             except ValueError:
+                logfn('# Not killing daemon process %s - invalid pid'
+                      % line.rstrip())
                 continue
             kill(pid, logfn, tryhard)
         fp.close()