// unlockIfHeld will unlock a lock, if it is held by this machine, or return an error. func unlockIfHeld(lck *lock.Lock) error { err := lck.Unlock() if err == lock.ErrNotExist { return nil } else if err == nil { fmt.Println("Unlocked existing lock for this machine") return nil } return err }
// lockAndReboot attempts to acquire the lock and reboot the machine in an // infinite loop. Returns if the reboot failed. func (r rebooter) lockAndReboot(lck *lock.Lock) { interval := initialInterval for { err := lck.Lock() if err != nil && err != lock.ErrExist { interval = expBackoff(interval) fmt.Printf("Retrying in %v. Error locking: %v\n", interval, err) time.Sleep(interval) continue } rebootAndSleep(r.lgn) return } }