From cd1106dcdc3ac2bc315b3853af047ea32dc49b95 Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Mon, 14 Dec 2015 00:48:01 -0500 Subject: [PATCH] fix type ctrl^C not stop updating when clair has network problem during updating vulnerability and failed to update vulnerability, it will keep updating and even if type ctrl^C can't stop the clair. This patch make clair to stop updating if type ctrl^C. Signed-off-by: Lei Jitang --- updater/updater.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/updater/updater.go b/updater/updater.go index 1a649edd..92ce6c79 100644 --- a/updater/updater.go +++ b/updater/updater.go @@ -61,6 +61,7 @@ func Run(config *config.UpdaterConfig, st *utils.Stopper) { // is no last update time stored in database (first update) or if an error // occurs. var nextUpdate time.Time + var stop bool if lastUpdate := getLastUpdate(); !lastUpdate.IsZero() { nextUpdate = lastUpdate.Add(config.Interval) } else { @@ -80,19 +81,24 @@ func Run(config *config.UpdaterConfig, st *utils.Stopper) { doneC <- true }() - for done := false; !done; { + for done := false; !done && !stop; { select { case <-doneC: done = true case <-time.After(refreshLockDuration): // Refresh the lock until the update is done. database.Lock(flagName, lockDuration, whoAmI) + case <-st.Chan(): + stop = true } } // Unlock the update. database.Unlock(flagName, whoAmI) + if stop { + break + } continue } else { lockOwner, lockExpiration, err := database.LockInfo(flagName)