From 0eb10d6f2f38c2c4bc7c82061a9d50f4d916c428 Mon Sep 17 00:00:00 2001 From: Gyuho Lee <6799218+gyuho@users.noreply.github.com> Date: Mon, 2 Sep 2024 11:39:59 +0900 Subject: [PATCH] fix(dmesg): fallback in case "dmesg --since" flag doesn't exist in older versions (#45) * fix(dmesg): fallback in case dmesg --since flag doesn't exist Signed-off-by: Gyuho Lee * try Signed-off-by: Gyuho Lee * Revert "try" This reverts commit a23f9ca3c2f5ba9222d15eaa07d5bb3ccc988bf3. --------- Signed-off-by: Gyuho Lee --- components/dmesg/config.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/dmesg/config.go b/components/dmesg/config.go index f9920fc1..5c4a7c58 100644 --- a/components/dmesg/config.go +++ b/components/dmesg/config.go @@ -50,11 +50,16 @@ const DefaultDmesgFile = "/var/log/dmesg" func DefaultConfig() Config { scanCommands := [][]string{ {"cat", DefaultDmesgFile}, - {"dmesg", "--ctime", "--nopager", "--buffer-size", "163920", "--since", "'1 hour ago'"}, + + // some old dmesg versions don't support --since, thus fall back to the one without --since and tail the last 200 lines + // ref. https://github.com/leptonai/gpud/issues/32 + {"dmesg --ctime --nopager --buffer-size 163920 --since '1 hour ago' || dmesg --ctime --nopager --buffer-size 163920 | tail -n 200"}, } if _, err := os.Stat(DefaultDmesgFile); os.IsNotExist(err) { scanCommands = [][]string{ - {"dmesg", "--ctime", "--nopager", "--buffer-size", "163920", "--since", "'1 hour ago'"}, + // some old dmesg versions don't support --since, thus fall back to the one without --since and tail the last 200 lines + // ref. https://github.com/leptonai/gpud/issues/32 + {"dmesg --ctime --nopager --buffer-size 163920 --since '1 hour ago' || dmesg --ctime --nopager --buffer-size 163920 | tail -n 200"}, } }