From 1f62799b85b401db4df854169ac61c4204aee1e2 Mon Sep 17 00:00:00 2001 From: Mikolaj Kucharski Date: Mon, 3 May 2021 19:23:02 +0000 Subject: [PATCH 1/3] unattended-upgrade-shutdown: fix wait-for-signal I've noticed that unattended upgrade on shutdown doesn't work. After analyzing the code and some test runs, following cought my attention, from `pydoc3 apt_pkg.get_lock`: > apt_pkg.get_lock = get_lock(...) > get_lock(file: str, errors: bool) -> int > > Create an empty file of the given name and lock it. If the locking > succeeds, return the file descriptor of the lock file. Afterwards, > locking the file from another process will fail and thus cause > get_lock() to return -1 or raise an Error (if 'errors' is True). > > From Python 2.6 on, it is recommended to use the context manager > provided by apt_pkg.FileLock instead using the with-statement. Based on above, I think condition on line 342 should be reversed. Running `unattended-upgrade-shutdown --wait-for-signal` with my diff fixes the issue for me. This addresses mvo5/unattended-upgrades#295 --- unattended-upgrade-shutdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unattended-upgrade-shutdown b/unattended-upgrade-shutdown index f59e2129..8c30a535 100755 --- a/unattended-upgrade-shutdown +++ b/unattended-upgrade-shutdown @@ -339,7 +339,7 @@ class UnattendedUpgradesShutdown(): res = apt_pkg.get_lock(self.options.lock_file) logging.debug("get_lock returned %i" % res) # exit here if there is no lock - if res > 0: + if res < 0: logging.debug("lock not taken") if self.lock_was_taken: exit_log_result(self.signal_sent) From 4ff7744fea817b5583d7a579c11be9afa1d5b8d0 Mon Sep 17 00:00:00 2001 From: Mikolaj Kucharski Date: Mon, 3 May 2021 20:40:40 +0000 Subject: [PATCH 2/3] Revert "unattended-upgrade-shutdown: fix wait-for-signal" Problem is in different place. --- unattended-upgrade-shutdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unattended-upgrade-shutdown b/unattended-upgrade-shutdown index 8c30a535..f59e2129 100755 --- a/unattended-upgrade-shutdown +++ b/unattended-upgrade-shutdown @@ -339,7 +339,7 @@ class UnattendedUpgradesShutdown(): res = apt_pkg.get_lock(self.options.lock_file) logging.debug("get_lock returned %i" % res) # exit here if there is no lock - if res < 0: + if res > 0: logging.debug("lock not taken") if self.lock_was_taken: exit_log_result(self.signal_sent) From 353af0d559456f12ee808af38869b279f19f20a1 Mon Sep 17 00:00:00 2001 From: Mikolaj Kucharski Date: Mon, 3 May 2021 20:42:44 +0000 Subject: [PATCH 3/3] unattended-upgrade-shutdown: fix u-u on shutdown, second try --- unattended-upgrade-shutdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unattended-upgrade-shutdown b/unattended-upgrade-shutdown index f59e2129..64992980 100755 --- a/unattended-upgrade-shutdown +++ b/unattended-upgrade-shutdown @@ -296,7 +296,8 @@ class UnattendedUpgradesShutdown(): if self.on_shutdown_mode is None: self.on_shutdown_mode = ( not self.options.stop_only - and not self.stop_signal_received.is_set() + and ((self.options.wait_for_signal and self.stop_signal_received.is_set()) or + (not self.options.wait_for_signal and not self.stop_signal_received.is_set())) and self.apt_pkg_reinit_done and apt_pkg.config.find_b( "Unattended-Upgrade::InstallOnShutdown", False))