Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtme: always print kernel panic / oops in interactive mode #227

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to be sure: can we still write to stderr here if we cannot access /proc/self/fd/2?

Also, compared to before, this warning will always be printed in such environment, when stderr is not accessible. I guess it will not be an issue, right?

)

# 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