Skip to content

Commit e5ae4d3

Browse files
committed
* BUG: Correctly check if program is an absolute path * FEATURE: If program is not an absolute. Include the program config directory in search path.
1 parent b3c5c9d commit e5ae4d3

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

supervisor/process.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,18 @@ def get_execv_args(self):
115115
else:
116116
raise BadCommand("command is empty")
117117

118-
if "/" in program:
118+
if os.path.isabs(program):
119119
filename = program
120120
try:
121121
st = self.config.options.stat(filename)
122122
except OSError:
123123
st = None
124-
125124
else:
126125
path = self.config.options.get_path()
126+
# Search the root config directory of this program if it's set and is absolute.
127+
if self.config.directory is not None and os.path.isabs(self.config.directory):
128+
path.insert(0, self.config.directory)
129+
127130
found = None
128131
st = None
129132
for dir in path:

supervisor/tests/test_process.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,49 @@ def test_get_execv_args_rel(self):
167167
self.assertEqual(args[0], '/bin/sh')
168168
self.assertEqual(args[1], ['sh', 'foo'])
169169

170+
def test_get_execv_args_rel_in_program_dir(self):
171+
executable = 'sh foo'
172+
directory = "/my/program/dir/"
173+
program = os.path.join(directory, 'sh')
174+
options = DummyOptions()
175+
config = DummyPConfig(options, 'sh', executable, directory)
176+
instance = self._makeOne(config)
177+
def stat(filename):
178+
if filename == program:
179+
return True
180+
else:
181+
raise OSError
182+
183+
config.options.stat = Mock(config.options.stat, side_effect=stat)
184+
args = instance.get_execv_args()
185+
self.assertEqual(len(args), 2)
186+
self.assertEqual(args[0], program)
187+
self.assertEqual(args[1], ['sh', 'foo'])
188+
189+
def test_get_execv_args_rel_in_path(self):
190+
executable = 'test_program foo'
191+
directory = "/my/program/dir/"
192+
program = os.path.join(directory, 'test_program')
193+
options = DummyOptions()
194+
config = DummyPConfig(options, 'test_program', executable)
195+
instance = self._makeOne(config)
196+
def stat(filename):
197+
if filename == program:
198+
return True
199+
else:
200+
raise OSError
201+
202+
def get_path():
203+
return ["/usr/bin", directory]
204+
205+
config.options.stat = Mock(config.options.stat, side_effect=stat)
206+
config.options.get_path = Mock(config.options.get_path, side_effect=get_path)
207+
208+
args = instance.get_execv_args()
209+
self.assertEqual(len(args), 2)
210+
self.assertEqual(args[0], program)
211+
self.assertEqual(args[1], ['test_program', 'foo'])
212+
170213
def test_record_spawnerr(self):
171214
options = DummyOptions()
172215
config = DummyPConfig(options, 'test', '/test')

0 commit comments

Comments
 (0)