Skip to content

Commit

Permalink
Merge pull request #227 from arighi/show-kernel-panic
Browse files Browse the repository at this point in the history
virtme: always print kernel panic / oops in interactive mode
  • Loading branch information
arighi authored Jan 30, 2025
2 parents 6de21c4 + 19c7f39 commit 1ebb7fb
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions virtme/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,25 +1282,28 @@ def do_it() -> int:
if args.graphics is None and not args.script_sh and not args.script_exec:
qemuargs.extend(["-echr", "1"])

if args.verbose:
# Check if we have permission to access the current stderr.
if not can_access_file("/proc/self/fd/2"):
print(
"ERROR: not a valid pts, try to run vng inside tmux or screen",
file=sys.stderr,
)
sys.exit(1)

# Redirect kernel messages to stderr, creating a separate console
# Redirect kernel errors to stderr, creating a separate console.
#
# If we don't have access to stderr via procfs (for example when
# running inside a container), print a warning and implicitly
# suppress the kernel errors redirection.
if can_access_file("/proc/self/fd/2"):
qemuargs.extend(["-chardev", "file,path=/proc/self/fd/2,id=dmesg"])
qemuargs.extend(["-device", arch.virtio_dev_type("serial")])
qemuargs.extend(["-device", "virtconsole,chardev=dmesg"])
kernelargs.extend(["console=hvc0"])
else:
print(
"WARNING: unable to write kernel messages, try to run vng with a valid PTS "
"(e.g., inside tmux or screen)",
file=sys.stderr,
)

# Unfortunately we can't use hvc0 to redirect early console
# messages to stderr, so just send them to the main console, in
# this way we don't lose early printk's in verbose mode and we can
# catch potential boot issues.
# Unfortunately we can't use hvc0 to redirect early console
# messages to stderr, so just send them to the main console, in
# this way we don't lose early printk's in verbose mode and we can
# catch potential boot issues.
if args.verbose:
kernelargs.extend(arch.earlyconsole_args())

qemuargs.extend(["-chardev", "stdio,id=console,signal=off,mux=on"])
Expand Down Expand Up @@ -1407,7 +1410,8 @@ def do_script(shellcmd: str, ret_path=None, show_boot_console=False) -> None:
not can_access_file("/proc/self/fd/1") or \
not can_access_file("/proc/self/fd/2"):
print(
"ERROR: not a valid pts, try to run vng inside tmux or screen",
"ERROR: not a valid pts, try to run vng with a valid PTS "
"(e.g., inside tmux or screen)",
file=sys.stderr,
)
sys.exit(1)
Expand Down Expand Up @@ -1671,11 +1675,11 @@ def get_net_mac(index):
)
initrdpath = None

if not args.verbose:
kernelargs.append("quiet")
kernelargs.append("loglevel=0")
else:
if args.verbose:
kernelargs.append("debug")
else:
kernelargs.append("quiet")
kernelargs.append("loglevel=1")

# Now that we're done setting up kernelargs, append user-specified args
# and then initargs
Expand Down

0 comments on commit 1ebb7fb

Please sign in to comment.