Skip to content

Commit c124735

Browse files
authored
Merge pull request #10 from BuddiesOfBudgie/guards
Ensure we return TRUE for inhibit dbus calls
2 parents 9edd901 + 3d430b9 commit c124735

1 file changed

Lines changed: 104 additions & 15 deletions

File tree

gnome-session/gsm-manager.c

Lines changed: 104 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,8 +2381,30 @@ on_inhibitor_vanished (GsmInhibitor *inhibitor,
23812381
GsmManager *manager)
23822382
{
23832383
GsmManagerPrivate *priv = gsm_manager_get_instance_private (manager);
2384+
const char *id;
2385+
const char *app_id;
2386+
const char *bus_name;
2387+
guint flags;
2388+
2389+
/* Take a ref to prevent the inhibitor from being destroyed while we work with it */
2390+
g_object_ref (inhibitor);
2391+
2392+
id = gsm_inhibitor_peek_id (inhibitor);
2393+
app_id = gsm_inhibitor_peek_app_id (inhibitor);
2394+
bus_name = gsm_inhibitor_peek_bus_name (inhibitor);
2395+
flags = gsm_inhibitor_peek_flags (inhibitor);
23842396

2385-
gsm_store_remove (priv->inhibitors, gsm_inhibitor_peek_id (inhibitor));
2397+
g_debug ("GsmManager: Inhibitor vanished: id=%s app_id=%s bus_name=%s flags=%u",
2398+
id ? id : "(null)",
2399+
app_id ? app_id : "(null)",
2400+
bus_name ? bus_name : "(null)",
2401+
flags);
2402+
2403+
if (id != NULL) {
2404+
gsm_store_remove (priv->inhibitors, id);
2405+
}
2406+
2407+
g_object_unref (inhibitor);
23862408
}
23872409

23882410
static void
@@ -2393,11 +2415,26 @@ on_store_inhibitor_added (GsmStore *store,
23932415
GsmManagerPrivate *priv = gsm_manager_get_instance_private (manager);
23942416
GsmInhibitor *i;
23952417
GsmInhibitorFlag new_inhibited_actions;
2396-
2397-
g_debug ("GsmManager: Inhibitor added: %s", id);
2418+
const char *bus_name;
2419+
const char *app_id;
2420+
const char *reason;
2421+
guint flags;
23982422

23992423
i = GSM_INHIBITOR (gsm_store_lookup (store, id));
24002424

2425+
bus_name = gsm_inhibitor_peek_bus_name (i);
2426+
app_id = gsm_inhibitor_peek_app_id (i);
2427+
reason = gsm_inhibitor_peek_reason (i);
2428+
flags = gsm_inhibitor_peek_flags (i);
2429+
2430+
g_debug ("GsmManager: Inhibitor added: id=%s bus_name=%s app_id=%s flags=%u reason=%s cookie=%u",
2431+
id,
2432+
bus_name ? bus_name : "(null)",
2433+
app_id ? app_id : "(null)",
2434+
flags,
2435+
reason ? reason : "(null)",
2436+
gsm_inhibitor_peek_cookie (i));
2437+
24012438
new_inhibited_actions = priv->inhibited_actions | gsm_inhibitor_peek_flags (i);
24022439
update_inhibited_actions (manager, new_inhibited_actions);
24032440

@@ -2415,7 +2452,14 @@ collect_inhibition_flags (const char *id,
24152452
{
24162453
GsmInhibitorFlag *new_inhibited_actions = user_data;
24172454

2418-
*new_inhibited_actions |= gsm_inhibitor_peek_flags (GSM_INHIBITOR (object));
2455+
if (GSM_IS_INHIBITOR (object)) {
2456+
GsmInhibitorFlag flags = gsm_inhibitor_peek_flags (GSM_INHIBITOR (object));
2457+
*new_inhibited_actions |= flags;
2458+
g_debug ("GsmManager: Collecting inhibitor %s flags=%u", id, flags);
2459+
} else {
2460+
g_warning ("GsmManager: collect_inhibition_flags called with non-inhibitor object for id %s",
2461+
id ? id : "(null)");
2462+
}
24192463

24202464
return FALSE;
24212465
}
@@ -2427,8 +2471,10 @@ on_store_inhibitor_removed (GsmStore *store,
24272471
{
24282472
GsmManagerPrivate *priv = gsm_manager_get_instance_private (manager);
24292473
GsmInhibitorFlag new_inhibited_actions;
2474+
guint inhibitor_count;
24302475

2431-
g_debug ("GsmManager: Inhibitor removed: %s", id);
2476+
inhibitor_count = gsm_store_size (priv->inhibitors);
2477+
g_debug ("GsmManager: Inhibitor removed: %s (remaining: %u)", id, inhibitor_count);
24322478

24332479
new_inhibited_actions = 0;
24342480
gsm_store_foreach (priv->inhibitors,
@@ -3198,7 +3244,7 @@ gsm_manager_inhibit (GsmExportedManager *skeleton,
31983244
"Reason not specified");
31993245
g_debug ("GsmManager: Unable to inhibit: %s", new_error->message);
32003246
g_dbus_method_invocation_take_error (invocation, new_error);
3201-
return FALSE;
3247+
return TRUE;
32023248
}
32033249

32043250
if (flags == 0) {
@@ -3209,7 +3255,7 @@ gsm_manager_inhibit (GsmExportedManager *skeleton,
32093255
"Invalid inhibit flags");
32103256
g_debug ("GsmManager: Unable to inhibit: %s", new_error->message);
32113257
g_dbus_method_invocation_take_error (invocation, new_error);
3212-
return FALSE;
3258+
return TRUE;
32133259
}
32143260

32153261
cookie = _generate_unique_cookie (manager);
@@ -3220,6 +3266,14 @@ gsm_manager_inhibit (GsmExportedManager *skeleton,
32203266
g_dbus_method_invocation_get_sender (invocation),
32213267
cookie);
32223268
gsm_store_add (priv->inhibitors, gsm_inhibitor_peek_id (inhibitor), G_OBJECT (inhibitor));
3269+
g_debug ("GsmManager: Inhibit successful - cookie=%u app_id=%s xid=%u flags=%u reason=%s sender=%s",
3270+
cookie,
3271+
app_id,
3272+
toplevel_xid,
3273+
flags,
3274+
reason,
3275+
g_dbus_method_invocation_get_sender (invocation));
3276+
32233277
g_object_unref (inhibitor);
32243278

32253279
gsm_exported_manager_complete_inhibit (skeleton, invocation, cookie);
@@ -3235,31 +3289,64 @@ gsm_manager_uninhibit (GsmExportedManager *skeleton,
32353289
{
32363290
GsmManagerPrivate *priv = gsm_manager_get_instance_private (manager);
32373291
GsmInhibitor *inhibitor;
3292+
const char *sender;
3293+
const char *inhibitor_id;
3294+
const char *app_id;
3295+
const char *bus_name;
3296+
const char *reason;
3297+
guint flags;
3298+
3299+
sender = g_dbus_method_invocation_get_sender (invocation);
32383300

3239-
g_debug ("GsmManager: Uninhibit %u", cookie);
3301+
g_debug ("GsmManager: Uninhibit %u from sender %s", cookie, sender);
32403302

32413303
inhibitor = (GsmInhibitor *)gsm_store_find (priv->inhibitors,
32423304
(GsmStoreFunc)_find_by_cookie,
32433305
&cookie);
32443306
if (inhibitor == NULL) {
32453307
GError *new_error;
32463308

3309+
g_warning ("GsmManager: Uninhibit called with invalid/unknown cookie %u from %s",
3310+
cookie, sender);
3311+
32473312
new_error = g_error_new (GSM_MANAGER_ERROR,
32483313
GSM_MANAGER_ERROR_GENERAL,
32493314
"Unable to uninhibit: Invalid cookie");
3250-
g_debug ("Unable to uninhibit: %s", new_error->message);
32513315
g_dbus_method_invocation_take_error (invocation, new_error);
32523316
return TRUE;
32533317
}
32543318

3255-
g_debug ("GsmManager: removing inhibitor %s %u reason '%s' %u connection %s",
3256-
gsm_inhibitor_peek_app_id (inhibitor),
3319+
/* Take a ref to prevent premature destruction */
3320+
g_object_ref (inhibitor);
3321+
3322+
inhibitor_id = gsm_inhibitor_peek_id (inhibitor);
3323+
app_id = gsm_inhibitor_peek_app_id (inhibitor);
3324+
bus_name = gsm_inhibitor_peek_bus_name (inhibitor);
3325+
reason = gsm_inhibitor_peek_reason (inhibitor);
3326+
flags = gsm_inhibitor_peek_flags (inhibitor);
3327+
3328+
g_debug ("GsmManager: removing inhibitor id=%s app_id=%s xid=%u reason='%s' flags=%u bus_name=%s",
3329+
inhibitor_id ? inhibitor_id : "(null)",
3330+
app_id ? app_id : "(null)",
32573331
gsm_inhibitor_peek_toplevel_xid (inhibitor),
3258-
gsm_inhibitor_peek_reason (inhibitor),
3259-
gsm_inhibitor_peek_flags (inhibitor),
3260-
gsm_inhibitor_peek_bus_name (inhibitor));
3332+
reason ? reason : "(null)",
3333+
flags,
3334+
bus_name ? bus_name : "(null)");
3335+
3336+
if (inhibitor_id == NULL) {
3337+
g_critical ("GsmManager: Inhibitor has NULL id, cannot remove from store");
3338+
g_object_unref (inhibitor);
3339+
3340+
GError *new_error = g_error_new (GSM_MANAGER_ERROR,
3341+
GSM_MANAGER_ERROR_GENERAL,
3342+
"Unable to uninhibit: Inhibitor has invalid state");
3343+
g_dbus_method_invocation_take_error (invocation, new_error);
3344+
return TRUE;
3345+
}
32613346

3262-
gsm_store_remove (priv->inhibitors, gsm_inhibitor_peek_id (inhibitor));
3347+
gsm_store_remove (priv->inhibitors, inhibitor_id);
3348+
3349+
g_object_unref (inhibitor);
32633350

32643351
gsm_exported_manager_complete_uninhibit (skeleton, invocation);
32653352

@@ -3286,6 +3373,8 @@ gsm_manager_is_inhibited (GsmExportedManager *skeleton,
32863373
if (inhibitor == NULL) {
32873374
is_inhibited = FALSE;
32883375
} else {
3376+
g_debug ("GsmManager: IsInhibited(%u) = TRUE (found inhibitor: %s)",
3377+
flags, gsm_inhibitor_peek_id (inhibitor));
32893378
is_inhibited = TRUE;
32903379
}
32913380
}

0 commit comments

Comments
 (0)