Skip to content

Commit 267db6d

Browse files
committed
dmesg: don't decode, just write out bytes
Signed-off-by: Stephen Brennan <[email protected]>
1 parent 338c474 commit 267db6d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drgn_tools/printk.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import argparse
77
import os
88
import subprocess
9+
import sys
910
from typing import Optional
1011

1112
from drgn import Program
@@ -42,4 +43,8 @@ class DmesgModule(CorelensModule):
4243
name = "dmesg"
4344

4445
def run(self, prog: Program, args: argparse.Namespace) -> None:
45-
print(get_dmesg(prog).decode("utf-8"))
46+
# Avoid the overhead of decoding and then re-encoding the bytes: just
47+
# write the bytes directly to stdout. Also, avoid any encoding errors.
48+
# There's no guaranteed encoding for the kernel log anyway.
49+
sys.stdout.buffer.write(get_dmesg(prog))
50+
print()

0 commit comments

Comments
 (0)