-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation/example missing for use of Inhibitor interface #34004
Comments
API means D-Bus API. You can find a full implementation to find inspiration from here: https://github.com/systemd/systemd/blob/main/src/login/inhibit.c |
Ok, thanks. So the C-looking "pseudo code" in the docs was just that - really pseudo, just C-looking, and in fact was about D-bus calls to the systemd daemons managing the system like In that case, perhaps a link to this source from the doc would be helpful =D Also, does the phrase "Taking inhibitor locks is a privileged operation" mean that taking such locks is an operation limited to privileged users or systemd units set up with special properties, so a random user-space process would not block OS life-cycle? Is there something to be detailed about this in that doc (e.g. what can non-root services do to get that privilege) or did I misunderstand the statement? |
Seems the referenced Wondering also if there is an autotools-friendly way to determine support for the feature, or just that the systemd version is to be consulted? |
This doc seems important to reference for "independent" development (that does not rely on internal headers etc.): ...because my tinkering so far reflects That man page also notes that The tool also refers to https://www.freedesktop.org/software/systemd/man/latest/sd_bus_message_enter_container.html which seems to be since 246 (no clear reference)... |
And also https://systemd.io/INHIBITOR_LOCKS/ is not in sync with https://github.com/systemd/systemd/blob/main/docs/INHIBITOR_LOCKS.md at least in regard to |
…us API) [networkupstools#1070] Thanks to pointers from systemd/systemd#34004 Signed-off-by: Jim Klimov <[email protected]>
@bluca : If I may, got another moment to clarify: as far as these bus messages and boolean states go, is "sleep" same as "suspend" or "hibernate"? |
Man pages to
|
Well, with systemd in WSL2 enabled via Can't get WSL2 to
|
Component
No response
Is your feature request related to a problem? Please describe
I investigate for an issue at networkupstools/nut#1070 to develop integration for a daemon with the systemd inhibitor interface, so that NUT
upsmon
would not shut down the system after a sleep and wake-up due to "lost" UPS last known to be in a critical state.Documentation at https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.login1.html implies that it "provides both a C library interface as well as a D-Bus interface", at https://www.freedesktop.org/software/systemd/man/latest/sd-login.html that "It is possible (and often a very good choice) to mix calls to the synchronous interface of sd-login.h with the asynchronous D-Bus interface of systemd-logind" and at https://systemd.io/INHIBITOR_LOCKS/ and https://github.com/systemd/systemd/blob/main/docs/INHIBITOR_LOCKS.md offers actual (pseudo-)code with
Inhibit()
method getting a file descriptor toclose()
later.I did not find any headers with C methods like
Inhibit
,PrepareForSleep
,PrepareForShutdown
orListInhibitors
on a couple of systems withlibsystemd-dev(el)
installed.Describe the solution you'd like
Clarify if there is actually a plain C API and provide a simple complete example.
Describe alternatives you've considered
Looking a bit at monsters like https://stackoverflow.com/questions/78653343/how-to-get-an-inhibitor-lock-for-a-service-in-c-language makes me scared about complex changes needed for a platform-specific bit.
If this is the only supported way, so be it, but I hoped that I can just call
if (PrepareForSleep(...))
in the program's main loop, and react to the returned value (e.g. set a flag internally to not consider stale UPS data as fatal, and clear the inhibitor lock so the system can go to sleep to conserve the battery).The systemd version you checked that didn't have the feature you are asking for
249
The text was updated successfully, but these errors were encountered: