From 84b5a2fad51e7f7f230f5ee7a717280912d10472 Mon Sep 17 00:00:00 2001 From: Lele Long Date: Tue, 28 Oct 2014 00:05:13 +0800 Subject: [PATCH 1/5] Fix #369 --- supervisor/process.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/supervisor/process.py b/supervisor/process.py index b01717585..72fca73fb 100644 --- a/supervisor/process.py +++ b/supervisor/process.py @@ -116,7 +116,11 @@ def get_execv_args(self): raise BadCommand("command is empty") if "/" in program: - filename = program + if program.startswith('/'): + filename = program + else: + filename = os.path.join(self.config.directory, program) + try: st = self.config.options.stat(filename) except OSError: From a42d988971543bd609ecc7ee4355e8f4f14d9b85 Mon Sep 17 00:00:00 2001 From: Luke Weber Date: Tue, 18 Aug 2015 22:24:36 -0700 Subject: [PATCH 2/5] Add config.directory to path that's searched --- supervisor/process.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/supervisor/process.py b/supervisor/process.py index d7ad37b79..fab130e31 100644 --- a/supervisor/process.py +++ b/supervisor/process.py @@ -115,19 +115,18 @@ def get_execv_args(self): else: raise BadCommand("command is empty") - if "/" in program: - if program.startswith('/'): - filename = program - else: - filename = os.path.join(self.config.directory, program) - + if os.path.isabs(program): + filename = program try: st = self.config.options.stat(filename) except OSError: st = None - else: path = self.config.options.get_path() + # Search the root config directory of this program if it's set and is absolute. + if self.config.directory is not None and os.path.isabs(self.config.directory): + path.insert(0, self.config.directory) + found = None st = None for dir in path: From ebd6fe4237434270ce0a5c98c727ffb9702ebb27 Mon Sep 17 00:00:00 2001 From: Luke Weber Date: Wed, 19 Aug 2015 10:03:10 -0700 Subject: [PATCH 3/5] Add tests for relative path and program directory search --- supervisor/tests/test_process.py | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/supervisor/tests/test_process.py b/supervisor/tests/test_process.py index 74a7123aa..f0f8ab8c2 100644 --- a/supervisor/tests/test_process.py +++ b/supervisor/tests/test_process.py @@ -167,6 +167,49 @@ def test_get_execv_args_rel(self): self.assertEqual(args[0], '/bin/sh') self.assertEqual(args[1], ['sh', 'foo']) + def test_get_execv_args_rel_in_program_dir(self): + executable = 'sh foo' + directory = "/my/program/dir/" + program = os.path.join(directory, 'sh') + options = DummyOptions() + config = DummyPConfig(options, 'sh', executable, directory) + instance = self._makeOne(config) + def stat(filename): + if filename == program: + return True + else: + raise OSError + + config.options.stat = Mock(config.options.stat, side_effect=stat) + args = instance.get_execv_args() + self.assertEqual(len(args), 2) + self.assertEqual(args[0], program) + self.assertEqual(args[1], ['sh', 'foo']) + + def test_get_execv_args_rel_in_path(self): + executable = 'test_program foo' + directory = "/my/program/dir/" + program = os.path.join(directory, 'test_program') + options = DummyOptions() + config = DummyPConfig(options, 'test_program', executable) + instance = self._makeOne(config) + def stat(filename): + if filename == program: + return True + else: + raise OSError + + def get_path(): + return ["/usr/bin", directory] + + config.options.stat = Mock(config.options.stat, side_effect=stat) + config.options.get_path = Mock(config.options.get_path, side_effect=get_path) + + args = instance.get_execv_args() + self.assertEqual(len(args), 2) + self.assertEqual(args[0], program) + self.assertEqual(args[1], ['test_program', 'foo']) + def test_record_spawnerr(self): options = DummyOptions() config = DummyPConfig(options, 'test', '/test') From 4bb39fa8f4ff42d2238791512425a0e49c19e45c Mon Sep 17 00:00:00 2001 From: Luke Weber Date: Tue, 29 Sep 2015 21:52:18 -0700 Subject: [PATCH 4/5] Update docs for relative path fixes in https://github.com/Supervisor/supervisor/issues/369 --- docs/configuration.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 7c2c82dd9..6044b1f08 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -561,9 +561,9 @@ where specified. The command that will be run when this program is started. The command can be either absolute (e.g. ``/path/to/programname``) or - relative (e.g. ``programname``). If it is relative, the - supervisord's environment ``$PATH`` will be searched for the - executable. Programs can accept arguments, e.g. ``/path/to/program + relative (e.g. ``programname``). If it is relative, the program's + directory and supervisord’s environment $PATH will be searched for + the executable. Programs can accept arguments, e.g. ``/path/to/program foo bar``. The command line can use double quotes to group arguments with spaces in them to pass to the program, e.g. ``/path/to/program/name -p "foo bar"``. Note that the value of From 5138dd46a28ad2b8e6e1c45461f005dabe94b1c7 Mon Sep 17 00:00:00 2001 From: Luke Weber Date: Wed, 30 Sep 2015 07:49:55 -0700 Subject: [PATCH 5/5] Update docs for relative path fixes in Supervisor#369 --- docs/configuration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 6044b1f08..ea8691387 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -562,7 +562,7 @@ where specified. The command that will be run when this program is started. The command can be either absolute (e.g. ``/path/to/programname``) or relative (e.g. ``programname``). If it is relative, the program's - directory and supervisord’s environment $PATH will be searched for + directory and supervisord's environment ``$PATH`` will be searched for the executable. Programs can accept arguments, e.g. ``/path/to/program foo bar``. The command line can use double quotes to group arguments with spaces in them to pass to the program,