#1031880 unattended-upgrades: requires on_ac_power from package powermgmt-base to function at all

#1031880#5
Date:
2023-02-24 17:23:20 UTC
From:
To:
Dear Maintainer,

   * What led up to the situation?

Currently unattended-upgrades marks the powermgmt-base package
as Suggested. powermgmt-base provides the /sbin/on_ac_power and
/usr/sbin/on_ac_power script(s), which unattended-upgrades requires to
function at all, because of this check in /usr/bin/unattended-upgrade
at line 676:

if apt_pkg.config.find_b("Unattended-Upgrade::OnlyOnACPower", True) \
   and subprocess.call("on_ac_power") == 1:

The absence of the powermgmt-base package, and thus the on_ac_power
script, results in the following error:

root# /usr/bin/unattended-upgrade
Traceback (most recent call last):
  File "/usr/bin/unattended-upgrade", line 2522, in <module>
    sys.exit(main(options))
  File "/usr/bin/unattended-upgrade", line 1993, in main
    res = run(options, rootdir, mem_log, logfile_dpkg,
  File "/usr/bin/unattended-upgrade", line 2061, in run
    if should_stop():
  File "/usr/bin/unattended-upgrade", line 676, in should_stop
    and subprocess.call("on_ac_power") == 1:
  File "/usr/lib/python3.9/subprocess.py", line 349, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: 'on_ac_power'

(Note that it's not clear to me why this is a PermissionError, since
the script doesn't actually exist, but that is a secondary point.)

The powermgmt-base package needs to be installed in order for
unattended-upgrades to function at all. Thus, the powermgmt-base package
needs to be marked as Depends for unattended-upgrades.

   * What exactly did you do (or not do) that was effective (or
     ineffective)?

Installing the powermgmt-base package makes the problem go away.

Thanks much,
--
Steve Lane
sdlane@lbl.gov

#1031880#10
Date:
2023-02-25 08:21:08 UTC
From:
To:
Hi Steve,

* Steve Lane <sdlane@lbl.gov> [2023-02-24 09:23]:

I can't reproduce this error on a fresh stable nor unstable VM without
powermgmt-base installed.

But this makes it reproducible:

touch /usr/bin/on_ac_power

So I guess you have a non executable on_ac_power in your $PATH.

I disagree and propose this patch instead:

https://github.com/mvo5/unattended-upgrades/pull/341

Cheers Jochen

#1031880#15
Date:
2023-02-25 20:24:08 UTC
From:
To:
Hi Jochen,

Thanks very much for looking into this so quickly. On a machine with root's
$PATH set to the default value:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Without powermgmt-base installed, I am seeing the following:

root# which -a on_ac_power
root#

(i.e. an executable on_ac_power is not found anywhere in root's $PATH), and;

root# for p in $( echo $PATH | sed 's/:/ /g' ) ; do ls -l ${p}/on_ac_power
; done
ls: cannot access '/usr/local/sbin/on_ac_power': No such file or directory
ls: cannot access '/usr/local/bin/on_ac_power': No such file or directory
ls: cannot access '/usr/sbin/on_ac_power': No such file or directory
ls: cannot access '/usr/bin/on_ac_power': No such file or directory
ls: cannot access '/sbin/on_ac_power': No such file or directory
ls: cannot access '/bin/on_ac_power': No such file or directory
root#

(i.e. as far as I am able to determine, there is no on_ac_power file in root's
$PATH without powermgmt-base installed on this machine).

Note that, in this situation, I am seeing the following:

root# which unattended-upgrade
/usr/bin/unattended-upgrade
root# unattended-upgrade
root#

(i.e. normal / expected behavior from unattended-upgrade).

After installing powermgmt-base, I see the following:

root# which -a on_ac_power
/usr/sbin/on_ac_power
/usr/bin/on_ac_power
/sbin/on_ac_power
/bin/on_ac_power
root# for p in $( echo $PATH | sed 's/:/ /g' ) ; do ls -l ${p}/on_ac_power
; done
ls: cannot access '/usr/local/sbin/on_ac_power': No such file or directory
ls: cannot access '/usr/local/bin/on_ac_power': No such file or directory
-rwxr-xr-x 1 root root 2228 Jul 20  2019 /usr/sbin/on_ac_power
lrwxrwxrwx 1 root root 17 Jul 20  2019 /usr/bin/on_ac_power ->
/sbin/on_ac_power
-rwxr-xr-x 1 root root 2228 Jul 20  2019 /sbin/on_ac_power
lrwxrwxrwx 1 root root 17 Jul 20  2019 /bin/on_ac_power -> /sbin/on_ac_power

and unattended-upgrade continues to behave normally.

I suspect that what happened was, on the machines I was testing on,
incomplete uninstalls of powermgmt-base resulted in the executables being
removed, but the links in /usr/bin and/or /bin to remain, creating the
problem I was seeing.

(I have a very slight idea how this might have happened, but that is a
separate issue.)

I think your recommended solution under these circumstances is the right
one. Thanks again very much for looking into this. Please feel free to
close this ticket (if you have not done so already).

Best,
--
Steve Lane

#1031880#20
Date:
2023-02-26 20:38:28 UTC
From:
To:
user debian-release@lists.debian.org

usertag 1031880 + bsp-2023-02-ca-montreal
severity 1031880 normal
thank you

Hi,

Although this seems like a real bug, I feel like the conditions to
reproduce it are very specific and do not justify the current severity.

As such, I'm downgrading it to severity: normal.

Cheers,