Skip to content

Commit

Permalink
Use a threading lock to control program log output.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwlehman committed Jan 18, 2013
1 parent e842107 commit 1ba3eda
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
3 changes: 3 additions & 0 deletions blivet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def enable_installer_mode():
from pyanaconda.bootloader import get_bootloader
from pyanaconda.bootloader import BootLoaderError

from pyanaconda.anaconda_log import program_log_lock
util.program_log_lock = program_log_lock

flags.installer_mode = True

DEVICE_TYPE_LVM = 0
Expand Down
46 changes: 26 additions & 20 deletions blivet/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
log = logging.getLogger("storage")
program_log = logging.getLogger("program")

from threading import Lock
# this will get set to anaconda's program_log_lock in enable_installer_mode
program_log_lock = Lock()

def _run_program(argv, root='/', stdin=None, env_prune=None):
if env_prune is None:
env_prune = []
Expand All @@ -16,31 +20,33 @@ def chroot():
if root and root != '/':
os.chroot(root)

program_log.info("Running... %s" % argv)
with program_log_lock:
program_log.info("Running... %s" % " ".join(argv))

env = os.environ.copy()
env.update({"LC_ALL": "C",
"INSTALL_PATH": root})
for var in env_prune:
env.pop(var, None)
env = os.environ.copy()
env.update({"LC_ALL": "C",
"INSTALL_PATH": root})
for var in env_prune:
env.pop(var, None)

try:
proc = subprocess.Popen(argv,
stdin=stdin,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
preexec_fn=chroot, cwd=root, env=env)
try:
proc = subprocess.Popen(argv,
stdin=stdin,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
preexec_fn=chroot, cwd=root, env=env)

out = proc.communicate()[0]
if out:
for line in out.splitlines():
program_log.info(line)
out = proc.communicate()[0]
if out:
for line in out.splitlines():
program_log.info(line)

except OSError as e:
program_log.error("Error running %s: %s" % (argv[0], e.strerror))
raise
except OSError as e:
program_log.error("Error running %s: %s" % (argv[0], e.strerror))
raise

program_log.debug("Return code: %d" % proc.returncode)

program_log.debug("Return code: %d" % proc.returncode)
return (proc.returncode, out)

def run_program(*args, **kwargs):
Expand Down

0 comments on commit 1ba3eda

Please sign in to comment.