From 59b0812adfff4af7993ffbb159542f66b1538d58 Mon Sep 17 00:00:00 2001 From: Mai MISHIRO <33324303+mai346@users.noreply.github.com> Date: Wed, 8 Nov 2017 17:16:59 +0900 Subject: [PATCH] Fix: "Reboot Required" detection process in scan/redhat.go (#534) --- scan/redhat.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scan/redhat.go b/scan/redhat.go index 75dfefc9..99a996a7 100644 --- a/scan/redhat.go +++ b/scan/redhat.go @@ -260,11 +260,13 @@ func (o *redhat) scanPackages() error { } func (o *redhat) rebootRequired() (bool, error) { - r := o.exec("rpm -q --last kernel | head -n1", noSudo) - if !r.isSuccess() { - return false, fmt.Errorf("Failed to detect the last installed kernel : %v", r) + r := o.exec("rpm -q --last kernel", noSudo) + scanner := bufio.NewScanner(strings.NewReader(r.Stdout)) + if !r.isSuccess() || !scanner.Scan() { + o.log.Warn("Failed to detect the last installed kernel : %v", r) + return false, nil } - lastInstalledKernelVer := strings.Fields(r.Stdout)[0] + lastInstalledKernelVer := strings.Fields(scanner.Text())[0] running := fmt.Sprintf("kernel-%s", o.Kernel.Release) return running != lastInstalledKernelVer, nil }