Skip to content
Snippets Groups Projects
Commit 01a7cff3 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Handle imported commands that aren't in the PATH

This fixes cases where a normal user tries to execute the program and
the program raises pbs.CommandNotFound exceptions because it tries to
import a command from sbin, which is not in the path.
parent 36e348b6
No related branches found
No related tags found
No related merge requests found
...@@ -9,8 +9,7 @@ import re ...@@ -9,8 +9,7 @@ import re
import sys import sys
import guestfs import guestfs
from pbs import dmsetup import pbs
from pbs import blockdev
from pbs import dd from pbs import dd
...@@ -18,6 +17,26 @@ class DiskError(Exception): ...@@ -18,6 +17,26 @@ class DiskError(Exception):
pass pass
def find_sbin_command(command, exception):
search_paths = ['/usr/local/sbin', '/usr/sbin', '/sbin']
for fullpath in map(lambda x: "%s/%s" % (x, command), search_paths):
if os.path.exists(fullpath) and os.access(fullpath, os.X_OK):
return pbs.Command(fullpath)
continue
raise exception
try:
from pbs import dmsetup
except pbs.CommandNotFound as e:
dmsetup = find_sbin_command('dmsetup', e)
try:
from pbs import blockdev
except pbs.CommandNotFound as e:
blockdev = find_sbin_command('blockdev', e)
class Disk(object): class Disk(object):
"""This class represents a hard disk hosting an Operating System """This class represents a hard disk hosting an Operating System
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment