/usr/sbin/on_ac_power incorrectly reporting ac power status

Bug #1980991 reported by Kevin Tate
46
This bug affects 7 people
Affects Status Importance Assigned to Milestone
powermgmt-base (Ubuntu)
Triaged
High
Unassigned
Kinetic
Won't Fix
High
Unassigned
Lunar
Triaged
High
Unassigned

Bug Description

Good afternoon, folks.

I believe I discovered a bug in the /usr/sbin/on_ac_power script. I have a Dell OptiPlex 5090 host that has an entry in /sys/class/power_supply for "ucsi-source-psy-USBC000:001". I believe this is the USB-C power delivery port on the front of the chassis. The issue I'm encountering is that /usr/sbin/on_ac_power is exiting with code 1 which states: (1 (false) if not on AC power) when that isn't the case.

This looks to be because of the ucsi-source-psy-USBC000:001 entry reporting the "online" status as 0, presumably because nothing is currently connected to that USB-C port.

This causes /usr/sbin/on_ac_power to incorrectly report that the machine isn't connected to AC power and causes other utilities like unattended-upgrades to quit when using the default configuration since it believes the machine isn't connected to AC power.

There is a workaround with unattended-upgrades where you can specify it to run regardless of if AC power is connected, but as more and more chassis implement power-delivery USB-C ports I foresee this becoming more of an issue.

I'm not sure if it's anything to look into, but I figured I would share my findings. Please let me know if you have any questions or if I can provide any additional information, troubleshooting, or testing.

Thanks!
-Kevin

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in powermgmt-base (Ubuntu):
status: New → Confirmed
Revision history for this message
Brian Murray (brian-murray) wrote :

Looking at the package, it hasn't been updated in 3 years in Debian.

tags: added: rls-kk-incoming
Changed in powermgmt-base (Ubuntu):
importance: Undecided → High
Lukas Märdian (slyon)
tags: added: fr-2548
tags: removed: rls-kk-incoming
Revision history for this message
Gordon Lack (gordon-lack) wrote :

I have this issue on an Intel NUC (NUC10i357FN).

The sysfs entry for the power supply does contain a usb_type entry for it, which contains:

[nuc]: cat usb_type
[C] PD

Revision history for this message
Gordon Lack (gordon-lack) wrote (last edit ):

Possibly this?

--- /bin/on_ac_power 2019-07-20 16:43:51.000000000 +0100
+++ ./on_ac_power 2022-09-22 01:44:53.412558622 +0100
@@ -28,6 +28,17 @@
            type="$(cat "${FN}/type")"
            case "${type}" in
            Mains|USB*|BrickID|Wireless)
+# If USB, is it input or output?
+#
+ case "${type}" in
+ USB*)
+ if test -r "${FN}/usb_type"; then
+ usb_type=`cat "${FN}/usb_type"`
+ case "${usb_type}" in
+ *PD*) continue ;;
+ esac
+ fi
+ esac
                if [ -r "${FN}/online" ]; then
                    online="$(cat "${FN}/online")"
                    [ "$online" = 1 ] && exit 0

(sorry - the indentation spaces after any + are being eaten)

Dan Bungert (dbungert)
Changed in powermgmt-base (Ubuntu Kinetic):
status: Confirmed → Triaged
Revision history for this message
Gordon Lack (gordon-lack) wrote :

This is still an issue in Kinetic.

And it's now stopping unattended_upgrades running, as these (now?) have a condition of ConditionACPower=true
which is not being met even though the system is running on AC (and has no other way of running).

Revision history for this message
Gordon Lack (gordon-lack) wrote (last edit ):

Actually, it turns out that systemd has its own code to check for AC power (same/similar logic - perhaps this should be done in a single system service rather than duplicated between sub-systems?).

So I'll open a bug for this against systemd as well and cross-reference them.

The systemd bug report for this is bug #1998872

Revision history for this message
Gordon Lack (gordon-lack) wrote :

/lib/systemd/systemd-ac-power works (on lunar). on_ac_power still does not.

Perhaps on_ac_power should just be made a symlink to this - or the script should exec that systemd executable if it exists?

Nick Rosbrook (enr0n)
tags: added: rls-mm-incoming
Revision history for this message
Bjorn Toft Madsen (sunbeam60) wrote :

It's worth adding that in #1973359 (was closed as duplicate of this bug; I was the author), the computer is plugged in with a barrel power plug, not via USB-C PD. I'm not sure how it still ends up being routed as a USB power source in /sys/class/power_supply. Specifically, it's this computer: https://imgur.com/a/0nUFAFH ... so it's very much in "has consistent power" range.

tags: added: foundations-todo
removed: rls-mm-incoming
Revision history for this message
Utkarsh Gupta (utkarsh) wrote :

Ubuntu 22.10 (Kinetic Kudu) has reached end of life, so this bug will not be fixed for that specific release.

Changed in powermgmt-base (Ubuntu Kinetic):
status: Triaged → Won't Fix
Revision history for this message
Gordon Lack (gordon-lack) wrote (last edit ):

It's *still* a bug in 23.04.

Do I need to open a new bug report?

Or do I have to wait until another LTS version comes along and report it against that (since it was also a problem with the previous LTS version, and hence still will be - note the comment above that it hasn't been changed in 3 years).

Revision history for this message
Nick Rosbrook (enr0n) wrote :

Gordon - Utkarsh's comment is just about cleaning up Kinetic-related items. We understand that this is still a problem in other releases.

Revision history for this message
Gordon Lack (gordon-lack) wrote :

However, I can't see any bug report for it it any other (later) release.

So this one is marked as High importance, but Won't fix.

There's a similar bug report about this from 2019 (bug #1823521). *That* was reported on 18.04.

Revision history for this message
Nick Rosbrook (enr0n) wrote :

This bug is only marked as "Won't Fix" for *Kinetic*; the "Triaged" state implicitly applies to the current development release (i.e. Mantic). In other words, this indicates that this bug has not been knowingly fixed in *any* release, and still needs attention.

Changed in powermgmt-base (Ubuntu Lunar):
status: New → Triaged
importance: Undecided → High
Revision history for this message
Nick Rosbrook (enr0n) wrote :

By the way - is the main problem for you behavior with unattended-upgrades? Or just use of the on_ac_power script in general?

If the main problem is unattended-upgrades, we can more quickly remove use of on_ac_power from that, as opposed move everything away from using on_ac_power.

Revision history for this message
Gordon Lack (gordon-lack) wrote :

I'm not the bug opener, but the main problem for *me* was with unattended-upgrades as I noticed it had stopped running (while my other systems were still updating).
But that is fixed (as it runs from systemd and the systemd AC power check was fixed in Lunar).

However, there are (at least) 3 crontab entries in /etc/cron.daily or weekly (apt-compat, plocate and apt-xapian-index) using on_ac_power (although 2 of those don't run from cron if systemd is running...). This isn't bothering me.

Revision history for this message
Bjorn Toft Madsen (sunbeam60) wrote :

FWIW, I opened the duplicate of this bug, and my problem was entirely with unattended upgrades.

Revision history for this message
jc00ke (jesse-jc00ke) wrote :

I'm seeing this issue as part of a dependency which relies on `on_ac_power`. Here's the GitHub issue: https://github.com/regolith-linux/regolith-powerd/issues/1

I'm on Lunar.

/lib/systemd/systemd-ac-power reports correctly on my desktop.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.