Skip to content

Commit

Permalink
Merge pull request mendersoftware#914 from kacf/MEN-5340
Browse files Browse the repository at this point in the history
MEN-5340: Fix incorrect logic if `reboot` is killed before the client.
  • Loading branch information
Kristian Amlie authored Jan 10, 2022
2 parents eda2cde + d664c60 commit 6a1168a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
26 changes: 17 additions & 9 deletions patches/0001-Instrument-Mender-client-for-coverage-analysis.patch
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
From 10eeda6a93a13b3a96c7fc2a6e4f6b4eb4690458 Mon Sep 17 00:00:00 2001
From 4b5cf8ce62086b028811617080af6689507b0334 Mon Sep 17 00:00:00 2001
From: Lluis Campos <[email protected]>
Date: Tue, 30 Nov 2021 19:40:35 +0100
Subject: [PATCH] Instrument mender binary
Subject: [PATCH 1/1] Instrument mender binary

Changelog: None

Signed-off-by: Lluis Campos <[email protected]>
---
main.go | 39 ++++++++++++++++++++++++++++++++++++++-
system/system.go | 13 +------------
2 files changed, 39 insertions(+), 13 deletions(-)
system/system.go | 21 +--------------------
2 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/main.go b/main.go
index 23a6f614..1195d3ab 100644
index 23a6f61..1195d3a 100644
--- a/main.go
+++ b/main.go
@@ -18,6 +18,8 @@ import (
Expand Down Expand Up @@ -74,7 +74,7 @@ index 23a6f614..1195d3ab 100644
+
}
diff --git a/system/system.go b/system/system.go
index 969275ee..c4bb61c1 100644
index cc67a01..c4bb61c 100644
--- a/system/system.go
+++ b/system/system.go
@@ -19,9 +19,7 @@ import (
Expand All @@ -87,24 +87,32 @@ index 969275ee..c4bb61c1 100644
log "github.com/sirupsen/logrus"
)

@@ -36,16 +34,7 @@ func NewSystemRebootCmd(command Commander) *SystemRebootCmd {
@@ -36,24 +34,7 @@ func NewSystemRebootCmd(command Commander) *SystemRebootCmd {
}

func (s *SystemRebootCmd) Reboot() error {
- err := s.command.Command("reboot").Run()
-
- // *Any* return from this function is an error.
-
- if err != nil {
- // MEN-5340: If there's an error, it may be because systemd is
- // in the process of shutting down our service, and happens to
- // kill `reboot` first. Give it a few seconds to follow up with
- // killing the client.
- time.Sleep(10 * time.Second)
- return err
- }
-
- // Wait up to ten minutes for reboot to kill the client, otherwise the
- // client may mistake a successful return code as "reboot is complete,
- // continue". *Any* return from this function is an error.
- // continue".
- time.Sleep(10 * time.Minute)
- return errors.New("System did not reboot, even though 'reboot' call succeeded.")
+ panic("Client needs reboot!")
}

type Commander interface {
--
2.30.2
2.17.1

12 changes: 10 additions & 2 deletions system/system.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Northern.tech AS
// Copyright 2022 Northern.tech AS
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,13 +37,21 @@ func NewSystemRebootCmd(command Commander) *SystemRebootCmd {

func (s *SystemRebootCmd) Reboot() error {
err := s.command.Command("reboot").Run()

// *Any* return from this function is an error.

if err != nil {
// MEN-5340: If there's an error, it may be because systemd is
// in the process of shutting down our service, and happens to
// kill `reboot` first. Give it a few seconds to follow up with
// killing the client.
time.Sleep(10 * time.Second)
return err
}

// Wait up to ten minutes for reboot to kill the client, otherwise the
// client may mistake a successful return code as "reboot is complete,
// continue". *Any* return from this function is an error.
// continue".
time.Sleep(10 * time.Minute)
return errors.New("System did not reboot, even though 'reboot' call succeeded.")
}
Expand Down

0 comments on commit 6a1168a

Please sign in to comment.