Skip to content

Commit eabc2c5

Browse files
committed
Restore original pidproxy arg parsing behavior. References Supervisor#1418
Issue Supervisor#1418 reported that pidproxy did not parse arguments correctly. A fix was suggested that was committed in ab26970. After actually running pidproxy to verify that fix, I found that pidproxy no longer worked. The original code in pidproxy was correct. This change partially reverts ab26970, restoring the original pidproxy behavior but leaving the unit tests. Two new end-to-end tests for pidproxy were added: one to verify a command without any arguments, and one with.
1 parent ab26970 commit eabc2c5

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

CHANGES.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
4.3.0.dev0 (Next Release)
22
-------------------------
33

4-
- Fixed a bug where ``pidproxy`` would not pass arguments to the command
5-
it runs.
6-
74
4.2.2 (2021-02-26)
85
------------------
96

supervisor/pidproxy.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ class PidProxy:
1919

2020
def __init__(self, args):
2121
try:
22-
self.pidfile = args[1]
23-
command_and_cmdargs = args[2:]
24-
self.command = os.path.abspath(command_and_cmdargs[0])
25-
self.cmdargs = command_and_cmdargs[1:]
22+
self.pidfile, cmdargs = args[1], args[2:]
23+
self.abscmd = os.path.abspath(cmdargs[0])
24+
self.cmdargs = cmdargs
2625
except (ValueError, IndexError):
2726
self.usage()
2827
sys.exit(1)
2928

3029
def go(self):
3130
self.setsignals()
32-
self.pid = os.spawnv(os.P_NOWAIT, self.command, self.cmdargs)
31+
self.pid = os.spawnv(os.P_NOWAIT, self.abscmd, self.cmdargs)
3332
while 1:
3433
time.sleep(5)
3534
try:

supervisor/tests/test_end_to_end.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,20 @@ def test_issue_1298(self):
279279
self.addCleanup(bash.kill, signal.SIGINT)
280280
bash.expect('spewage 2', timeout=30)
281281

282+
def test_issue_1481_pidproxy_cmd_with_no_args(self):
283+
args = ['-m', 'supervisor.pidproxy', 'nonexistent-pidfile', "/bin/echo"]
284+
pidproxy = pexpect.spawn(sys.executable, args, encoding='utf-8')
285+
self.addCleanup(pidproxy.kill, signal.SIGINT)
286+
pidproxy.expect(pexpect.EOF)
287+
self.assertEqual(pidproxy.before.strip(), "")
288+
289+
def test_issue_1481_pidproxy_cmd_with_args(self):
290+
args = ['-m', 'supervisor.pidproxy', 'nonexistent-pidfile', "/bin/echo", "1", "2"]
291+
pidproxy = pexpect.spawn(sys.executable, args, encoding='utf-8')
292+
self.addCleanup(pidproxy.kill, signal.SIGINT)
293+
pidproxy.expect(pexpect.EOF)
294+
self.assertEqual(pidproxy.before.strip(), "1 2")
295+
282296
def test_suite():
283297
return unittest.findTestCases(sys.modules[__name__])
284298

supervisor/tests/test_pidproxy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ def test_ctor_parses_args(self):
1313
args = ["pidproxy.py", "/path/to/pidfile", "./cmd", "-arg1", "-arg2"]
1414
pp = self._makeOne(args)
1515
self.assertEqual(pp.pidfile, "/path/to/pidfile")
16-
self.assertEqual(pp.command, os.path.abspath("./cmd"))
17-
self.assertEqual(pp.cmdargs, ["-arg1", "-arg2"])
16+
self.assertEqual(pp.abscmd, os.path.abspath("./cmd"))
17+
self.assertEqual(pp.cmdargs, ["./cmd", "-arg1", "-arg2"])

0 commit comments

Comments
 (0)