diff options
| author | Michael Albinus | 2026-01-17 11:40:31 +0100 |
|---|---|---|
| committer | Michael Albinus | 2026-01-17 11:40:31 +0100 |
| commit | ab77b4b60ca1837e2da5147e6604cd2020567b80 (patch) | |
| tree | 2904dc0a52c8c96bc44efca75dec15b2d250a114 /doc | |
| parent | 6287637ccd9f66a219844231380ab9873d049c6e (diff) | |
| download | emacs-ab77b4b60ca1837e2da5147e6604cd2020567b80.tar.gz emacs-ab77b4b60ca1837e2da5147e6604cd2020567b80.zip | |
New D-Bus functions to support systemd inhibitor locks
* doc/misc/dbus.texi (Top): Add "Inhibitor Locks" submenu.
Remove trailing period from chapter and section titles.
(Inhibitor Locks): New node.
* etc/NEWS: New D-Bus functions to support systemd inhibitor locks.
Presentational fixes and improvements.
* src/dbusbind.c (xd_registered_inhibitor_locks): New variable.
(Fdbus_make_inhibitor_lock, Fdbus_close_inhibitor_lock)
(Fdbus_registered_inhibitor_locks): New DEFUNs. (Bug#79963)
(syms_of_dbusbind_for_pdumper): Initialize
`xd_registered_inhibitor_locks'.
(syms_of_dbusbind): Declare subroutines
`Sdbus_make_inhibitor_lock', `Sdbus_close_inhibitor_lock' and
`Sdbus_registered_inhibitor_locks'. Declare symbol `Qdbus_call_method'.
staticpro `xd_registered_inhibitor_locks'.
* test/lisp/net/dbus-tests.el (dbus--test-systemd-service)
(dbus--test-systemd-path, dbus--test-systemd-manager-interface):
New defconsts.
(dbus-test10-inhibitor-locks): New test.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/misc/dbus.texi | 142 |
1 files changed, 124 insertions, 18 deletions
diff --git a/doc/misc/dbus.texi b/doc/misc/dbus.texi index 7fad406520c..946e7666629 100644 --- a/doc/misc/dbus.texi +++ b/doc/misc/dbus.texi | |||
| @@ -64,6 +64,7 @@ another. An overview of D-Bus can be found at | |||
| 64 | * Alternative Buses:: Alternative buses and environments. | 64 | * Alternative Buses:: Alternative buses and environments. |
| 65 | * Errors and Events:: Errors and events. | 65 | * Errors and Events:: Errors and events. |
| 66 | * Monitoring Messages:: Monitoring messages. | 66 | * Monitoring Messages:: Monitoring messages. |
| 67 | * Inhibitor Locks:: Inhibit system shutdowns and sleep states. | ||
| 67 | * Index:: Index including concepts, functions, variables. | 68 | * Index:: Index including concepts, functions, variables. |
| 68 | 69 | ||
| 69 | * GNU Free Documentation License:: The license for this documentation. | 70 | * GNU Free Documentation License:: The license for this documentation. |
| @@ -124,7 +125,7 @@ name could be @samp{org.gnu.Emacs.TextEditor} or | |||
| 124 | 125 | ||
| 125 | 126 | ||
| 126 | @node Inspection | 127 | @node Inspection |
| 127 | @chapter Inspection of D-Bus services. | 128 | @chapter Inspection of D-Bus services |
| 128 | @cindex inspection | 129 | @cindex inspection |
| 129 | 130 | ||
| 130 | @menu | 131 | @menu |
| @@ -139,7 +140,7 @@ name could be @samp{org.gnu.Emacs.TextEditor} or | |||
| 139 | 140 | ||
| 140 | 141 | ||
| 141 | @node Version | 142 | @node Version |
| 142 | @section D-Bus version. | 143 | @section D-Bus version |
| 143 | 144 | ||
| 144 | D-Bus has evolved over the years. New features have been added with | 145 | D-Bus has evolved over the years. New features have been added with |
| 145 | new D-Bus versions. There are two variables, which allow the determination | 146 | new D-Bus versions. There are two variables, which allow the determination |
| @@ -158,7 +159,7 @@ It is also @code{nil}, if it cannot be determined at runtime. | |||
| 158 | 159 | ||
| 159 | 160 | ||
| 160 | @node Bus names | 161 | @node Bus names |
| 161 | @section Bus names. | 162 | @section Bus names |
| 162 | 163 | ||
| 163 | There are several basic functions which inspect the buses for | 164 | There are several basic functions which inspect the buses for |
| 164 | registered names. Internally they use the basic interface | 165 | registered names. Internally they use the basic interface |
| @@ -267,7 +268,7 @@ at D-Bus @var{bus}, as a string. | |||
| 267 | 268 | ||
| 268 | 269 | ||
| 269 | @node Introspection | 270 | @node Introspection |
| 270 | @section Knowing the details of D-Bus services. | 271 | @section Knowing the details of D-Bus services |
| 271 | 272 | ||
| 272 | D-Bus services publish their interfaces. This can be retrieved and | 273 | D-Bus services publish their interfaces. This can be retrieved and |
| 273 | analyzed during runtime, in order to understand the used | 274 | analyzed during runtime, in order to understand the used |
| @@ -483,7 +484,7 @@ If @var{object} has no @var{attribute}, the function returns | |||
| 483 | 484 | ||
| 484 | 485 | ||
| 485 | @node Nodes and Interfaces | 486 | @node Nodes and Interfaces |
| 486 | @section Detecting object paths and interfaces. | 487 | @section Detecting object paths and interfaces |
| 487 | 488 | ||
| 488 | The first elements, to be introspected for a D-Bus object, are further | 489 | The first elements, to be introspected for a D-Bus object, are further |
| 489 | object paths and interfaces. | 490 | object paths and interfaces. |
| @@ -593,7 +594,7 @@ data from a running system: | |||
| 593 | 594 | ||
| 594 | 595 | ||
| 595 | @node Methods and Signal | 596 | @node Methods and Signal |
| 596 | @section Applying the functionality. | 597 | @section Applying the functionality |
| 597 | 598 | ||
| 598 | Methods and signals are the communication means to D-Bus. The | 599 | Methods and signals are the communication means to D-Bus. The |
| 599 | following functions return their specifications. | 600 | following functions return their specifications. |
| @@ -673,7 +674,7 @@ Example: | |||
| 673 | 674 | ||
| 674 | 675 | ||
| 675 | @node Properties and Annotations | 676 | @node Properties and Annotations |
| 676 | @section What else to know about interfaces. | 677 | @section What else to know about interfaces |
| 677 | 678 | ||
| 678 | Interfaces can have properties. These can be exposed via the | 679 | Interfaces can have properties. These can be exposed via the |
| 679 | @samp{org.freedesktop.DBus.Properties} interface@footnote{See | 680 | @samp{org.freedesktop.DBus.Properties} interface@footnote{See |
| @@ -894,7 +895,7 @@ An attribute value can be retrieved by | |||
| 894 | 895 | ||
| 895 | 896 | ||
| 896 | @node Arguments and Signatures | 897 | @node Arguments and Signatures |
| 897 | @section The final details. | 898 | @section The final details |
| 898 | 899 | ||
| 899 | Methods and signals have arguments. They are described in the | 900 | Methods and signals have arguments. They are described in the |
| 900 | @code{arg} XML elements. | 901 | @code{arg} XML elements. |
| @@ -962,7 +963,7 @@ non-@code{nil}, @var{direction} must be @samp{out}. Example: | |||
| 962 | 963 | ||
| 963 | 964 | ||
| 964 | @node Type Conversion | 965 | @node Type Conversion |
| 965 | @chapter Mapping Lisp types and D-Bus types. | 966 | @chapter Mapping Lisp types and D-Bus types |
| 966 | @cindex type conversion | 967 | @cindex type conversion |
| 967 | 968 | ||
| 968 | D-Bus method calls and signals accept usually several arguments as | 969 | D-Bus method calls and signals accept usually several arguments as |
| @@ -975,7 +976,7 @@ applied Lisp object @expansion{} D-Bus type for input parameters, and | |||
| 975 | D-Bus type @expansion{} Lisp object for output parameters. | 976 | D-Bus type @expansion{} Lisp object for output parameters. |
| 976 | 977 | ||
| 977 | 978 | ||
| 978 | @section Input parameters. | 979 | @section Input parameters |
| 979 | 980 | ||
| 980 | Input parameters for D-Bus methods and signals occur as arguments of a | 981 | Input parameters for D-Bus methods and signals occur as arguments of a |
| 981 | Lisp function call. The following mapping to D-Bus types is | 982 | Lisp function call. The following mapping to D-Bus types is |
| @@ -1116,7 +1117,7 @@ lower-case hex digits. As a special case, "" is escaped to | |||
| 1116 | @end defun | 1117 | @end defun |
| 1117 | 1118 | ||
| 1118 | 1119 | ||
| 1119 | @section Output parameters. | 1120 | @section Output parameters |
| 1120 | 1121 | ||
| 1121 | Output parameters of D-Bus methods and signals are mapped to Lisp | 1122 | Output parameters of D-Bus methods and signals are mapped to Lisp |
| 1122 | objects. | 1123 | objects. |
| @@ -1199,7 +1200,7 @@ that string: | |||
| 1199 | 1200 | ||
| 1200 | 1201 | ||
| 1201 | @node Synchronous Methods | 1202 | @node Synchronous Methods |
| 1202 | @chapter Calling methods in a blocking way. | 1203 | @chapter Calling methods in a blocking way |
| 1203 | @cindex method calls, synchronous | 1204 | @cindex method calls, synchronous |
| 1204 | @cindex synchronous method calls | 1205 | @cindex synchronous method calls |
| 1205 | 1206 | ||
| @@ -1319,7 +1320,7 @@ emulate the @code{lshal} command on GNU/Linux systems: | |||
| 1319 | 1320 | ||
| 1320 | 1321 | ||
| 1321 | @node Asynchronous Methods | 1322 | @node Asynchronous Methods |
| 1322 | @chapter Calling methods non-blocking. | 1323 | @chapter Calling methods non-blocking |
| 1323 | @cindex method calls, asynchronous | 1324 | @cindex method calls, asynchronous |
| 1324 | @cindex asynchronous method calls | 1325 | @cindex asynchronous method calls |
| 1325 | 1326 | ||
| @@ -1371,7 +1372,7 @@ message arrives, and @var{handler} is called. Example: | |||
| 1371 | 1372 | ||
| 1372 | 1373 | ||
| 1373 | @node Register Objects | 1374 | @node Register Objects |
| 1374 | @chapter Offering own services. | 1375 | @chapter Offering own services |
| 1375 | @cindex method calls, returning | 1376 | @cindex method calls, returning |
| 1376 | @cindex returning method calls | 1377 | @cindex returning method calls |
| 1377 | 1378 | ||
| @@ -1722,7 +1723,7 @@ to the service from D-Bus. | |||
| 1722 | 1723 | ||
| 1723 | 1724 | ||
| 1724 | @node Signals | 1725 | @node Signals |
| 1725 | @chapter Sending and receiving signals. | 1726 | @chapter Sending and receiving signals |
| 1726 | @cindex signals | 1727 | @cindex signals |
| 1727 | 1728 | ||
| 1728 | Signals are one way messages. They carry input parameters, which are | 1729 | Signals are one way messages. They carry input parameters, which are |
| @@ -1859,7 +1860,7 @@ for a dummy signal, and check the result: | |||
| 1859 | 1860 | ||
| 1860 | 1861 | ||
| 1861 | @node Alternative Buses | 1862 | @node Alternative Buses |
| 1862 | @chapter Alternative buses and environments. | 1863 | @chapter Alternative buses and environments |
| 1863 | @cindex bus names | 1864 | @cindex bus names |
| 1864 | @cindex UNIX domain socket | 1865 | @cindex UNIX domain socket |
| 1865 | @cindex TCP/IP socket | 1866 | @cindex TCP/IP socket |
| @@ -1986,7 +1987,7 @@ running. This could be achieved by | |||
| 1986 | 1987 | ||
| 1987 | 1988 | ||
| 1988 | @node Errors and Events | 1989 | @node Errors and Events |
| 1989 | @chapter Errors and events. | 1990 | @chapter Errors and events |
| 1990 | @cindex debugging | 1991 | @cindex debugging |
| 1991 | @cindex errors | 1992 | @cindex errors |
| 1992 | @cindex events | 1993 | @cindex events |
| @@ -2145,7 +2146,7 @@ whether a given D-Bus error is related to them. | |||
| 2145 | 2146 | ||
| 2146 | 2147 | ||
| 2147 | @node Monitoring Messages | 2148 | @node Monitoring Messages |
| 2148 | @chapter Monitoring messages. | 2149 | @chapter Monitoring messages |
| 2149 | @cindex monitoring | 2150 | @cindex monitoring |
| 2150 | 2151 | ||
| 2151 | @defun dbus-register-monitor bus &optional handler &key type sender destination path interface member | 2152 | @defun dbus-register-monitor bus &optional handler &key type sender destination path interface member |
| @@ -2204,6 +2205,111 @@ switches to the monitor buffer. | |||
| 2204 | @end deffn | 2205 | @end deffn |
| 2205 | 2206 | ||
| 2206 | 2207 | ||
| 2208 | @node Inhibitor Locks | ||
| 2209 | @chapter Inhibit system shutdowns and sleep states | ||
| 2210 | |||
| 2211 | @uref{https://systemd.io/INHIBITOR_LOCKS/, Systemd} includes a logic to | ||
| 2212 | inhibit system shutdowns and sleep states. It can be controlled by a | ||
| 2213 | D-Bus API@footnote{@uref{https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.login1.html}}. | ||
| 2214 | Because this API includes handling of file descriptors, not all | ||
| 2215 | functions can be implemented by simple D-Bus method calls. Therefore, | ||
| 2216 | the following functions are provided. | ||
| 2217 | |||
| 2218 | @defun dbus-make-inhibitor-lock what why &optional block | ||
| 2219 | This function creates an inhibitor for system shutdowns and sleep states. | ||
| 2220 | |||
| 2221 | @var{what} is a colon-separated string of lock types: @samp{shutdown}, | ||
| 2222 | @samp{sleep}, @samp{idle}, @samp{handle-power-key}, | ||
| 2223 | @samp{handle-suspend-key}, @samp{handle-hibernate-key}, | ||
| 2224 | @samp{handle-lid-switch}. Example: @samp{shutdown:idle}. | ||
| 2225 | |||
| 2226 | @c@var{who} is a descriptive string of who is taking the lock. If it is | ||
| 2227 | @c@code{nil}, it defaults to @samp{Emacs}. | ||
| 2228 | |||
| 2229 | @var{why} is a descriptive string of why the lock is taken. Example: | ||
| 2230 | @samp{Package Update in Progress}. | ||
| 2231 | |||
| 2232 | The optional @var{block} is the mode of the inhibitor lock, either | ||
| 2233 | @samp{block} (@var{block} is non-@code{nil}), or @samp{delay}. | ||
| 2234 | |||
| 2235 | Note, that the @code{who} argument of the inhibitor lock object of the | ||
| 2236 | systemd manager is always set to the string @samp{Emacs}. | ||
| 2237 | |||
| 2238 | It returns a file descriptor or @code{nil}, if the lock cannot be | ||
| 2239 | acquired. If there is already an inhibitor lock for the triple | ||
| 2240 | @code{(WHAT WHY BLOCK)}, this lock is returned. Example: | ||
| 2241 | |||
| 2242 | @lisp | ||
| 2243 | (dbus-make-inhibitor-lock "sleep" "Test") | ||
| 2244 | |||
| 2245 | @result{} 25 | ||
| 2246 | @end lisp | ||
| 2247 | @end defun | ||
| 2248 | |||
| 2249 | @defun dbus-registered-inhibitor-locks | ||
| 2250 | Return registered inhibitor locks, an alist. | ||
| 2251 | This allows to check, whether other packages of the running Emacs | ||
| 2252 | instance have acquired an inhibitor lock as well. | ||
| 2253 | |||
| 2254 | An entry in this list is a list @code{(@var{fd} @var{what} @var{why} | ||
| 2255 | @var{block})}. The car of the list is the file descriptor retrieved | ||
| 2256 | from a @code{dbus-make-inhibitor-lock} call. The cdr of the list | ||
| 2257 | represents the three arguments @code{dbus-make-inhibitor-lock} was | ||
| 2258 | called with. Example: | ||
| 2259 | |||
| 2260 | @lisp | ||
| 2261 | (dbus-registered-inhibitor-locks) | ||
| 2262 | |||
| 2263 | @result{} ((25 "sleep" "Test" nil)) | ||
| 2264 | @end lisp | ||
| 2265 | @end defun | ||
| 2266 | |||
| 2267 | @defun dbus-close-inhibitor-lock lock | ||
| 2268 | Close inhibitor lock file descriptor. | ||
| 2269 | |||
| 2270 | @var{lock}, a file descriptor, must be the result of a | ||
| 2271 | @code{dbus-make-inhibitor-lock} call. It returns @code{t} in case of | ||
| 2272 | success, or @code{nil} if it isn't be possible to close the lock, or if | ||
| 2273 | the lock is closed already. Example: | ||
| 2274 | |||
| 2275 | @lisp | ||
| 2276 | (dbus-close-inhibitor-lock 25) | ||
| 2277 | |||
| 2278 | @result{} t | ||
| 2279 | |||
| 2280 | @end lisp | ||
| 2281 | @end defun | ||
| 2282 | |||
| 2283 | A typical scenario for these functions is to register for the | ||
| 2284 | D-Bus signal @samp{org.freedesktop.login1.Manager.PrepareForSleep}: | ||
| 2285 | |||
| 2286 | @lisp | ||
| 2287 | (defvar my-inhibitor-lock | ||
| 2288 | (dbus-make-inhibitor-lock "sleep" "Test")) | ||
| 2289 | |||
| 2290 | (defun my-dbus-PrepareForSleep-handler (start) | ||
| 2291 | (if start ;; The system goes down for sleep | ||
| 2292 | (progn | ||
| 2293 | @dots{} | ||
| 2294 | ;; Release inhibitor lock. | ||
| 2295 | (when (natnump my-inhibitor-lock) | ||
| 2296 | (dbus-close-inhibitor-lock my-inhibitor-lock) | ||
| 2297 | (setq my-inhibitor-lock nil))) | ||
| 2298 | ;; Reacquire inhibitor lock. | ||
| 2299 | (setq my-inhibitor-lock | ||
| 2300 | (dbus-make-inhibitor-lock "sleep" "Test")))) | ||
| 2301 | |||
| 2302 | (dbus-register-signal | ||
| 2303 | :system "org.freedesktop.login1" "/org/freedesktop/login1/Manager" | ||
| 2304 | "org.freedesktop.login1.Manager" "PrepareForSleep" | ||
| 2305 | #'my-dbus-PrepareForSleep-handler) | ||
| 2306 | |||
| 2307 | @result{} ((:signal :system "org.freedesktop.login1.Manager" "PrepareForSleep") | ||
| 2308 | ("org.freedesktop.login1" "/org/freedesktop/login1/Manager" | ||
| 2309 | my-dbus-PrepareForSleep-handler)) | ||
| 2310 | @end lisp | ||
| 2311 | |||
| 2312 | |||
| 2207 | @node Index | 2313 | @node Index |
| 2208 | @unnumbered Index | 2314 | @unnumbered Index |
| 2209 | 2315 | ||