changeset 29822:4ddfb730789d

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.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 18 Aug 2016 18:43:48 +0900
parents ceff91dea404
children 01f036f0e40b
files tests/killdaemons.py
diffstat 1 files changed, 4 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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()