powerbtn.sh conflicts with logind

Bug #1201180 reported by Marco Trevisan (Treviño) on 2013-07-14
140
This bug affects 49 people
Affects Status Importance Assigned to Milestone
acpid (Ubuntu)
Medium
Martin Pitt
gnome-session (Ubuntu)
Medium
Unassigned
kde-workspace (Ubuntu)
Medium
Unassigned
systemd (Ubuntu)
Medium
Martin Pitt
systemd-shim (Ubuntu)
Medium
Unassigned

Bug Description

In saucy the PC powers down as soon as I press the power button, it seems that systemd is calling "poweroff", but I'm not sure if it's doing that in response of some other event (i.e. as callback of a dbus call):

root 4998 0.0 0.0 177932 2104 ? Sl 20:41 0:00 /usr/lib/x86_64-linux-gnu/systemd-shim
root 5012 0.0 0.0 4440 624 ? S 20:41 0:00 \_ sh -c /sbin/poweroff
root 5013 0.0 0.0 4440 628 ? S 20:41 0:00 \_ /bin/sh /sbin/shutdown -h -P now

In any case the caller or systemd itself should be aware that there's a session-manager running and that it shouldn't actually directly power off the system then.

desrt (desrt) wrote :

This is an issue between logind and gnome-session. Once systemd-shim gets the instruction to shutdown, it shuts down.

Changed in systemd-shim (Ubuntu):
status: New → Invalid
Iain Lane (laney) wrote :

I did some investigation last night. Here's what I found out. gnome-session doesn't (successfully) set a shutdown inhibitor lock, meaning that logind shuts the system down as soon as it is asked to. When run, gnome-session outputs the following warning

  gnome-session[6124]: WARNING: Error getting login monitor: -2

That comes from the following block of code

        if ((ret = sd_login_monitor_new (NULL, &sd_source->monitor)) < 0) {
                g_warning ("Error getting login monitor: %d", ret);
        } else {
                sd_source->pollfd.fd = sd_login_monitor_get_fd (sd_source->monitor);
                sd_source->pollfd.events = G_IO_IN;
                g_source_add_poll (source, &sd_source->pollfd);
        }

The return code there is '-2' which corresponds to ENOENT.

Checking the code for sd_login_monitor_new() in systemd shows that this function tries to inotify_add_watch() on a number of paths systemd cares about. If we strace -f -e trace=inotify_add_watch gnome-session then the output shows

  [pid 5439] inotify_add_watch(14, "/sys/fs/cgroup/systemd/machine", IN_MOVED_TO|IN_CREATE|IN_DELETE) = -1 ENOENT (No such file or directory)

And indeed this directory has not been created. In systemd:src/core/cgroup.c, these hierarchies are created here:

        if (m->running_as == SYSTEMD_SYSTEM) {
                cg_create(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_hierarchy, "../user");
                cg_create(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_hierarchy, "../machine");
        }

I believe the if check there is essentially systemd as PID 1, i.e. not true for Ubuntu.

In systemd git this seems to have moved to /run/systemd/machines/ created by systemd-machined.

Now, I'm not totally sure that this broken call is why the inhibitor lock isn't being set, but sd_login_monitor_new() definitely shouldn't be broken anyway and fixing this seems like a good place to start.

Martin Pitt (pitti) on 2013-07-17
Changed in systemd (Ubuntu):
status: New → Triaged
milestone: none → ubuntu-13.07
Changed in systemd-shim (Ubuntu):
assignee: nobody → Martin Pitt (pitti)
Changed in systemd (Ubuntu):
importance: Undecided → High
Changed in systemd-shim (Ubuntu):
assignee: Martin Pitt (pitti) → nobody
Changed in systemd (Ubuntu):
assignee: nobody → Martin Pitt (pitti)
Martin Pitt (pitti) on 2013-07-19
Changed in systemd (Ubuntu):
status: Triaged → In Progress
Martin Pitt (pitti) wrote :

I fixed the sd login monitor to work now, and added an autopkgtest for it. However, gnome-session still doesn't play along, so that needs further debugging on the g-session side.

Changed in systemd (Ubuntu):
importance: High → Undecided
status: In Progress → Fix Committed
Changed in gnome-session (Ubuntu):
status: New → Triaged
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package systemd - 204-0ubuntu7

---------------
systemd (204-0ubuntu7) saucy; urgency=low

  * debian/tests/control: Add missing pkg-config test dependency, drop
    unnecessary python3 dependency.
 -- Martin Pitt <email address hidden> Fri, 19 Jul 2013 11:38:40 +0200

Changed in systemd (Ubuntu):
status: Fix Committed → Fix Released
Turbo (axelhc) wrote :

Hi all,

I just installed Kubuntu 13.10 Beta a couple of days ago and this bug is still present. I'm really afraid of touching the power button.

Regards.

Turbo.

Turbo (axelhc) wrote :

Hi,

In order to be sure, I created a virtual machine two days ago and installed Kubuntu 13.10 beta 2. Then tried simulating the "press power button" and, exactly as my personal PC, it turned off inmediatly ignoring every single option in System Preferences.

Please, visit the other link:

https://bugs.launchpad.net/ubuntu/+source/kde-workspace/+bug/1124149

Really worried here, as Kubuntu 13.10 will be release in a few weeks from now :-o :-o

Regards.

Turbo.

Martin Pitt (pitti) wrote :

It seems gnome-session got fixed for this now. When I press the power button, I now get the usual dialog that asks you what to do (shutdown/reboot/etc.)

I'll add a task for kde-workspace as apparently it's still not working under KDE. I. e. the KDE session needs to inhibit logind's power button handling if it wants to handle the power button itself, similar to what gnome-session is doing in gsm_systemd_add_inhibitor() (https://git.gnome.org/browse/gnome-session/tree/gnome-session/gsm-systemd.c#n750)

Changed in gnome-session (Ubuntu):
status: Triaged → Fix Released
Launchpad Janitor (janitor) wrote :

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

Changed in kde-workspace (Ubuntu):
status: New → Confirmed
Martin Pitt (pitti) wrote :

FTR, bug 1222021 is the XFCE side of this.

Graeme Hewson (ghewson) wrote :

Also affects Kubuntu Trusty alpha.

tags: added: kubuntu trusty
Torsten Römer (dode) wrote :

Can confirm that this is still not working on Kubuntu 13.10.

Changed in gnome-session (Ubuntu):
importance: Undecided → Medium
Changed in systemd (Ubuntu):
importance: Undecided → Medium
Changed in kde-workspace (Ubuntu):
importance: Undecided → Medium
Changed in systemd-shim (Ubuntu):
importance: Undecided → Medium
Changed in kde-workspace (Ubuntu):
status: Confirmed → Triaged
Rohan Garg (rohangarg) wrote :

Hi
Could you please check if this is still present in 14.04?

Rohan Garg (rohangarg) wrote :

( Specifically for KDE )

Graeme Hewson (ghewson) wrote :

Still not working in Kubuntu 13.10 or 14.04.

Hi,

I can confirm the bug in Kubuntu 13.10 and 14.04, both full updated. This one is getting old, no solution yet ??

Thank you.

> Date: Tue, 21 Jan 2014 11:57:43 +0000
> From: <email address hidden>
> To: <email address hidden>
> Subject: [Bug 1201180] Re: Pressing power button turns off the PC ignoring the presence of another session manager
>
> Hi
> Could you please check if this is still present in 14.04?
>
> --
> You received this bug notification because you are subscribed to a
> duplicate bug report (1124149).
> https://bugs.launchpad.net/bugs/1201180
>
> Title:
> Pressing power button turns off the PC ignoring the presence of
> another session manager
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/gnome-session/+bug/1201180/+subscriptions

Turbo (axelhc) wrote :

Hi,

I can confirm the bug in Kubuntu 13.10 and 14.04, both full updated.
This one is getting old, no solution yet ??

Thank you.

> Date: Tue, 21 Jan 2014 11:58:05 +0000
> From: <email address hidden>
> To: <email address hidden>
> Subject: [Bug 1201180] Re: Pressing power button turns off the PC ignoring the presence of another session manager
>
> ( Specifically for KDE )
>
> --
> You received this bug notification because you are subscribed to a
> duplicate bug report (1124149).
> https://bugs.launchpad.net/bugs/1201180
>
> Title:
> Pressing power button turns off the PC ignoring the presence of
> another session manager
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/gnome-session/+bug/1201180/+subscriptions

Turbo (axelhc) wrote :

Hi,

I can confirm the bug in Kubuntu 13.10 and 14.04, both full updated.
This one is getting old, no solution yet ??

Thank you.

> Date: Tue, 21 Jan 2014 11:57:43 +0000
> From: <email address hidden>
> To: <email address hidden>
> Subject: [Bug 1201180] Re: Pressing power button turns off the PC ignoring the presence of another session manager
>
> Hi
> Could you please check if this is still present in 14.04?
>
> --
> You received this bug notification because you are subscribed to a
> duplicate bug report (1124149).
> https://bugs.launchpad.net/bugs/1201180
>
> Title:
> Pressing power button turns off the PC ignoring the presence of
> another session manager
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/gnome-session/+bug/1201180/+subscriptions

I can confirm the bug in Kubuntu 13.10, the attached patch works for me. (The trouble seems to be that /usr/bin/qdbus links to /usr/bin/qtchooser which does not seem to work as expected.)

The attachment "Patch for powerbtn.sh which checks for qdbus availabilities." seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
Tobias Lübben (tl) wrote :

daniel’s KDE Patch works for me, too! (Kubuntu 13.10)

Hi,

May I try it on Kubuntu 14.04 beta ??

Thank you.

> Date: Mon, 17 Mar 2014 14:21:33 +0000
> From: <email address hidden>
> To: <email address hidden>
> Subject: [Bug 1201180] Re: Pressing power button turns off the PC ignoring the presence of another session manager
>
> daniel’s KDE Patch works for me, too! (Kubuntu 13.10)
>
> --
> You received this bug notification because you are subscribed to a
> duplicate bug report (1124149).
> https://bugs.launchpad.net/bugs/1201180
>
> Title:
> Pressing power button turns off the PC ignoring the presence of
> another session manager
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/gnome-session/+bug/1201180/+subscriptions

Adding acpid task for the qdbus fix, subscribing sponsors.

Changed in acpid (Ubuntu):
status: New → Triaged
Changed in acpid (Ubuntu):
importance: Undecided → Medium

Still broken in 14.04 LTS beta 2 !

Commenting out or removing the final "/sbin/shutdown -h now "Power button pressed"" line in /etc/acpi/powerbtn.sh fixes things, such that the laptop does what KDE is set to.

In which case this bug is a duplicate of the long standing #1243399 and #268734

Hi,

I can confirm that comenting the line as he said, works as it should.

Just don't get it; if the solution is so easy, WHY this bug is alive several years late.

Regards.

> Date: Sat, 29 Mar 2014 23:52:12 +0000
> From: <email address hidden>
> To: <email address hidden>
> Subject: [Bug 1201180] Re: Pressing power button turns off the PC ignoring the presence of another session manager
>
> In which case this bug is a duplicate of the long standing #1243399 and
> #268734
>
> --
> You received this bug notification because you are subscribed to a
> duplicate bug report (1124149).
> https://bugs.launchpad.net/bugs/1201180
>
> Title:
> Pressing power button turns off the PC ignoring the presence of
> another session manager
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/acpid/+bug/1201180/+subscriptions

I think we should completely disable powerbtn.sh if logind is running; that's much safer than trying to cover all session managers, and much more correct too as logind itself handles the power button unless a session manager inhibits it.

Changed in acpid (Ubuntu):
assignee: nobody → Martin Pitt (pitti)
summary: - Pressing power button turns off the PC ignoring the presence of another
- session manager
+ powerbtn.sh conflicts with logind
Changed in acpid (Ubuntu):
milestone: none → ubuntu-14.04
Martin Pitt (pitti) on 2014-04-03
Changed in acpid (Ubuntu):
status: Triaged → Fix Committed
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package acpid - 1:2.0.21-1ubuntu2

---------------
acpid (1:2.0.21-1ubuntu2) trusty; urgency=medium

  * ./debian/powerbtn.sh: Don't do anything if logind is running, as that
    already handles power button presses. This fixes unconditional shutdowns
    if a desktop environment wants to handle the power key by itself (and
    inhibits logind). (LP: #1201180)
 -- Martin Pitt <email address hidden> Thu, 03 Apr 2014 14:53:35 +0100

Changed in acpid (Ubuntu):
status: Fix Committed → Fix Released
Dmitry Shachnev (mitya57) wrote :

rubik-cube: there are some issues with your patch:

1) Do not hardcode x86_64-linux-gnu triplet, which only works on amd64. Instead, you can use `dpkg-architecture -qDEB_HOST_MULTIARCH` for example.
2) `test -L /usr/bin/qdbus` will be *always* true, as the binary is managed by qtchooser.
3) Finally, please generate a proper debdiff with a changelog entry.

Also, please note that instead of specifying full paths to qdbus binary, you can just run `qdbus -qt4` or `qdbus -qt5` without caring about the paths (though not sure if it's helpful here).

Unsubscribing sponsors unless these issues are resolved.

Bernhard (baumber) wrote :

This patch makes it worse for KDE/Powerdevil, because "Standby" is not selectable anymore in Powerdevil dialog and it continues to ignore the power button setting => shutdown immediately.

Martin Pitt (pitti) wrote :

Bernard, what do you mean with "this patch"? The acpid fix that I uploaded has zero impact on the KDE/powerdevil settings. Daniel Hornung's patch also doesn't, but that wasn't uploaded. Which one did you test?

Also, please ensure that you have systemd-services 204-5ubuntu17 installed. ubuntu15 and 16 were dramatically failing pretty much everything due to some critical bugs in the new cgmanager integration. If you ran these versions they probably interfered with your testing of this.

Bernhard (baumber) wrote :

I have tested acpid (1:2.0.21-1ubuntu2) with "systemd-services 204-5ubuntu16" ...

You are correct, with installing "systemd-services 204-5ubuntu17" all is working fine again.

KDE/Powerdevil with powerbutton settings work as expected.

Thank you for your clarification!

Hi,

this patch:

if pidof systemd-logind >/dev/null; then
    exit 0
fi

together with this line:
PMS="$PMS unity-settings-daemon"

are preventing me from using the power button to immediatly shutdown Ubuntu without any confirmation. In my case I want to be able to shut down an Ubuntu VM through acpi from virsh.

With the current powerbtn.sh the following configuration lines this won't have much effect :-(

gsettings set org.gnome.settings-daemon.plugins.power button-power 'shutdown'
gsettings set org.gnome.SessionManager logout-prompt false
gsettings set com.canonical.indicator.session suppress-logout-restart-shutdown true

Erik Hovland (erik-m) wrote :

I can confirm that systemd logind is in control of the power button on my ASUS UX305 laptop as of Kubuntu 15.04. This means that no matter what the settings in KDE system-settings the power button is handled by logind.

Since the power button is right above backspace and I often hit the backspace key (and have accidentally shut off my laptop several times) I have changed the line in /etc/systemd/logind.conf to:
HandlePowerKey=ignore

This renders the power key useless, but that is better then accidentally shutting my computer off in the middle of typing.

If logind is going to "handle" the power key, maybe system-settings should deal with logind and not acpi or whatever else system-settings is trying modify to get configuration control of the power key?

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

Duplicates of this bug

Other bug subscribers