Skip to content

Commit

Permalink
Merge pull request #5842 from M4rtinK/rhel-10-redirect_EVERYTHING
Browse files Browse the repository at this point in the history
Redirect everything that was spamming TTY1 to Journal
  • Loading branch information
M4rtinK authored Aug 21, 2024
2 parents 83c6d10 + 487a26b commit d196ffb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
10 changes: 10 additions & 0 deletions anaconda.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
import signal
import pid

# Redirect Anaconda main process stderr to Journal,
# as otherwise this could end up writing all over
# the TUI on TTY1.

# create an appropriately named Journal writing stream
from systemd import journal
anaconda_stderr_stream = journal.stream("anaconda", priority=journal.LOG_ERR)
# redirect stderr of this process to the stream
os.dup2(anaconda_stderr_stream.fileno(), sys.stderr.fileno())


def exitHandler(rebootData):
# Clear the list of watched PIDs.
Expand Down
11 changes: 10 additions & 1 deletion pyanaconda/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
from simpleline import App
from simpleline.render.screen_handler import ScreenHandler

from systemd import journal

from pyanaconda.anaconda_loggers import get_module_logger, get_stdout_logger
log = get_module_logger(__name__)
stdout_log = get_stdout_logger()
Expand Down Expand Up @@ -249,8 +251,15 @@ def wl_preexec():
if headless:
argv.extend(["--headless"])

# redirect stdout and stderr from GNOME Kiosk to journal
gnome_kiosk_stdout_stream = journal.stream("gnome-kiosk", priority=journal.LOG_INFO)
gnome_kiosk_stderr_stream = journal.stream("gnome-kiosk", priority=journal.LOG_ERR)

childproc = util.startProgram(argv, env_add={'XDG_DATA_DIRS': xdg_data_dirs},
preexec_fn=wl_preexec)
preexec_fn=wl_preexec,
stdout=gnome_kiosk_stdout_stream,
stderr=gnome_kiosk_stderr_stream,
)
WatchProcesses.watch_process(childproc, argv[0])

for _i in range(0, int(timeout / 0.1)):
Expand Down
18 changes: 6 additions & 12 deletions pyanaconda/gnome_remote_destop.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from pyanaconda.core import util
from pyanaconda.core.util import execWithCapture, startProgram
import socket
from systemd import journal

from pyanaconda.core.i18n import _

Expand Down Expand Up @@ -149,7 +150,6 @@ def _find_network_address(self):

try:
hinfo = socket.gethostbyaddr(self.ip)
self.log.info(hinfo)
if len(hinfo) == 3:
# Consider as coming from a valid DNS record only if single IP is returned
if len(hinfo[2]) == 1:
Expand All @@ -170,23 +170,17 @@ def _run_grdctl(self, argv):
# make sure HOME is set to /root or else settings might not be saved
execWithCapture("grdctl", combined_argv, env_add={"HOME": "/root"})

def _open_grd_log_file(self):
# FIXME: redirect to journal ?
try:
fd = os.open(GRD_LOG_FILE, os.O_RDWR | os.O_CREAT)
except OSError as e:
sys.stderr.write("error opening %s: %s\n", (GRD_LOG_FILE, e))
fd = None

return fd

def _start_grd_process(self):
"""Start the GNOME remote desktop process."""
try:
self.log.info("Starting GNOME remote desktop.")
global grd_process
# forward GRD stdout & stderr to Journal
grd_stdout_stream = journal.stream("gnome-remote-desktop", priority=journal.LOG_INFO)
grd_stderr_stream = journal.stream("gnome-remote-desktop", priority=journal.LOG_ERR)
grd_process = startProgram([GRD_BINARY_PATH, "--headless"],
stdout=self._open_grd_log_file(),
stdout=grd_stdout_stream,
stderr=grd_stderr_stream,
env_add={"HOME": "/root"})
self.log.info("GNOME remote desktop is now running.")
except OSError:
Expand Down
8 changes: 6 additions & 2 deletions scripts/run-in-new-session
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import signal
import struct
import subprocess
import sys
from systemd import journal

VT_GETSTATE = 0x5603
VT_ACTIVATE = 0x5606
Expand Down Expand Up @@ -118,9 +119,12 @@ def run_program_in_new_session(arguments, pam_environment, user, service,
print(f"Could not wait for VT {vt} to change: {e}", file=old_tty_output)

try:
# redirect output (both stodout & stderr) from the command to Journal
new_session_stdout_stream = journal.stream("run-in-new-session", priority=journal.LOG_INFO)
new_session_stderr_stream = journal.stream("run-in-new-session", priority=journal.LOG_ERR)
os.dup2(tty_input.fileno(), 0)
os.dup2(tty_output.fileno(), 1)
os.dup2(tty_output.fileno(), 2)
os.dup2(new_session_stdout_stream.fileno(), 1)
os.dup2(new_session_stderr_stream.fileno(), 2)
except OSError as e:
print(f"Could not set up standard i/o: {e}", file=old_tty_output)

Expand Down

0 comments on commit d196ffb

Please sign in to comment.