Bug Summary

File:cafe-session/csm-consolekit.c
Warning:line 675, column 17
Value stored to 'res' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name csm-consolekit.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/rootdir/cafe-session -fcoverage-compilation-dir=/rootdir/cafe-session -resource-dir /usr/lib/llvm-19/lib/clang/19 -D HAVE_CONFIG_H -I . -I .. -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/uuid -I ../egg -D LOCALE_DIR="/usr/share/locale" -D DATA_DIR="/usr/share/cafe-session" -D LIBEXECDIR="/usr/libexec" -D CTKBUILDER_DIR="/usr/share/cafe-session-manager" -D I_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2025-01-24-072850-18298-1 -x c csm-consolekit.c
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2008 Jon McCann <jmccann@redhat.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301, USA.
19 */
20
21#include "config.h"
22
23#include <errno(*__errno_location ()).h>
24#include <string.h>
25#include <unistd.h>
26
27#include <glib.h>
28#include <glib-object.h>
29#include <glib/gi18n.h>
30
31#include <dbus/dbus-glib.h>
32#include <dbus/dbus-glib-lowlevel.h>
33
34#include "csm-marshal.h"
35#include "csm-consolekit.h"
36
37#define CK_NAME"org.freedesktop.ConsoleKit" "org.freedesktop.ConsoleKit"
38#define CK_PATH"/org/freedesktop/ConsoleKit" "/org/freedesktop/ConsoleKit"
39#define CK_INTERFACE"org.freedesktop.ConsoleKit" "org.freedesktop.ConsoleKit"
40
41#define CK_MANAGER_PATH"/org/freedesktop/ConsoleKit/Manager" "/org/freedesktop/ConsoleKit/Manager"
42#define CK_MANAGER_INTERFACE"org.freedesktop.ConsoleKit.Manager" "org.freedesktop.ConsoleKit.Manager"
43#define CK_SEAT_INTERFACE"org.freedesktop.ConsoleKit.Seat" "org.freedesktop.ConsoleKit.Seat"
44#define CK_SESSION_INTERFACE"org.freedesktop.ConsoleKit.Session" "org.freedesktop.ConsoleKit.Session"
45
46typedef struct
47{
48 DBusGConnection *dbus_connection;
49 DBusGProxy *bus_proxy;
50 DBusGProxy *ck_proxy;
51 guint32 is_connected : 1;
52} CsmConsolekitPrivate;
53
54enum {
55 PROP_0,
56 PROP_IS_CONNECTED
57};
58
59enum {
60 REQUEST_COMPLETED = 0,
61 PRIVILEGES_COMPLETED,
62 LAST_SIGNAL
63};
64
65static guint signals[LAST_SIGNAL] = { 0 };
66
67static void csm_consolekit_finalize (GObject *object);
68
69static void csm_consolekit_free_dbus (CsmConsolekit *manager);
70
71static DBusHandlerResult csm_consolekit_dbus_filter (DBusConnection *connection,
72 DBusMessage *message,
73 void *user_data);
74
75static void csm_consolekit_on_name_owner_changed (DBusGProxy *bus_proxy,
76 const char *name,
77 const char *prev_owner,
78 const char *new_owner,
79 CsmConsolekit *manager);
80
81G_DEFINE_TYPE_WITH_PRIVATE (CsmConsolekit, csm_consolekit, G_TYPE_OBJECT)static void csm_consolekit_init (CsmConsolekit *self); static
void csm_consolekit_class_init (CsmConsolekitClass *klass); static
GType csm_consolekit_get_type_once (void); static gpointer csm_consolekit_parent_class
= ((void*)0); static gint CsmConsolekit_private_offset; static
void csm_consolekit_class_intern_init (gpointer klass) { csm_consolekit_parent_class
= g_type_class_peek_parent (klass); if (CsmConsolekit_private_offset
!= 0) g_type_class_adjust_private_offset (klass, &CsmConsolekit_private_offset
); csm_consolekit_class_init ((CsmConsolekitClass*) klass); }
__attribute__ ((__unused__)) static inline gpointer csm_consolekit_get_instance_private
(CsmConsolekit *self) { return (((gpointer) ((guint8*) (self
) + (glong) (CsmConsolekit_private_offset)))); } GType csm_consolekit_get_type
(void) { static GType static_g_define_type_id = 0; if ((__extension__
({ _Static_assert (sizeof *(&static_g_define_type_id) ==
sizeof (gpointer), "Expression evaluates to false"); (void) (
0 ? (gpointer) * (&static_g_define_type_id) : ((void*)0))
; (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(*(&static_g_define_type_id)) gapg_temp_newval; __typeof__
((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id
); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5)
; gapg_temp_newval; })) && g_once_init_enter_pointer (
&static_g_define_type_id)); })) ) { GType g_define_type_id
= csm_consolekit_get_type_once (); (__extension__ ({ _Static_assert
(sizeof *(&static_g_define_type_id) == sizeof (gpointer)
, "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id
) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer
((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id
)); })) ; } return static_g_define_type_id; } __attribute__ (
(__noinline__)) static GType csm_consolekit_get_type_once (void
) { GType g_define_type_id = g_type_register_static_simple ((
(GType) ((20) << (2))), g_intern_static_string ("CsmConsolekit"
), sizeof (CsmConsolekitClass), (GClassInitFunc)(void (*)(void
)) csm_consolekit_class_intern_init, sizeof (CsmConsolekit), (
GInstanceInitFunc)(void (*)(void)) csm_consolekit_init, (GTypeFlags
) 0); { {{ CsmConsolekit_private_offset = g_type_add_instance_private
(g_define_type_id, sizeof (CsmConsolekitPrivate)); };} } return
g_define_type_id; }
;
82
83static void
84csm_consolekit_get_property (GObject *object,
85 guint prop_id,
86 GValue *value,
87 GParamSpec *pspec)
88{
89 CsmConsolekit *manager = CSM_CONSOLEKIT (object);
90 CsmConsolekitPrivate *priv;
91
92 priv = csm_consolekit_get_instance_private (manager);
93
94 switch (prop_id) {
95 case PROP_IS_CONNECTED:
96 g_value_set_boolean (value,
97 priv->is_connected);
98 break;
99
100 default:
101 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,do { GObject *_glib__object = (GObject*) ((object)); GParamSpec
*_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id
= ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'"
, "csm-consolekit.c", 103, ("property"), _glib__property_id, _glib__pspec
->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) (
_glib__pspec))->g_class))->g_type)))), (g_type_name (((
(((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class
))->g_type)))))); } while (0)
102 prop_id,do { GObject *_glib__object = (GObject*) ((object)); GParamSpec
*_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id
= ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'"
, "csm-consolekit.c", 103, ("property"), _glib__property_id, _glib__pspec
->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) (
_glib__pspec))->g_class))->g_type)))), (g_type_name (((
(((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class
))->g_type)))))); } while (0)
103 pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec
*_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id
= ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'"
, "csm-consolekit.c", 103, ("property"), _glib__property_id, _glib__pspec
->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) (
_glib__pspec))->g_class))->g_type)))), (g_type_name (((
(((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class
))->g_type)))))); } while (0)
;
104 }
105}
106
107static void
108csm_consolekit_class_init (CsmConsolekitClass *manager_class)
109{
110 GObjectClass *object_class;
111 GParamSpec *param_spec;
112
113 object_class = G_OBJECT_CLASS (manager_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((manager_class)), (((GType) ((20) << (2))))))))
;
114
115 object_class->finalize = csm_consolekit_finalize;
116 object_class->get_property = csm_consolekit_get_property;
117
118 param_spec = g_param_spec_boolean ("is-connected",
119 "Is connected",
120 "Whether the session is connected to ConsoleKit",
121 FALSE(0),
122 G_PARAM_READABLE);
123
124 g_object_class_install_property (object_class, PROP_IS_CONNECTED,
125 param_spec);
126
127 signals [REQUEST_COMPLETED] =
128 g_signal_new ("request-completed",
129 G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)),
130 G_SIGNAL_RUN_LAST,
131 G_STRUCT_OFFSET (CsmConsolekitClass, request_completed)((glong) __builtin_offsetof(CsmConsolekitClass, request_completed
))
,
132 NULL((void*)0),
133 NULL((void*)0),
134 g_cclosure_marshal_VOID__POINTER,
135 G_TYPE_NONE((GType) ((1) << (2))),
136 1, G_TYPE_POINTER((GType) ((17) << (2))));
137
138 signals [PRIVILEGES_COMPLETED] =
139 g_signal_new ("privileges-completed",
140 G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)),
141 G_SIGNAL_RUN_LAST,
142 G_STRUCT_OFFSET (CsmConsolekitClass, privileges_completed)((glong) __builtin_offsetof(CsmConsolekitClass, privileges_completed
))
,
143 NULL((void*)0),
144 NULL((void*)0),
145 csm_marshal_VOID__BOOLEAN_BOOLEAN_POINTER,
146 G_TYPE_NONE((GType) ((1) << (2))),
147 3, G_TYPE_BOOLEAN((GType) ((5) << (2))), G_TYPE_BOOLEAN((GType) ((5) << (2))), G_TYPE_POINTER((GType) ((17) << (2))));
148
149}
150
151static DBusHandlerResult
152csm_consolekit_dbus_filter (DBusConnection *connection,
153 DBusMessage *message,
154 void *user_data)
155{
156 CsmConsolekit *manager;
157
158 manager = CSM_CONSOLEKIT (user_data);
159
160 if (dbus_message_is_signal (message,
161 DBUS_INTERFACE_LOCAL"org.freedesktop.DBus.Local", "Disconnected") &&
162 strcmp (dbus_message_get_path (message), DBUS_PATH_LOCAL"/org/freedesktop/DBus/Local") == 0) {
163 csm_consolekit_free_dbus (manager);
164 /* let other filters get this disconnected signal, so that they
165 * can handle it too */
166 }
167
168 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
169}
170
171static gboolean
172csm_consolekit_ensure_ck_connection (CsmConsolekit *manager,
173 GError **error)
174{
175 GError *connection_error;
176 gboolean is_connected;
177 CsmConsolekitPrivate *priv;
178
179 connection_error = NULL((void*)0);
180 priv = csm_consolekit_get_instance_private (manager);
181
182 if (priv->dbus_connection == NULL((void*)0)) {
183 DBusConnection *connection;
184
185 priv->dbus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM,
186 &connection_error);
187
188 if (priv->dbus_connection == NULL((void*)0)) {
189 g_propagate_error (error, connection_error);
190 is_connected = FALSE(0);
191 goto out;
192 }
193
194 connection = dbus_g_connection_get_connection (priv->dbus_connection);
195 dbus_connection_set_exit_on_disconnect (connection, FALSE(0));
196 dbus_connection_add_filter (connection,
197 csm_consolekit_dbus_filter,
198 manager, NULL((void*)0));
199 }
200
201 if (priv->bus_proxy == NULL((void*)0)) {
202 priv->bus_proxy =
203 dbus_g_proxy_new_for_name_owner (priv->dbus_connection,
204 DBUS_SERVICE_DBUS"org.freedesktop.DBus",
205 DBUS_PATH_DBUS"/org/freedesktop/DBus",
206 DBUS_INTERFACE_DBUS"org.freedesktop.DBus",
207 &connection_error);
208
209 if (priv->bus_proxy == NULL((void*)0)) {
210 g_propagate_error (error, connection_error);
211 is_connected = FALSE(0);
212 goto out;
213 }
214
215 dbus_g_proxy_add_signal (priv->bus_proxy,
216 "NameOwnerChanged",
217 G_TYPE_STRING((GType) ((16) << (2))),
218 G_TYPE_STRING((GType) ((16) << (2))),
219 G_TYPE_STRING((GType) ((16) << (2))),
220 G_TYPE_INVALID((GType) ((0) << (2))));
221
222 dbus_g_proxy_connect_signal (priv->bus_proxy,
223 "NameOwnerChanged",
224 G_CALLBACK (csm_consolekit_on_name_owner_changed)((GCallback) (csm_consolekit_on_name_owner_changed)),
225 manager, NULL((void*)0));
226 }
227
228 if (priv->ck_proxy == NULL((void*)0)) {
229 priv->ck_proxy =
230 dbus_g_proxy_new_for_name_owner (priv->dbus_connection,
231 "org.freedesktop.ConsoleKit",
232 "/org/freedesktop/ConsoleKit/Manager",
233 "org.freedesktop.ConsoleKit.Manager",
234 &connection_error);
235
236 if (priv->ck_proxy == NULL((void*)0)) {
237 g_propagate_error (error, connection_error);
238 is_connected = FALSE(0);
239 goto out;
240 }
241 }
242
243 is_connected = TRUE(!(0));
244
245out:
246 if (priv->is_connected != is_connected) {
247 priv->is_connected = is_connected;
248 g_object_notify (G_OBJECT (manager)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((manager)), (((GType) ((20) << (2))))))))
, "is-connected");
249 }
250
251 if (!is_connected) {
252 if (priv->dbus_connection == NULL((void*)0)) {
253 if (priv->bus_proxy != NULL((void*)0)) {
254 g_object_unref (priv->bus_proxy);
255 priv->bus_proxy = NULL((void*)0);
256 }
257
258 if (priv->ck_proxy != NULL((void*)0)) {
259 g_object_unref (priv->ck_proxy);
260 priv->ck_proxy = NULL((void*)0);
261 }
262 } else if (priv->bus_proxy == NULL((void*)0)) {
263 if (priv->ck_proxy != NULL((void*)0)) {
264 g_object_unref (priv->ck_proxy);
265 priv->ck_proxy = NULL((void*)0);
266 }
267 }
268 }
269
270 return is_connected;
271}
272
273static void
274csm_consolekit_on_name_owner_changed (DBusGProxy *bus_proxy,
275 const char *name,
276 const char *prev_owner,
277 const char *new_owner,
278 CsmConsolekit *manager)
279{
280 CsmConsolekitPrivate *priv;
281
282 if (name != NULL((void*)0) && strcmp (name, "org.freedesktop.ConsoleKit") != 0) {
283 return;
284 }
285
286 priv = csm_consolekit_get_instance_private (manager);
287
288 if (priv->ck_proxy != NULL((void*)0)) {
289 g_object_unref (priv->ck_proxy);
290 priv->ck_proxy = NULL((void*)0);
291 }
292
293 csm_consolekit_ensure_ck_connection (manager, NULL((void*)0));
294}
295
296static void
297csm_consolekit_init (CsmConsolekit *manager)
298{
299 GError *error;
300
301 error = NULL((void*)0);
302
303 if (!csm_consolekit_ensure_ck_connection (manager, &error)) {
304 g_warning ("Could not connect to ConsoleKit: %s",
305 error->message);
306 g_error_free (error);
307 }
308}
309
310static void
311csm_consolekit_free_dbus (CsmConsolekit *manager)
312{
313 CsmConsolekitPrivate *priv;
314
315 priv = csm_consolekit_get_instance_private (manager);
316 if (priv->bus_proxy != NULL((void*)0)) {
317 g_object_unref (priv->bus_proxy);
318 priv->bus_proxy = NULL((void*)0);
319 }
320
321 if (priv->ck_proxy != NULL((void*)0)) {
322 g_object_unref (priv->ck_proxy);
323 priv->ck_proxy = NULL((void*)0);
324 }
325
326 if (priv->dbus_connection != NULL((void*)0)) {
327 DBusConnection *connection;
328 connection = dbus_g_connection_get_connection (priv->dbus_connection);
329 dbus_connection_remove_filter (connection,
330 csm_consolekit_dbus_filter,
331 manager);
332
333 dbus_g_connection_unref (priv->dbus_connection);
334 priv->dbus_connection = NULL((void*)0);
335 }
336}
337
338static void
339csm_consolekit_finalize (GObject *object)
340{
341 CsmConsolekit *manager;
342 GObjectClass *parent_class;
343
344 manager = CSM_CONSOLEKIT (object);
345
346 parent_class = G_OBJECT_CLASS (csm_consolekit_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((csm_consolekit_parent_class)), (((GType) ((20) << (
2))))))))
;
347
348 csm_consolekit_free_dbus (manager);
349
350 if (parent_class->finalize != NULL((void*)0)) {
351 parent_class->finalize (object);
352 }
353}
354
355GQuark
356csm_consolekit_error_quark (void)
357{
358 static GQuark error_quark = 0;
359
360 if (error_quark == 0) {
361 error_quark = g_quark_from_static_string ("csm-consolekit-error");
362 }
363
364 return error_quark;
365}
366
367CsmConsolekit *
368csm_consolekit_new (void)
369{
370 CsmConsolekit *manager;
371
372 manager = g_object_new (CSM_TYPE_CONSOLEKIT(csm_consolekit_get_type ()), NULL((void*)0));
373
374 return manager;
375}
376
377static void
378emit_restart_complete (CsmConsolekit *manager,
379 GError *error)
380{
381 GError *call_error;
382
383 call_error = NULL((void*)0);
384
385 if (error != NULL((void*)0)) {
386 call_error = g_error_new_literal (CSM_CONSOLEKIT_ERROR(csm_consolekit_error_quark ()),
387 CSM_CONSOLEKIT_ERROR_RESTARTING,
388 error->message);
389 }
390
391 g_signal_emit (G_OBJECT (manager)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((manager)), (((GType) ((20) << (2))))))))
,
392 signals [REQUEST_COMPLETED],
393 0, call_error);
394
395 if (call_error != NULL((void*)0)) {
396 g_error_free (call_error);
397 }
398}
399
400static void
401emit_stop_complete (CsmConsolekit *manager,
402 GError *error)
403{
404 GError *call_error;
405
406 call_error = NULL((void*)0);
407
408 if (error != NULL((void*)0)) {
409 call_error = g_error_new_literal (CSM_CONSOLEKIT_ERROR(csm_consolekit_error_quark ()),
410 CSM_CONSOLEKIT_ERROR_STOPPING,
411 error->message);
412 }
413
414 g_signal_emit (G_OBJECT (manager)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((manager)), (((GType) ((20) << (2))))))))
,
415 signals [REQUEST_COMPLETED],
416 0, call_error);
417
418 if (call_error != NULL((void*)0)) {
419 g_error_free (call_error);
420 }
421}
422
423void
424csm_consolekit_attempt_restart (CsmConsolekit *manager)
425{
426 gboolean res;
427 GError *error;
428 CsmConsolekitPrivate *priv;
429
430 error = NULL((void*)0);
431 priv = csm_consolekit_get_instance_private (manager);
432
433 if (!csm_consolekit_ensure_ck_connection (manager, &error)) {
434 g_warning ("Could not connect to ConsoleKit: %s",
435 error->message);
436 emit_restart_complete (manager, error);
437 g_error_free (error);
438 return;
439 }
440
441 res = dbus_g_proxy_call_with_timeout (priv->ck_proxy,
442 "Restart",
443 INT_MAX2147483647,
444 &error,
445 G_TYPE_INVALID((GType) ((0) << (2))),
446 G_TYPE_INVALID((GType) ((0) << (2))));
447
448 if (!res) {
449 g_warning ("Unable to restart system: %s", error->message);
450 emit_restart_complete (manager, error);
451 g_error_free (error);
452 } else {
453 emit_restart_complete (manager, NULL((void*)0));
454 }
455}
456
457void
458csm_consolekit_attempt_stop (CsmConsolekit *manager)
459{
460 gboolean res;
461 GError *error;
462 CsmConsolekitPrivate *priv;
463
464 error = NULL((void*)0);
465 priv = csm_consolekit_get_instance_private (manager);
466
467 if (!csm_consolekit_ensure_ck_connection (manager, &error)) {
468 g_warning ("Could not connect to ConsoleKit: %s",
469 error->message);
470 emit_stop_complete (manager, error);
471 g_error_free (error);
472 return;
473 }
474
475 res = dbus_g_proxy_call_with_timeout (priv->ck_proxy,
476 "Stop",
477 INT_MAX2147483647,
478 &error,
479 G_TYPE_INVALID((GType) ((0) << (2))),
480 G_TYPE_INVALID((GType) ((0) << (2))));
481
482 if (!res) {
483 g_warning ("Unable to stop system: %s", error->message);
484 emit_stop_complete (manager, error);
485 g_error_free (error);
486 } else {
487 emit_stop_complete (manager, NULL((void*)0));
488 }
489}
490
491void
492csm_consolekit_attempt_suspend (CsmConsolekit *manager)
493{
494 gboolean res;
495 GError *error;
496 CsmConsolekitPrivate *priv;
497
498 error = NULL((void*)0);
499 priv = csm_consolekit_get_instance_private (manager);
500
501 if (!csm_consolekit_ensure_ck_connection (manager, &error)) {
502 g_warning ("Could not connect to ConsoleKit: %s",
503 error->message);
504 g_error_free (error);
505 return;
506 }
507
508 res = dbus_g_proxy_call_with_timeout (priv->ck_proxy,
509 "Suspend",
510 INT_MAX2147483647,
511 &error,
512 G_TYPE_BOOLEAN((GType) ((5) << (2))), TRUE(!(0)), /* interactive */
513 G_TYPE_INVALID((GType) ((0) << (2))),
514 G_TYPE_INVALID((GType) ((0) << (2))));
515
516 if (!res) {
517 g_warning ("Unable to suspend system: %s", error->message);
518 g_error_free (error);
519 }
520}
521
522void
523csm_consolekit_attempt_hibernate (CsmConsolekit *manager)
524{
525 gboolean res;
526 GError *error;
527 CsmConsolekitPrivate *priv;
528
529 error = NULL((void*)0);
530 priv = csm_consolekit_get_instance_private (manager);
531
532 if (!csm_consolekit_ensure_ck_connection (manager, &error)) {
533 g_warning ("Could not connect to ConsoleKit: %s",
534 error->message);
535 g_error_free (error);
536 return;
537 }
538
539 res = dbus_g_proxy_call_with_timeout (priv->ck_proxy,
540 "Hibernate",
541 INT_MAX2147483647,
542 &error,
543 G_TYPE_BOOLEAN((GType) ((5) << (2))), TRUE(!(0)), /* interactive */
544 G_TYPE_INVALID((GType) ((0) << (2))),
545 G_TYPE_INVALID((GType) ((0) << (2))));
546
547
548 if (!res) {
549 g_warning ("Unable to hibernate system: %s", error->message);
550 g_error_free (error);
551 }
552}
553
554static gboolean
555get_current_session_id (DBusConnection *connection,
556 char **session_id)
557{
558 DBusError local_error;
559 DBusMessage *message;
560 DBusMessage *reply;
561 gboolean ret;
562 DBusMessageIter iter;
563 const char *value;
564
565 ret = FALSE(0);
566 reply = NULL((void*)0);
567
568 dbus_error_init (&local_error);
569 message = dbus_message_new_method_call (CK_NAME"org.freedesktop.ConsoleKit",
570 CK_MANAGER_PATH"/org/freedesktop/ConsoleKit/Manager",
571 CK_MANAGER_INTERFACE"org.freedesktop.ConsoleKit.Manager",
572 "GetCurrentSession");
573 if (message == NULL((void*)0)) {
574 goto out;
575 }
576
577 dbus_error_init (&local_error);
578 reply = dbus_connection_send_with_reply_and_block (connection,
579 message,
580 -1,
581 &local_error);
582 if (reply == NULL((void*)0)) {
583 if (dbus_error_is_set (&local_error)) {
584 g_warning ("Unable to determine session: %s", local_error.message);
585 dbus_error_free (&local_error);
586 goto out;
587 }
588 }
589
590 dbus_message_iter_init (reply, &iter);
591 dbus_message_iter_get_basic (&iter, &value);
592 if (session_id != NULL((void*)0)) {
593 *session_id = g_strdup (value)g_strdup_inline (value);
594 }
595
596 ret = TRUE(!(0));
597out:
598 if (message != NULL((void*)0)) {
599 dbus_message_unref (message);
600 }
601 if (reply != NULL((void*)0)) {
602 dbus_message_unref (reply);
603 }
604
605 return ret;
606}
607
608static gboolean
609get_seat_id_for_session (DBusConnection *connection,
610 const char *session_id,
611 char **seat_id)
612{
613 DBusError local_error;
614 DBusMessage *message;
615 DBusMessage *reply;
616 gboolean ret;
617 DBusMessageIter iter;
618 const char *value;
619
620 ret = FALSE(0);
621 reply = NULL((void*)0);
622
623 dbus_error_init (&local_error);
624 message = dbus_message_new_method_call (CK_NAME"org.freedesktop.ConsoleKit",
625 session_id,
626 CK_SESSION_INTERFACE"org.freedesktop.ConsoleKit.Session",
627 "GetSeatId");
628 if (message == NULL((void*)0)) {
629 goto out;
630 }
631
632 dbus_error_init (&local_error);
633 reply = dbus_connection_send_with_reply_and_block (connection,
634 message,
635 -1,
636 &local_error);
637 if (reply == NULL((void*)0)) {
638 if (dbus_error_is_set (&local_error)) {
639 g_warning ("Unable to determine seat: %s", local_error.message);
640 dbus_error_free (&local_error);
641 goto out;
642 }
643 }
644
645 dbus_message_iter_init (reply, &iter);
646 dbus_message_iter_get_basic (&iter, &value);
647 if (seat_id != NULL((void*)0)) {
648 *seat_id = g_strdup (value)g_strdup_inline (value);
649 }
650
651 ret = TRUE(!(0));
652out:
653 if (message != NULL((void*)0)) {
654 dbus_message_unref (message);
655 }
656 if (reply != NULL((void*)0)) {
657 dbus_message_unref (reply);
658 }
659
660 return ret;
661}
662
663static char *
664get_current_seat_id (DBusConnection *connection)
665{
666 gboolean res;
667 char *session_id;
668 char *seat_id;
669
670 session_id = NULL((void*)0);
671 seat_id = NULL((void*)0);
672
673 res = get_current_session_id (connection, &session_id);
674 if (res) {
675 res = get_seat_id_for_session (connection, session_id, &seat_id);
Value stored to 'res' is never read
676 }
677 g_free (session_id);
678
679 return seat_id;
680}
681
682void
683csm_consolekit_set_session_idle (CsmConsolekit *manager,
684 gboolean is_idle)
685{
686 gboolean res;
687 GError *error;
688 char *session_id;
689 DBusMessage *message;
690 DBusMessage *reply;
691 DBusError dbus_error;
692 DBusMessageIter iter;
693 CsmConsolekitPrivate *priv;
694
695 error = NULL((void*)0);
696 priv = csm_consolekit_get_instance_private (manager);
697
698 if (!csm_consolekit_ensure_ck_connection (manager, &error)) {
699 g_warning ("Could not connect to ConsoleKit: %s",
700 error->message);
701 g_error_free (error);
702 return;
703 }
704
705 session_id = NULL((void*)0);
706 res = get_current_session_id (dbus_g_connection_get_connection (priv->dbus_connection),
707 &session_id);
708 if (!res) {
709 goto out;
710 }
711
712
713 g_debug ("Updating ConsoleKit idle status: %d", is_idle);
714 message = dbus_message_new_method_call (CK_NAME"org.freedesktop.ConsoleKit",
715 session_id,
716 CK_SESSION_INTERFACE"org.freedesktop.ConsoleKit.Session",
717 "SetIdleHint");
718 if (message == NULL((void*)0)) {
719 g_debug ("Couldn't allocate the D-Bus message");
720 return;
721 }
722
723 dbus_message_iter_init_append (message, &iter);
724 dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN((int) 'b'), &is_idle);
725
726 /* FIXME: use async? */
727 dbus_error_init (&dbus_error);
728 reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection (priv->dbus_connection),
729 message,
730 -1,
731 &dbus_error);
732 dbus_message_unref (message);
733
734 if (reply != NULL((void*)0)) {
735 dbus_message_unref (reply);
736 }
737
738 if (dbus_error_is_set (&dbus_error)) {
739 g_debug ("%s raised:\n %s\n\n", dbus_error.name, dbus_error.message);
740 dbus_error_free (&dbus_error);
741 }
742
743out:
744 g_free (session_id);
745}
746
747static gboolean
748seat_can_activate_sessions (DBusConnection *connection,
749 const char *seat_id)
750{
751 DBusError local_error;
752 DBusMessage *message;
753 DBusMessage *reply;
754 DBusMessageIter iter;
755 gboolean can_activate;
756
757 can_activate = FALSE(0);
758 reply = NULL((void*)0);
759
760 dbus_error_init (&local_error);
761 message = dbus_message_new_method_call (CK_NAME"org.freedesktop.ConsoleKit",
762 seat_id,
763 CK_SEAT_INTERFACE"org.freedesktop.ConsoleKit.Seat",
764 "CanActivateSessions");
765 if (message == NULL((void*)0)) {
766 goto out;
767 }
768
769 dbus_error_init (&local_error);
770 reply = dbus_connection_send_with_reply_and_block (connection,
771 message,
772 -1,
773 &local_error);
774 if (reply == NULL((void*)0)) {
775 if (dbus_error_is_set (&local_error)) {
776 g_warning ("Unable to activate session: %s", local_error.message);
777 dbus_error_free (&local_error);
778 goto out;
779 }
780 }
781
782 dbus_message_iter_init (reply, &iter);
783 dbus_message_iter_get_basic (&iter, &can_activate);
784
785out:
786 if (message != NULL((void*)0)) {
787 dbus_message_unref (message);
788 }
789 if (reply != NULL((void*)0)) {
790 dbus_message_unref (reply);
791 }
792
793 return can_activate;
794}
795
796gboolean
797csm_consolekit_can_switch_user (CsmConsolekit *manager)
798{
799 GError *error;
800 char *seat_id;
801 gboolean ret;
802 CsmConsolekitPrivate *priv;
803
804 error = NULL((void*)0);
805 priv = csm_consolekit_get_instance_private (manager);
806
807 if (!csm_consolekit_ensure_ck_connection (manager, &error)) {
808 g_warning ("Could not connect to ConsoleKit: %s",
809 error->message);
810 g_error_free (error);
811 return FALSE(0);
812 }
813
814 seat_id = get_current_seat_id (dbus_g_connection_get_connection (priv->dbus_connection));
815 if (seat_id == NULL((void*)0) || seat_id[0] == '\0') {
816 g_debug ("seat id is not set; can't switch sessions");
817 return FALSE(0);
818 }
819
820 ret = seat_can_activate_sessions (dbus_g_connection_get_connection (priv->dbus_connection),
821 seat_id);
822 g_free (seat_id);
823
824 return ret;
825}
826
827gboolean
828csm_consolekit_get_restart_privileges (CsmConsolekit *manager)
829{
830 g_signal_emit (G_OBJECT (manager)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((manager)), (((GType) ((20) << (2))))))))
,
831 signals [PRIVILEGES_COMPLETED],
832 0, TRUE(!(0)), TRUE(!(0)), NULL((void*)0));
833
834 return TRUE(!(0));
835}
836
837gboolean
838csm_consolekit_get_stop_privileges (CsmConsolekit *manager)
839{
840 g_signal_emit (G_OBJECT (manager)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((manager)), (((GType) ((20) << (2))))))))
,
841 signals [PRIVILEGES_COMPLETED],
842 0, TRUE(!(0)), TRUE(!(0)), NULL((void*)0));
843
844 return TRUE(!(0));
845}
846
847gboolean
848csm_consolekit_can_restart (CsmConsolekit *manager)
849{
850 gboolean res;
851 gboolean can_restart;
852 GError *error;
853 CsmConsolekitPrivate *priv;
854
855 error = NULL((void*)0);
856 priv = csm_consolekit_get_instance_private (manager);
857
858 if (!csm_consolekit_ensure_ck_connection (manager, &error)) {
859 g_warning ("Could not connect to ConsoleKit: %s",
860 error->message);
861 g_error_free (error);
862 return FALSE(0);
863 }
864
865 res = dbus_g_proxy_call_with_timeout (priv->ck_proxy,
866 "CanRestart",
867 INT_MAX2147483647,
868 &error,
869 G_TYPE_INVALID((GType) ((0) << (2))),
870 G_TYPE_BOOLEAN((GType) ((5) << (2))), &can_restart,
871 G_TYPE_INVALID((GType) ((0) << (2))));
872 if (res == FALSE(0)) {
873 g_warning ("Could not make DBUS call: %s",
874 error->message);
875 g_error_free (error);
876 return FALSE(0);
877 }
878
879 return can_restart;
880}
881
882gboolean
883csm_consolekit_can_stop (CsmConsolekit *manager)
884{
885 gboolean res;
886 gboolean can_stop;
887 GError *error;
888 CsmConsolekitPrivate *priv;
889
890 error = NULL((void*)0);
891 priv = csm_consolekit_get_instance_private (manager);
892
893 if (!csm_consolekit_ensure_ck_connection (manager, &error)) {
894 g_warning ("Could not connect to ConsoleKit: %s",
895 error->message);
896 g_error_free (error);
897 return FALSE(0);
898 }
899
900 res = dbus_g_proxy_call_with_timeout (priv->ck_proxy,
901 "CanStop",
902 INT_MAX2147483647,
903 &error,
904 G_TYPE_INVALID((GType) ((0) << (2))),
905 G_TYPE_BOOLEAN((GType) ((5) << (2))), &can_stop,
906 G_TYPE_INVALID((GType) ((0) << (2))));
907
908 if (res == FALSE(0)) {
909 g_warning ("Could not make DBUS call: %s",
910 error->message);
911 g_error_free (error);
912 return FALSE(0);
913 }
914
915 return can_stop;
916}
917
918gboolean
919csm_consolekit_can_suspend (CsmConsolekit *manager)
920{
921 gboolean res;
922 gboolean can_suspend;
923 gchar *retval;
924 GError *error = NULL((void*)0);
925 CsmConsolekitPrivate *priv;
926
927 priv = csm_consolekit_get_instance_private (manager);
928
929 if (!csm_consolekit_ensure_ck_connection (manager, &error)) {
930 g_warning ("Could not connect to ConsoleKit: %s",
931 error->message);
932 g_error_free (error);
933 return FALSE(0);
934 }
935
936 res = dbus_g_proxy_call_with_timeout (priv->ck_proxy,
937 "CanSuspend",
938 INT_MAX2147483647,
939 &error,
940 G_TYPE_INVALID((GType) ((0) << (2))),
941 G_TYPE_STRING((GType) ((16) << (2))), &retval,
942 G_TYPE_INVALID((GType) ((0) << (2))));
943
944 if (res == FALSE(0)) {
945 g_warning ("Could not make DBUS call: %s",
946 error->message);
947 g_error_free (error);
948 return FALSE(0);
949 }
950
951 can_suspend = g_strcmp0 (retval, "yes") == 0 ||
952 g_strcmp0 (retval, "challenge") == 0;
953
954 g_free (retval);
955 return can_suspend;
956}
957
958gboolean
959csm_consolekit_can_hibernate (CsmConsolekit *manager)
960{
961 gboolean res;
962 gboolean can_hibernate;
963 gchar *retval;
964 GError *error = NULL((void*)0);
965 CsmConsolekitPrivate *priv;
966
967 priv = csm_consolekit_get_instance_private (manager);
968
969 if (!csm_consolekit_ensure_ck_connection (manager, &error)) {
970 g_warning ("Could not connect to ConsoleKit: %s",
971 error->message);
972 g_error_free (error);
973 return FALSE(0);
974 }
975
976 res = dbus_g_proxy_call_with_timeout (priv->ck_proxy,
977 "CanHibernate",
978 INT_MAX2147483647,
979 &error,
980 G_TYPE_INVALID((GType) ((0) << (2))),
981 G_TYPE_STRING((GType) ((16) << (2))), &retval,
982 G_TYPE_INVALID((GType) ((0) << (2))));
983
984 if (res == FALSE(0)) {
985 g_warning ("Could not make DBUS call: %s",
986 error->message);
987 g_error_free (error);
988 return FALSE(0);
989 }
990
991 can_hibernate = g_strcmp0 (retval, "yes") == 0 ||
992 g_strcmp0 (retval, "challenge") == 0;
993
994 g_free (retval);
995 return can_hibernate;
996}
997
998gchar *
999csm_consolekit_get_current_session_type (CsmConsolekit *manager)
1000{
1001 GError *gerror;
1002 DBusConnection *connection;
1003 DBusError error;
1004 DBusMessage *message = NULL((void*)0);
1005 DBusMessage *reply = NULL((void*)0);
1006 gchar *session_id;
1007 gchar *ret;
1008 DBusMessageIter iter;
1009 const char *value;
1010 CsmConsolekitPrivate *priv;
1011
1012 session_id = NULL((void*)0);
1013 ret = NULL((void*)0);
1014 gerror = NULL((void*)0);
1015 priv = csm_consolekit_get_instance_private (manager);
1016
1017 if (!csm_consolekit_ensure_ck_connection (manager, &gerror)) {
1018 g_warning ("Could not connect to ConsoleKit: %s",
1019 gerror->message);
1020 g_error_free (gerror);
1021 goto out;
1022 }
1023
1024 connection = dbus_g_connection_get_connection (priv->dbus_connection);
1025 if (!get_current_session_id (connection, &session_id)) {
1026 goto out;
1027 }
1028
1029 dbus_error_init (&error);
1030 message = dbus_message_new_method_call (CK_NAME"org.freedesktop.ConsoleKit",
1031 session_id,
1032 CK_SESSION_INTERFACE"org.freedesktop.ConsoleKit.Session",
1033 "GetSessionType");
1034 if (message == NULL((void*)0)) {
1035 goto out;
1036 }
1037
1038 reply = dbus_connection_send_with_reply_and_block (connection,
1039 message,
1040 -1,
1041 &error);
1042
1043 if (reply == NULL((void*)0)) {
1044 if (dbus_error_is_set (&error)) {
1045 g_warning ("Unable to determine session type: %s", error.message);
1046 dbus_error_free (&error);
1047 }
1048 goto out;
1049 }
1050
1051 dbus_message_iter_init (reply, &iter);
1052 dbus_message_iter_get_basic (&iter, &value);
1053 ret = g_strdup (value)g_strdup_inline (value);
1054
1055out:
1056 if (message != NULL((void*)0)) {
1057 dbus_message_unref (message);
1058 }
1059 if (reply != NULL((void*)0)) {
1060 dbus_message_unref (reply);
1061 }
1062 g_free (session_id);
1063
1064 return ret;
1065}
1066
1067
1068CsmConsolekit *
1069csm_get_consolekit (void)
1070{
1071 static CsmConsolekit *manager = NULL((void*)0);
1072
1073 if (manager == NULL((void*)0)) {
1074 manager = csm_consolekit_new ();
1075 }
1076
1077 return g_object_ref (manager)((__typeof__ (manager)) (g_object_ref) (manager));
1078}