Skip to content

Commit

Permalink
Check return values from GRD calls
Browse files Browse the repository at this point in the history
Start checking return codes of the GRD calls.
  • Loading branch information
jkonecny12 authored and KKoukiou committed Oct 10, 2024
1 parent 0efddea commit ccb2531
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
11 changes: 8 additions & 3 deletions pyanaconda/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,9 @@ def _run_program(argv, root='/', stdin=None, stdout=None, env_prune=None,
return (proc.returncode, output_string)


def execWithRedirect(command, argv, stdin=None, stdout=None, root='/', env_prune=None,
log_output=True, binary_output=False, do_preexec=True):
def execWithRedirect(command, argv, stdin=None, stdout=None, root='/',
env_prune=None, env_add=None, log_output=True, binary_output=False,
do_preexec=True):
""" Run an external program and redirect the output to a file.
:param command: The command to run
Expand All @@ -248,14 +249,16 @@ def execWithRedirect(command, argv, stdin=None, stdout=None, root='/', env_prune
:param stdout: Optional file object to redirect stdout and stderr to.
:param root: The directory to chroot to before running command.
:param env_prune: environment variable to remove before execution
:param env_add: environment variables added for the execution
:param log_output: whether to log the output of command
:param binary_output: whether to treat the output of command as binary data
:param do_preexec: whether to use a preexec_fn for subprocess.Popen
:return: The return code of the command
"""
argv = [command] + argv
return _run_program(argv, stdin=stdin, stdout=stdout, root=root, env_prune=env_prune,
log_output=log_output, binary_output=binary_output, do_preexec=do_preexec)[0]
env_add=env_add, log_output=log_output, binary_output=binary_output,
do_preexec=do_preexec)[0]


def execWithCapture(command, argv, stdin=None, root='/', env_prune=None, env_add=None,
Expand All @@ -266,6 +269,8 @@ def execWithCapture(command, argv, stdin=None, root='/', env_prune=None, env_add
:param argv: The argument list
:param stdin: The file object to read stdin from.
:param root: The directory to chroot to before running command.
:param env_prune: environment variable to remove before execution
:param env_add: environment variables added for the execution
:param log_output: Whether to log the output of command
:param filter_stderr: Whether stderr should be excluded from the returned output
:param do_preexec: whether to use the preexec function
Expand Down
23 changes: 13 additions & 10 deletions pyanaconda/gnome_remote_desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pyanaconda.core import util
from pyanaconda.core.constants import THREAD_RDP_OBTAIN_HOSTNAME
from pyanaconda.core.threads import thread_manager
from pyanaconda.core.util import execWithCapture, startProgram
from pyanaconda.core.util import execWithRedirect, startProgram

from pyanaconda.core.i18n import _

Expand Down Expand Up @@ -111,14 +111,16 @@ def _handle_rdp_certificates(self):
# then create folder for the certs
os.makedirs(GRD_RDP_CERT_DIR)
# generate the certs
execWithCapture(OPENSSL_BINARY_PATH,
["req", "-new",
"-newkey", "rsa:4096",
"-days", "720", "-nodes", "-x509",
"-subj", "/C=DE/ST=NONE/L=NONE/O=GNOME/CN=localhost",
"-out", GRD_RDP_CERT,
"-keyout", GRD_RDP_CERT_KEY]
)
ret = execWithRedirect(OPENSSL_BINARY_PATH,
["req", "-new",
"-newkey", "rsa:4096",
"-days", "720", "-nodes", "-x509",
"-subj", "/C=DE/ST=NONE/L=NONE/O=GNOME/CN=localhost",
"-out", GRD_RDP_CERT,
"-keyout", GRD_RDP_CERT_KEY]
)
if ret != 0:
self._fail_with_error("Can't generate certificates for Gnome remote desktop. Aborting.")
# tell GNOME remote desktop to use these certificates
self._run_grdctl(["rdp", "set-tls-cert", GRD_RDP_CERT])
self._run_grdctl(["rdp", "set-tls-key", GRD_RDP_CERT_KEY])
Expand Down Expand Up @@ -189,7 +191,8 @@ def _run_grdctl(self, argv):
# extend the base argv by the caller provided arguments
combined_argv = base_argv + argv
# make sure HOME is set to /root or else settings might not be saved
execWithCapture("grdctl", combined_argv, env_add={"HOME": "/root"})
if execWithRedirect("grdctl", combined_argv, env_add={"HOME": "/root"}) != 0:
self._fail_with_error("Gnome remote desktop invocation failed!")

def _start_grd_process(self):
"""Start the GNOME remote desktop process."""
Expand Down

0 comments on commit ccb2531

Please sign in to comment.