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
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"])
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
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
37 #include <dbus/dbus-glib.h>
38 #include <dbus/dbus-glib-lowlevel.h>
40 +#if (defined(sun) && defined(__SVR4))
41 +#include <libscf_priv.h>
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,
58 DBusGMethodInvocation *context;
59 AuthorizedCallback callback;
61 } AuthorizedCallbackData;
64 @@ -799,7 +805,7 @@ auth_ready_callback (PolkitAuthority
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,
77 - AuthorizedCallback callback)
78 + AuthorizedCallback callback,
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;
89 polkit_authority_check_authorization (manager->priv->pol_ctx,
91 @@ -1048,7 +1056,8 @@ static gboolean
92 check_rbac_permissions (CkManager *manager,
93 DBusGMethodInvocation *context,
95 - AuthorizedCallback callback)
96 + AuthorizedCallback callback,
101 @@ -1085,7 +1094,7 @@ out:
104 if (res && callback) {
105 - callback (manager, context);
106 + callback (manager, context, arg);
110 @@ -1094,7 +1103,8 @@ out:
113 do_restart (CkManager *manager,
114 - DBusGMethodInvocation *context)
115 + DBusGMethodInvocation *context,
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,
131 g_warning ("Compiled without PolicyKit or RBAC support!");
133 @@ -1168,7 +1179,7 @@ ck_manager_can_restart (CkManager *mana
134 get_polkit_permissions (manager, action, context);
136 if (check_rbac_permissions (manager, context, RBAC_SHUTDOWN_KEY,
139 dbus_g_method_return (context, TRUE);
141 dbus_g_method_return (context, FALSE);
142 @@ -1180,7 +1191,8 @@ ck_manager_can_restart (CkManager *mana
145 do_stop (CkManager *manager,
146 - DBusGMethodInvocation *context)
147 + DBusGMethodInvocation *context,
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,
163 g_warning ("Compiled without PolicyKit or RBAC support!");
165 @@ -1243,7 +1256,7 @@ ck_manager_can_stop (CkManager *manager
166 get_polkit_permissions (manager, action, context);
168 if (check_rbac_permissions (manager, context, RBAC_SHUTDOWN_KEY,
171 dbus_g_method_return (context, TRUE);
173 dbus_g_method_return (context, FALSE);
174 @@ -1253,6 +1266,218 @@ ck_manager_can_stop (CkManager *manager
178 +#define OS_STRUCT_TYPE (dbus_g_type_get_struct ("GValueArray", \
186 +#if (defined(sun) && defined(__SVR4))
188 +parse_output (const gchar *output, GPtrArray **systems)
191 + gint default_id = -1;
193 + if (output == NULL)
196 + lines = g_strsplit (output, "\n", 0);
197 + for (int i = 0; lines[i] != NULL; i++) {
200 + if (i == 0 || i == 2) {
201 + /* We do not care 1st & 2nd line. */
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);
211 + } else if (lines[i][0] != NULL && systems) {
212 + /* boot menu entries */
215 + index = strchr (lines[i], ' ');
216 + if (index && (index + 1)) {
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,
229 + 4, (default_id == id),
231 + g_ptr_array_add (*systems,
232 + g_value_get_boxed (&elem));
238 + g_strfreev (lines);
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;
253 + g_spawn_sync (NULL, cmd, NULL,
254 + G_SPAWN_STDERR_TO_DEV_NULL, NULL,
255 + NULL, &output, NULL,
258 + g_error_free (err);
263 + ret = parse_output (output, systems);
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
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);
290 + dbus_g_method_return (context, systems);
295 +#if (defined(sun) && defined(__SVR4))
297 +set_default_boot_entry (CkManager *manager,
299 + DBusGMethodInvocation *context)
303 + default_id = get_available_boot_environment (manager, NULL, context);
304 + if (default_id != id) {
307 + g_debug ("Set default boot entry from %d to %d",
309 + cmd = g_strdup_printf ("/usr/sbin/bootadm set-menu default=%d",
311 + if (g_spawn_command_line_async (cmd, NULL) == FALSE) {
312 + g_warning ("Unable to set default boot entry");
320 +do_restart_with_parameters (CkManager *manager,
321 + DBusGMethodInvocation *context,
324 +#if (defined(sun) && defined(__SVR4))
327 + if (parameters == NULL)
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])) {
336 + id = atoi (¶m[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])) {
344 + val = atoi (¶m[i][5]);
346 + scf_fastreboot_default_set_transient (1);
348 + scf_fastreboot_default_set_transient (0);
353 + g_strfreev (param);
355 + do_restart (manager, context, NULL);
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"
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";
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);
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
412 <arg name="can_stop" type="b" direction="out"/>
415 + <method name="GetAvailableOperatingSystems">
416 + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
417 + <arg name="systems" direction="out" type="a(isssb)">
419 + <doc:summary>An array of available operating systems</doc:summary>
424 + <doc:para>This method returns an array of available operating systems.</doc:para>
429 + <method name="RestartWithParameters">
430 + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
431 + <arg name="parameters" direction="in" type="s">
433 + <doc:summary>The parameeters used to restart.</doc:summary>
438 + <doc:para>This method initiates a request to restart (ie. reboot) with system specific parameters.</doc:para>
443 <method name="OpenSession">
444 <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
445 <arg name="cookie" direction="out" type="s">