mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-18 17:00:24 +00:00
Merge pull request #440 from lpirl/empty-pidfile
fix crash when stopping/restarting with an invalid pidfile
This commit is contained in:
commit
5483c86d2b
@ -185,7 +185,16 @@ def stop(config):
|
||||
return 2
|
||||
with open(pidfile, "r") as f:
|
||||
pid = f.read()
|
||||
pid = int(pid)
|
||||
|
||||
try:
|
||||
pid = int(pid)
|
||||
except ValueError:
|
||||
# The error message below mimics a Twisted error message, which is
|
||||
# displayed when starting a node with an invalid pidfile.
|
||||
print >>err, "Pidfile %s contains non-numeric value" % pidfile
|
||||
# we define rc=2 to mean "nothing is running, but it wasn't me who
|
||||
# stopped it"
|
||||
return 2
|
||||
|
||||
# kill it hard (SIGKILL), delete the twistd.pid file, then wait for the
|
||||
# process itself to go away. If it hasn't gone away after 20 seconds, warn
|
||||
|
@ -7,6 +7,7 @@ import re
|
||||
from twisted.trial import unittest
|
||||
from twisted.python.monkey import MonkeyPatcher
|
||||
from twisted.internet import task
|
||||
from twisted.python.filepath import FilePath
|
||||
|
||||
import allmydata
|
||||
from allmydata.util import fileutil, hashutil, base32, keyutil
|
||||
@ -1289,3 +1290,24 @@ class Options(ReallyEqualMixin, unittest.TestCase):
|
||||
["--node-directory=there", "start", "--nodaemon"])
|
||||
self.failUnlessRaises(usage.UsageError, self.parse,
|
||||
["start", "--basedir=here", "--nodaemon"])
|
||||
|
||||
|
||||
class Stop(unittest.TestCase):
|
||||
def test_non_numeric_pid(self):
|
||||
"""
|
||||
If the pidfile exists but does not contain a numeric value, a complaint to
|
||||
this effect is written to stderr and the non-success result is
|
||||
returned.
|
||||
"""
|
||||
basedir = FilePath(self.mktemp().decode("ascii"))
|
||||
basedir.makedirs()
|
||||
basedir.child(u"twistd.pid").setContent(b"foo")
|
||||
|
||||
config = startstop_node.StopOptions()
|
||||
config.stdout = StringIO()
|
||||
config.stderr = StringIO()
|
||||
config['basedir'] = basedir.path
|
||||
|
||||
result_code = startstop_node.stop(config)
|
||||
self.assertEqual(2, result_code)
|
||||
self.assertIn("contains non-numeric value", config.stderr.getvalue())
|
||||
|
Loading…
x
Reference in New Issue
Block a user