Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 905440 - emerge should call systemd-inhibit
Summary: emerge should call systemd-inhibit
Status: CONFIRMED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All Linux
: Normal minor (vote)
Assignee: Portage team
URL: https://forums.gentoo.org/viewtopic-t...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-05-02 02:41 UTC by C. Wijtmans
Modified: 2023-08-10 19:56 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description C. Wijtmans 2023-05-02 02:41:07 UTC
To prevent systemd going idle and going to sleep during build or sync emerge should call `systemd-inhibit --mode=block --what=idle --who=portage --why="emerge running"`.

See for example RPM plugin https://www.man7.org/linux/man-pages/man8/rpm-plugin-systemd-inhibit.8.html


Reproducible: Always

Steps to Reproduce:
Set IdleAction and emerge something
Actual Results:  
machines goes "idle" and sleeps

Expected Results:  
machines goes brrrr


my config.

> 📄 `/etc/systemd/logind.conf`
>
> ```ini
> [Login]
> HandlePowerKey=suspend
> HandlePowerKeyLongPress=poweroff
> HandleHibernateKey=suspend
> HandleHibernateKeyLongPress=hibernate
> IdleAction=suspend
> IdleActionSec=15min
> ```
Comment 1 John Helmert III archtester Gentoo Infrastructure gentoo-dev Security 2023-05-02 02:57:21 UTC
$ grep Idle /etc/systemd/logind.conf
#IdleAction=ignore
#IdleActionSec=30min
#StopIdleSessionSec=infinity

It looks like by default, nothing is done on idle? I'm not sure Portage is the right place to change the behavior of users' configuration.
Comment 2 C. Wijtmans 2023-05-02 12:20:54 UTC
I think you are correct about default behaviour but emerge should allow it to be called somehow. But I think allowing a script to be called by emerge is a security risk? Or am I going to be forced to `alias emerge = systemd-inhibit ... emerge`
Comment 3 Alec Warner (RETIRED) archtester gentoo-dev Security 2023-05-02 23:32:08 UTC
(In reply to C. Wijtmans from comment #2)
> I think you are correct about default behaviour but emerge should allow it
> to be called somehow. But I think allowing a script to be called by emerge
> is a security risk? Or am I going to be forced to `alias emerge =
> systemd-inhibit ... emerge`

I suspect a wrapper script will yield the quickest resolution for you.

Emerge has "hooks" that it calls at various points; but the primary function of hooks is to run code at certain times while emerge is running (during hooked points of interest where we run callbacks); hooks are not needed for pre / post actions; callers can simply wrap emerge in those cases.

-A
Comment 4 C. Wijtmans 2023-05-04 16:51:25 UTC
Is there a hook for installation phase? That is the most important one against possible corruptions. Although i would like to have one for the whole process
Comment 5 C. Wijtmans 2023-05-04 16:57:39 UTC
My first thought was to prevent system to idle when emerge is doing its thing. The thing is i just realized how important inhibiting shutdown or reboot during installation would be bumping the importance of the "bug" report a bit.
Comment 6 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-05-05 05:58:45 UTC
(In reply to C. Wijtmans from comment #5)
> My first thought was to prevent system to idle when emerge is doing its
> thing. The thing is i just realized how important inhibiting shutdown or
> reboot during installation would be bumping the importance of the "bug"
> report a bit.

You've made me realise a good reason to do it as well. We don't want the system to go to sleep or similar during PAM upgrades (think pam upgraded but not pambase yet, or vice versa), because there's a risk of the screenlocker not working when it comes back.

That's disruptive in itself but it also might cause the user to reboot (making the situation worse as it'll disrupt the ongoing upgrade).
Comment 7 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-05-05 06:00:37 UTC
Forums discussion: https://forums.gentoo.org/viewtopic-t-1163094.html.
Comment 8 C. Wijtmans 2023-05-05 14:08:46 UTC
Actually my system is about a NAS(headless and no GUI) I am making with old hardware and I do not want it running all the time using 50watt. In suspend it consumes 3watt and waits for a wol mmagic/unicast signal. The issue is systemd uses "user activity" to determine idle, whatever that means. When talking baout default behaviour systemd turns off when you press the power button. That is dangerous to do during an installation process so emerge should inihibt poweroff/reboot at the very least. I configured it to suspend instead. But i think it would be wise to inhibit suspend/sleep/hibernatae as well since a lot can go wrong there. It really doesnt solve my main problem but it solves a problem with emerge and power management(with systemd) considering it even happens with default behaviour in the systemd profile.
Comment 9 Fabian Groffen gentoo-dev 2023-05-06 17:23:26 UTC
Feels like this could use some hooks that can be run at emerge start and finish so you can implement on your system to call systemd-inhibit, others could use caffeinate, etc.  If the start hook would expose portage's main PID via an envvar, it would be trivial to call something like caffeinate -w ${MAIN_PID}.