[PATCH] killdaemons: prevent killing all user processes by bad pid file

Yuya Nishihara yuya at tcha.org
Thu Aug 18 10:07:53 UTC 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1471513428 -32400
#      Thu Aug 18 18:43:48 2016 +0900
# Node ID 1650ada9f2a157ef12c5177ae360eb6398244d02
# Parent  8d226db31f20b8c4a2c119e10be7533948f0bad6
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.

diff --git a/tests/killdaemons.py b/tests/killdaemons.py
--- a/tests/killdaemons.py
+++ b/tests/killdaemons.py
@@ -82,7 +82,11 @@ def killdaemons(pidfile, tryhard=True, r
         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()


More information about the Mercurial-devel mailing list