shared-macros.mk: simplify java settings
[oi-userland.git] / components / library / ConsoleKit / patches / 09-fastreboot.patch
blobf98eb3efecdd72a3ef50a821384d56087798f211
1 diff -uprN ConsoleKit-0.4.1-backup/configure.ac ConsoleKit-0.4.1/configure.ac
2 --- ConsoleKit-0.4.1-backup/configure.ac 2009-11-10 15:28:55.524301156 +0800
3 +++ ConsoleKit-0.4.1/configure.ac 2009-11-10 15:31:24.985394958 +0800
4 @@ -81,10 +81,10 @@ AC_PATH_PROG(GLIB_GENMARSHAL, glib-genma
6 EXTRA_COMPILE_WARNINGS(yes)
8 -# Solaris requires libresolv for daemon()
9 +# Solaris requires libscf
10 case "$host" in
11 *-*-solaris*)
12 - AC_CHECK_LIB(resolv, daemon, [CONSOLE_KIT_LIBS="$CONSOLE_KIT_LIBS -lresolv"])
13 + AC_CHECK_LIB(scf, daemon, [CONSOLE_KIT_LIBS="$CONSOLE_KIT_LIBS -lscf"])
15 esac
17 diff -uprN ConsoleKit-0.4.1-backup/data/ConsoleKit.conf ConsoleKit-0.4.1/data/ConsoleKit.conf
18 --- ConsoleKit-0.4.1-backup/data/ConsoleKit.conf 2009-11-10 15:28:55.525135254 +0800
19 +++ ConsoleKit-0.4.1/data/ConsoleKit.conf 2009-11-10 15:31:24.985644376 +0800
20 @@ -38,6 +38,12 @@
21 send_member="CanStop"/>
22 <allow send_destination="org.freedesktop.ConsoleKit"
23 send_interface="org.freedesktop.ConsoleKit.Manager"
24 + send_member="GetAvailableOperatingSystems"/>
25 + <allow send_destination="org.freedesktop.ConsoleKit"
26 + send_interface="org.freedesktop.ConsoleKit.Manager"
27 + send_member="RestartWithParameters"/>
28 + <allow send_destination="org.freedesktop.ConsoleKit"
29 + send_interface="org.freedesktop.ConsoleKit.Manager"
30 send_member="OpenSession"/>
31 <allow send_destination="org.freedesktop.ConsoleKit"
32 send_interface="org.freedesktop.ConsoleKit.Manager"
33 diff -uprN ConsoleKit-0.4.1-backup/src/ck-manager.c ConsoleKit-0.4.1/src/ck-manager.c
34 --- ConsoleKit-0.4.1-backup/src/ck-manager.c 2009-11-10 15:28:55.561041146 +0800
35 +++ ConsoleKit-0.4.1/src/ck-manager.c 2009-11-10 15:32:06.905204994 +0800
36 @@ -39,6 +39,10 @@
37 #include <dbus/dbus-glib.h>
38 #include <dbus/dbus-glib-lowlevel.h>
40 +#if (defined(sun) && defined(__SVR4))
41 +#include <libscf_priv.h>
42 +#endif
44 #if defined HAVE_POLKIT
45 #include <polkit/polkit.h>
46 #elif defined ENABLE_RBAC_SHUTDOWN
47 @@ -759,13 +763,15 @@ get_cookie_for_pid (CkManager *manager,
50 typedef void (*AuthorizedCallback) (CkManager *manager,
51 - DBusGMethodInvocation *context);
52 + DBusGMethodInvocation *context,
53 + void *arg);
55 typedef struct
57 CkManager *manager;
58 DBusGMethodInvocation *context;
59 AuthorizedCallback callback;
60 + void *arg;
61 } AuthorizedCallbackData;
63 static void
64 @@ -799,7 +805,7 @@ auth_ready_callback (PolkitAuthority
65 g_error_free (error);
67 else if (polkit_authorization_result_get_is_authorized (result)) {
68 - data->callback (data->manager, data->context);
69 + data->callback (data->manager, data->context, data->arg);
71 else if (polkit_authorization_result_get_is_challenge (result)) {
72 error = g_error_new (CK_MANAGER_ERROR,
73 @@ -825,7 +831,8 @@ static void
74 check_polkit_permissions (CkManager *manager,
75 DBusGMethodInvocation *context,
76 const char *action,
77 - AuthorizedCallback callback)
78 + AuthorizedCallback callback,
79 + void *arg)
81 const char *sender;
82 PolkitSubject *subject;
83 @@ -843,6 +850,7 @@ check_polkit_permissions (CkManager
84 data->manager = g_object_ref (manager);
85 data->context = context;
86 data->callback = callback;
87 + data->arg = arg;
89 polkit_authority_check_authorization (manager->priv->pol_ctx,
90 subject,
91 @@ -1048,7 +1056,8 @@ static gboolean
92 check_rbac_permissions (CkManager *manager,
93 DBusGMethodInvocation *context,
94 const char *action,
95 - AuthorizedCallback callback)
96 + AuthorizedCallback callback,
97 + void *arg)
99 const char *sender;
100 char *username;
101 @@ -1085,7 +1094,7 @@ out:
102 g_free (username);
104 if (res && callback) {
105 - callback (manager, context);
106 + callback (manager, context, arg);
109 return res;
110 @@ -1094,7 +1103,8 @@ out:
112 static void
113 do_restart (CkManager *manager,
114 - DBusGMethodInvocation *context)
115 + DBusGMethodInvocation *context,
116 + void *arg)
118 GError *error;
119 gboolean res;
120 @@ -1145,9 +1155,10 @@ ck_manager_restart (CkManager
121 g_debug ("ConsoleKit Restart: %s", action);
123 #if defined HAVE_POLKIT
124 - check_polkit_permissions (manager, context, action, do_restart);
125 + check_polkit_permissions (manager, context, action, do_restart, NULL);
126 #elif defined ENABLE_RBAC_SHUTDOWN
127 - check_rbac_permissions (manager, context, RBAC_SHUTDOWN_KEY, do_restart);
128 + check_rbac_permissions (manager, context, RBAC_SHUTDOWN_KEY, do_restart,
129 + NULL);
130 #else
131 g_warning ("Compiled without PolicyKit or RBAC support!");
132 #endif
133 @@ -1168,7 +1179,7 @@ ck_manager_can_restart (CkManager *mana
134 get_polkit_permissions (manager, action, context);
135 #else
136 if (check_rbac_permissions (manager, context, RBAC_SHUTDOWN_KEY,
137 - NULL)) {
138 + NULL, NULL)) {
139 dbus_g_method_return (context, TRUE);
140 } else {
141 dbus_g_method_return (context, FALSE);
142 @@ -1180,7 +1191,8 @@ ck_manager_can_restart (CkManager *mana
144 static void
145 do_stop (CkManager *manager,
146 - DBusGMethodInvocation *context)
147 + DBusGMethodInvocation *context,
148 + void *arg)
150 GError *error;
151 gboolean res;
152 @@ -1221,9 +1233,10 @@ ck_manager_stop (CkManager *
155 #if defined HAVE_POLKIT
156 - check_polkit_permissions (manager, context, action, do_stop);
157 + check_polkit_permissions (manager, context, action, do_stop, NULL);
158 #elif defined ENABLE_RBAC_SHUTDOWN
159 - check_rbac_permissions (manager, context, RBAC_SHUTDOWN_KEY, do_stop);
160 + check_rbac_permissions (manager, context, RBAC_SHUTDOWN_KEY, do_stop,
161 + NULL);
162 #else
163 g_warning ("Compiled without PolicyKit or RBAC support!");
164 #endif
165 @@ -1243,7 +1256,7 @@ ck_manager_can_stop (CkManager *manager
166 get_polkit_permissions (manager, action, context);
167 #else
168 if (check_rbac_permissions (manager, context, RBAC_SHUTDOWN_KEY,
169 - NULL)) {
170 + NULL, NULL)) {
171 dbus_g_method_return (context, TRUE);
172 } else {
173 dbus_g_method_return (context, FALSE);
174 @@ -1253,6 +1266,218 @@ ck_manager_can_stop (CkManager *manager
175 return TRUE;
178 +#define OS_STRUCT_TYPE (dbus_g_type_get_struct ("GValueArray", \
179 + G_TYPE_INT, \
180 + G_TYPE_STRING, \
181 + G_TYPE_STRING, \
182 + G_TYPE_STRING, \
183 + G_TYPE_BOOLEAN, \
184 + G_TYPE_INVALID))
186 +#if (defined(sun) && defined(__SVR4))
187 +static gint
188 +parse_output (const gchar *output, GPtrArray **systems)
190 + gchar **lines;
191 + gint default_id = -1;
193 + if (output == NULL)
194 + return default_id;
196 + lines = g_strsplit (output, "\n", 0);
197 + for (int i = 0; lines[i] != NULL; i++) {
198 + gchar *index;
200 + if (i == 0 || i == 2) {
201 + /* We do not care 1st & 2nd line. */
202 + continue;
203 + } else if (i == 1) {
204 + /* default boot menu entry */
205 + index = strchr (lines[i], ' ');
206 + if (index && (index + 1)) {
207 + default_id = atol (index + 1);
208 + } else {
209 + continue;
211 + } else if (lines[i][0] != NULL && systems) {
212 + /* boot menu entries */
213 + GValue elem = {0};
215 + index = strchr (lines[i], ' ');
216 + if (index && (index + 1)) {
217 + gint id;
219 + *index = '\0';
220 + id = atoi (lines[i]);
221 + g_value_init (&elem, OS_STRUCT_TYPE);
222 + g_value_take_boxed (&elem,
223 + dbus_g_type_specialized_construct (OS_STRUCT_TYPE));
224 + dbus_g_type_struct_set (&elem,
225 + 0, id,
226 + 1, "",
227 + 2, "",
228 + 3, (index + 1),
229 + 4, (default_id == id),
230 + G_MAXUINT);
231 + g_ptr_array_add (*systems,
232 + g_value_get_boxed (&elem));
233 + } else {
234 + continue;
238 + g_strfreev (lines);
239 + return default_id;
242 +static gint
243 +get_available_boot_environment (CkManager *manager,
244 + GPtrArray **systems,
245 + DBusGMethodInvocation *context)
247 + gchar *cmd[] = {"/usr/sbin/bootadm", "list-menu", NULL};
248 + gchar *output = NULL;
249 + GError *err = NULL;
250 + gint status;
251 + gint ret = -1;
253 + g_spawn_sync (NULL, cmd, NULL,
254 + G_SPAWN_STDERR_TO_DEV_NULL, NULL,
255 + NULL, &output, NULL,
256 + &status, &err);
257 + if (err) {
258 + g_error_free (err);
259 + return ret;
262 + if (status == 0) {
263 + ret = parse_output (output, systems);
265 + if (output)
266 + g_free (output);
267 + return ret;
269 +#endif
272 + Example:
273 + dbus-send --system --dest=org.freedesktop.ConsoleKit \
274 + --type=method_call --print-reply --reply-timeout=2000 \
275 + /org/freedesktop/ConsoleKit/Manager \
276 + org.freedesktop.ConsoleKit.Manager.GetAvailableOperatingSystems
278 +gboolean
279 +ck_manager_get_available_operating_systems (CkManager *manager,
280 + DBusGMethodInvocation *context)
282 + GPtrArray *systems;
284 + g_return_val_if_fail (CK_IS_MANAGER (manager), FALSE);
286 + systems = g_ptr_array_new ();
287 +#if (defined(sun) && defined(__SVR4))
288 + get_available_boot_environment (manager, &systems, context);
289 +#endif
290 + dbus_g_method_return (context, systems);
292 + return TRUE;
295 +#if (defined(sun) && defined(__SVR4))
296 +static void
297 +set_default_boot_entry (CkManager *manager,
298 + gint id,
299 + DBusGMethodInvocation *context)
301 + gint default_id;
303 + default_id = get_available_boot_environment (manager, NULL, context);
304 + if (default_id != id) {
305 + gchar *cmd;
307 + g_debug ("Set default boot entry from %d to %d",
308 + default_id, id);
309 + cmd = g_strdup_printf ("/usr/sbin/bootadm set-menu default=%d",
310 + id);
311 + if (g_spawn_command_line_async (cmd, NULL) == FALSE) {
312 + g_warning ("Unable to set default boot entry");
314 + g_free (cmd);
317 +#endif
319 +static void
320 +do_restart_with_parameters (CkManager *manager,
321 + DBusGMethodInvocation *context,
322 + void *parameters)
324 +#if (defined(sun) && defined(__SVR4))
325 + gchar **param;
327 + if (parameters == NULL)
328 + return;
330 + param = g_strsplit ((gchar*)parameters, " ", 0);
331 + for (int i = 0; param[i] != NULL; i++) {
332 + if (strncmp (param[i], "id:", 3) == 0) {
333 + if (g_ascii_isdigit(param[i][3])) {
334 + gint id;
336 + id = atoi (&param[i][3]);
337 + set_default_boot_entry (manager, id, context);
339 +#if defined(__x86__) || defined(__x86)
340 + } else if (strncmp (param[i], "fast:", 5) == 0) {
341 + if (g_ascii_isdigit(param[i][5])) {
342 + gint val;
344 + val = atoi (&param[i][5]);
345 + if (val == 1)
346 + scf_fastreboot_default_set_transient (1);
347 + else if (val == 0)
348 + scf_fastreboot_default_set_transient (0);
350 +#endif
353 + g_strfreev (param);
354 +#endif
355 + do_restart (manager, context, NULL);
359 + Example:
360 + dbus-send --system --dest=org.freedesktop.ConsoleKit \
361 + --type=method_call --print-reply --reply-timeout=2000 \
362 + /org/freedesktop/ConsoleKit/Manager \
363 + org.freedesktop.ConsoleKit.Manager.RestartWithParameters \
364 + string:"id:0 fast:1"
366 +gboolean
367 +ck_manager_restart_with_parameters (CkManager *manager,
368 + const gchar *parameters,
369 + DBusGMethodInvocation *context)
371 + const char *action;
373 + g_return_val_if_fail (CK_IS_MANAGER (manager), FALSE);
375 +#if defined HAVE_POLKIT
376 + if (get_system_num_users (manager) > 1) {
377 + action = "org.freedesktop.consolekit.system.restart-multiple-users";
378 + } else {
379 + action = "org.freedesktop.consolekit.system.restart";
381 + check_polkit_permissions (manager, context, action,
382 + do_restart_with_parameters, (void *)parameters);
383 +#elif defined ENABLE_RBAC_SHUTDOWN
384 + check_rbac_permissions (manager, context, RBAC_SHUTDOWN_KEY,
385 + do_restart_with_parameters, (void *)parameters);
386 +#endif
387 + return TRUE;
390 static void
391 on_seat_active_session_changed_full (CkSeat *seat,
392 CkSession *old_session,
393 diff -uprN ConsoleKit-0.4.1-backup/src/ck-manager.h ConsoleKit-0.4.1/src/ck-manager.h
394 --- ConsoleKit-0.4.1-backup/src/ck-manager.h 2009-11-10 15:28:55.534101649 +0800
395 +++ ConsoleKit-0.4.1/src/ck-manager.h 2009-11-10 15:31:24.987857782 +0800
396 @@ -88,6 +88,11 @@ gboolean ck_manager_can_stop
397 DBusGMethodInvocation *context);
398 gboolean ck_manager_can_restart (CkManager *manager,
399 DBusGMethodInvocation *context);
400 +gboolean ck_manager_get_available_operating_systems (CkManager *manager,
401 + DBusGMethodInvocation *context);
402 +gboolean ck_manager_restart_with_parameters (CkManager *manager,
403 + const gchar *parameters,
404 + DBusGMethodInvocation *context);
405 /* Authoritative properties */
406 gboolean ck_manager_open_session (CkManager *manager,
407 DBusGMethodInvocation *context);
408 diff -uprN ConsoleKit-0.4.1-backup/src/org.freedesktop.ConsoleKit.Manager.xml ConsoleKit-0.4.1/src/org.freedesktop.ConsoleKit.Manager.xml
409 --- ConsoleKit-0.4.1-backup/src/org.freedesktop.ConsoleKit.Manager.xml 2009-11-10 15:28:55.540314508 +0800
410 +++ ConsoleKit-0.4.1/src/org.freedesktop.ConsoleKit.Manager.xml 2009-11-10 15:31:24.988157959 +0800
411 @@ -32,6 +32,34 @@
412 <arg name="can_stop" type="b" direction="out"/>
413 </method>
415 + <method name="GetAvailableOperatingSystems">
416 + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
417 + <arg name="systems" direction="out" type="a(isssb)">
418 + <doc:doc>
419 + <doc:summary>An array of available operating systems</doc:summary>
420 + </doc:doc>
421 + </arg>
422 + <doc:doc>
423 + <doc:description>
424 + <doc:para>This method returns an array of available operating systems.</doc:para>
425 + </doc:description>
426 + </doc:doc>
427 + </method>
429 + <method name="RestartWithParameters">
430 + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
431 + <arg name="parameters" direction="in" type="s">
432 + <doc:doc>
433 + <doc:summary>The parameeters used to restart.</doc:summary>
434 + </doc:doc>
435 + </arg>
436 + <doc:doc>
437 + <doc:description>
438 + <doc:para>This method initiates a request to restart (ie. reboot) with system specific parameters.</doc:para>
439 + </doc:description>
440 + </doc:doc>
441 + </method>
443 <method name="OpenSession">
444 <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
445 <arg name="cookie" direction="out" type="s">