22
33#include <unistd.h>
44
5+ #include "sd-messages.h"
6+
57#include "alloc-util.h"
68#include "bus-error.h"
79#include "bus-util.h"
1113#include "logind-dbus.h"
1214#include "logind-session-dbus.h"
1315#include "process-util.h"
14- #include "sleep-config.h"
1516#include "special.h"
1617#include "string-table.h"
1718#include "terminal-util.h"
1819#include "user-util.h"
1920
21+ static const ActionTableItem action_table [_HANDLE_ACTION_MAX ] = {
22+ [HANDLE_POWEROFF ] = {
23+ SPECIAL_POWEROFF_TARGET ,
24+ INHIBIT_SHUTDOWN ,
25+ "org.freedesktop.login1.power-off" ,
26+ "org.freedesktop.login1.power-off-multiple-sessions" ,
27+ "org.freedesktop.login1.power-off-ignore-inhibit" ,
28+ _SLEEP_OPERATION_INVALID ,
29+ SD_MESSAGE_SHUTDOWN_STR ,
30+ "System is powering down" ,
31+ "power-off" ,
32+ },
33+ [HANDLE_REBOOT ] = {
34+ SPECIAL_REBOOT_TARGET ,
35+ INHIBIT_SHUTDOWN ,
36+ "org.freedesktop.login1.reboot" ,
37+ "org.freedesktop.login1.reboot-multiple-sessions" ,
38+ "org.freedesktop.login1.reboot-ignore-inhibit" ,
39+ _SLEEP_OPERATION_INVALID ,
40+ SD_MESSAGE_SHUTDOWN_STR ,
41+ "System is rebooting" ,
42+ "reboot" ,
43+ },
44+ [HANDLE_HALT ] = {
45+ SPECIAL_HALT_TARGET ,
46+ INHIBIT_SHUTDOWN ,
47+ "org.freedesktop.login1.halt" ,
48+ "org.freedesktop.login1.halt-multiple-sessions" ,
49+ "org.freedesktop.login1.halt-ignore-inhibit" ,
50+ _SLEEP_OPERATION_INVALID ,
51+ SD_MESSAGE_SHUTDOWN_STR ,
52+ "System is halting" ,
53+ "halt" ,
54+ },
55+ [HANDLE_KEXEC ] = {
56+ SPECIAL_KEXEC_TARGET ,
57+ INHIBIT_SHUTDOWN ,
58+ "org.freedesktop.login1.reboot" ,
59+ "org.freedesktop.login1.reboot-multiple-sessions" ,
60+ "org.freedesktop.login1.reboot-ignore-inhibit" ,
61+ _SLEEP_OPERATION_INVALID ,
62+ SD_MESSAGE_SHUTDOWN_STR ,
63+ "System is rebooting with kexec" ,
64+ "kexec" ,
65+ },
66+ [HANDLE_SUSPEND ] = {
67+ SPECIAL_SUSPEND_TARGET ,
68+ INHIBIT_SLEEP ,
69+ "org.freedesktop.login1.suspend" ,
70+ "org.freedesktop.login1.suspend-multiple-sessions" ,
71+ "org.freedesktop.login1.suspend-ignore-inhibit" ,
72+ SLEEP_SUSPEND ,
73+ },
74+ [HANDLE_HIBERNATE ] = {
75+ SPECIAL_HIBERNATE_TARGET ,
76+ INHIBIT_SLEEP ,
77+ "org.freedesktop.login1.hibernate" ,
78+ "org.freedesktop.login1.hibernate-multiple-sessions" ,
79+ "org.freedesktop.login1.hibernate-ignore-inhibit" ,
80+ SLEEP_HIBERNATE ,
81+ },
82+ [HANDLE_HYBRID_SLEEP ] = {
83+ SPECIAL_HYBRID_SLEEP_TARGET ,
84+ INHIBIT_SLEEP ,
85+ "org.freedesktop.login1.hibernate" ,
86+ "org.freedesktop.login1.hibernate-multiple-sessions" ,
87+ "org.freedesktop.login1.hibernate-ignore-inhibit" ,
88+ SLEEP_HYBRID_SLEEP ,
89+ },
90+ [HANDLE_SUSPEND_THEN_HIBERNATE ] = {
91+ SPECIAL_SUSPEND_THEN_HIBERNATE_TARGET ,
92+ INHIBIT_SLEEP ,
93+ "org.freedesktop.login1.hibernate" ,
94+ "org.freedesktop.login1.hibernate-multiple-sessions" ,
95+ "org.freedesktop.login1.hibernate-ignore-inhibit" ,
96+ SLEEP_SUSPEND_THEN_HIBERNATE ,
97+ },
98+ [HANDLE_FACTORY_RESET ] = {
99+ SPECIAL_FACTORY_RESET_TARGET ,
100+ _INHIBIT_WHAT_INVALID ,
101+ NULL ,
102+ NULL ,
103+ NULL ,
104+ _SLEEP_OPERATION_INVALID ,
105+ SD_MESSAGE_FACTORY_RESET_STR ,
106+ "System is performing factory reset" ,
107+ NULL
108+ },
109+ };
110+
20111const char * manager_target_for_action (HandleAction handle ) {
21- static const char * const target_table [_HANDLE_ACTION_MAX ] = {
22- [HANDLE_POWEROFF ] = SPECIAL_POWEROFF_TARGET ,
23- [HANDLE_REBOOT ] = SPECIAL_REBOOT_TARGET ,
24- [HANDLE_HALT ] = SPECIAL_HALT_TARGET ,
25- [HANDLE_KEXEC ] = SPECIAL_KEXEC_TARGET ,
26- [HANDLE_SUSPEND ] = SPECIAL_SUSPEND_TARGET ,
27- [HANDLE_HIBERNATE ] = SPECIAL_HIBERNATE_TARGET ,
28- [HANDLE_HYBRID_SLEEP ] = SPECIAL_HYBRID_SLEEP_TARGET ,
29- [HANDLE_SUSPEND_THEN_HIBERNATE ] = SPECIAL_SUSPEND_THEN_HIBERNATE_TARGET ,
30- [HANDLE_FACTORY_RESET ] = SPECIAL_FACTORY_RESET_TARGET ,
31- };
112+ assert (handle >= 0 );
113+ assert (handle < (ssize_t ) ELEMENTSOF (action_table ));
32114
115+ return action_table [handle ].target ;
116+ }
117+
118+ const ActionTableItem * manager_item_for_handle (HandleAction handle ) {
33119 assert (handle >= 0 );
34- if (handle < (ssize_t ) ELEMENTSOF (target_table ))
35- return target_table [handle ];
36- return NULL ;
120+ assert (handle < (ssize_t ) ELEMENTSOF (action_table ));
121+
122+ return & action_table [handle ];
123+ }
124+
125+ HandleAction manager_handle_for_item (const ActionTableItem * a ) {
126+ if (a && a < action_table + ELEMENTSOF (action_table ))
127+ return a - action_table ;
128+ return _HANDLE_ACTION_INVALID ;
37129}
38130
39131int manager_handle_action (
@@ -59,7 +151,6 @@ int manager_handle_action(
59151 InhibitWhat inhibit_operation ;
60152 Inhibitor * offending = NULL ;
61153 bool supported ;
62- const char * target ;
63154 int r ;
64155
65156 assert (m );
@@ -129,17 +220,13 @@ int manager_handle_action(
129220 return log_warning_errno (SYNTHETIC_ERRNO (EOPNOTSUPP ),
130221 "Requested %s operation not supported, ignoring." , handle_action_to_string (handle ));
131222
132- if (m -> action_what > 0 )
223+ if (m -> delayed_action )
133224 return log_debug_errno (SYNTHETIC_ERRNO (EALREADY ),
134225 "Action already in progress (%s), ignoring requested %s operation." ,
135- inhibit_what_to_string (m -> action_what ),
226+ inhibit_what_to_string (m -> delayed_action -> inhibit_what ),
136227 handle_action_to_string (handle ));
137228
138- assert_se (target = manager_target_for_action (handle ));
139-
140- inhibit_operation = IN_SET (handle , HANDLE_SUSPEND , HANDLE_HIBERNATE ,
141- HANDLE_HYBRID_SLEEP ,
142- HANDLE_SUSPEND_THEN_HIBERNATE ) ? INHIBIT_SLEEP : INHIBIT_SHUTDOWN ;
229+ inhibit_operation = manager_item_for_handle (handle )-> inhibit_what ;
143230
144231 /* If the actual operation is inhibited, warn and fail */
145232 if (!ignore_inhibited &&
@@ -162,7 +249,7 @@ int manager_handle_action(
162249
163250 log_info ("%s" , message_table [handle ]);
164251
165- r = bus_manager_shutdown_or_sleep_now_or_later (m , target , inhibit_operation , & error );
252+ r = bus_manager_shutdown_or_sleep_now_or_later (m , manager_item_for_handle ( handle ) , & error );
166253 if (r < 0 )
167254 return log_error_errno (r , "Failed to execute %s operation: %s" ,
168255 handle_action_to_string (handle ),
0 commit comments