Skip to content

Fix #369 relative command path #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

schemacs
Copy link

The docs say:

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.

This fixes relative path like to/programname as stated in #369 .

@schemacs schemacs changed the title Fix #369 Fix #369 relative command path Oct 27, 2014
if program.startswith('/'):
filename = program
else:
filename = os.path.join(self.config.directory, program)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the documentation says If it is relative, the supervisord’s environment $PATH will be searched for the executable., but this code assumes the program is relative to the configuration file directory, which is a very different thing. It introduces new behaviour that does not match the documentation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but '/' in program does not mean it IS NOT a relative path(or IS absolute). Only program.startswith('/') means absolute path? If so, this code doesn't not comply with the docs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but your change fixes one bug and introduces another. Where in the docs does it say that a program should be found relative to the config file dir?

It seems to me the correct way to fix the issue is to change this line:

         if "/" in program:

To this:

         if program.startswith('/'):

Or, even better:

         if os.path.isabs(program):

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't introduce another bug, for self.config.directory is the directory option in the program's config section, not the config file(supervisord.conf) dir. But isabs can be a better choice when checking absolute path.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're right, my bad. Sorry. Indeed self.config.directory is the "directory" program config option, not the directory of the config file. I withdraw my objection!
+1

@mal
Copy link

mal commented Feb 14, 2015

+1 this, but agree that it's worth using isabs over the current character check.

@olgert
Copy link

olgert commented Aug 14, 2015

Any chances to get this PR merged?

@mnaberez
Copy link
Member

#648 is an alternate version of this pull request with some tweaks.

@lukeweber
Copy link
Contributor

@mnaberez - I understand it was kind of a "duplicate" but the code was cleaned up and ready to be merged based on feedback here, and it really wasn't. I also just added two tests to ease the mind. I think merging the new one and closing this one would have been perfectly appropriate since I can't update this pull request without the original author of this pull request merging my code.

About #508:

  1. Current master checks for absolute path with "/" in program which is unideal.
  2. Thread seems to be agreement that code should be fixed with isabs() although it doesn't really matter as this is only a unix project.
  3. Patch was submitted almost a year ago and no new commits.
  4. Patch assumes that if you have a "/" in name your program it is either relative to your program directory or is absolute.

About #648:

  1. Uses isabs() for program check which was mentioned here as a desired fix and makes sense.
  2. Inserts program directory into position 0 in path search for program, which is similar to how path search works in other programs when executing a command from a directory.
  3. Now has two tests for having the program in a custom path, and for having the program in the program directory.

As you can see the code isn't really duplicate.

#508

                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:

#648

-        if "/" in 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

@mnaberez

This comment has been minimized.

@lukeweber

This comment has been minimized.

@lukeweber

This comment has been minimized.

@mnaberez

This comment has been minimized.

@mnaberez

This comment has been minimized.

@wardenlym
Copy link

a simple bugfix,a PR which not merged,i meet the shit three years after.

@maralla
Copy link

maralla commented Apr 16, 2020

Do the maintainers of this project really think this problem is meaningless?? Long time passed, nothing improved.

@medihack
Copy link

medihack commented Jul 6, 2020

Oh yes .. plz merge it. Wasted half an hour of my life ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

9 participants