After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 696522 - only one user can invoke gnome_idle_monitor_add_user_active_watch() at a time
only one user can invoke gnome_idle_monitor_add_user_active_watch() at a time
Status: RESOLVED FIXED
Product: gnome-desktop
Classification: Core
Component: libgnome-desktop
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Desktop Maintainers
Desktop Maintainers
Depends on:
Blocks: 696169
 
 
Reported: 2013-03-24 23:18 UTC by Colin Walters
Modified: 2013-03-27 17:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
idleMonitor: Properly increment watch id in add_user_active_watch (1.03 KB, patch)
2013-03-24 23:32 UTC, drago01
reviewed Details | Review
idleMonitor: Properly increment watch id in add_user_active_watch (1.99 KB, patch)
2013-03-24 23:39 UTC, drago01
needs-work Details | Review
idle-monitor: Allow multiple watches for an alarm (4.14 KB, patch)
2013-03-25 00:16 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
idle-monitor: Use an incrementing watch ID for the active alarm as well (2.11 KB, patch)
2013-03-25 00:16 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
idle-monitor: Reindent (846 bytes, patch)
2013-03-25 00:16 UTC, Jasper St. Pierre (not reading bugmail)
accepted-commit_after_freeze Details | Review
idle-monitor: Refactor code a bit (3.12 KB, patch)
2013-03-25 00:16 UTC, Jasper St. Pierre (not reading bugmail)
accepted-commit_after_freeze Details | Review
idle-monitor: Store the monitor in the private watch struct (2.00 KB, patch)
2013-03-25 17:51 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
idle-monitor: Allow multiple watches for an alarm (2.81 KB, patch)
2013-03-25 17:51 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
idle-monitor: Use an incrementing watch ID for the active alarm as well (2.44 KB, patch)
2013-03-25 17:51 UTC, Jasper St. Pierre (not reading bugmail)
accepted-commit_now Details | Review
idle-monitor: Don't leak the user active alarm on dispose (998 bytes, patch)
2013-03-25 17:51 UTC, Jasper St. Pierre (not reading bugmail)
accepted-commit_now Details | Review
idle-monitor: Reindent (846 bytes, patch)
2013-03-25 17:51 UTC, Jasper St. Pierre (not reading bugmail)
accepted-commit_now Details | Review
idle-monitor: Refactor code a bit (3.13 KB, patch)
2013-03-25 17:51 UTC, Jasper St. Pierre (not reading bugmail)
accepted-commit_now Details | Review
idle-monitor: Allow multiple watches for an alarm (4.56 KB, patch)
2013-03-25 18:56 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
idle-monitor: Use an incrementing watch ID for the active alarm as well (2.46 KB, patch)
2013-03-25 18:56 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
idle-monitor: Don't leak the user active alarm on dispose (997 bytes, patch)
2013-03-25 18:56 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
idle-monitor: Reindent (846 bytes, patch)
2013-03-25 18:56 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
idle-monitor: Refactor code a bit (3.01 KB, patch)
2013-03-25 18:56 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
idle-monitor: Use g_clear_pointer (1.17 KB, patch)
2013-03-25 20:06 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
idle-monitor: Allow multiple watches for an alarm (4.43 KB, patch)
2013-03-25 20:06 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
idle-monitor: Use an incrementing watch ID for the active alarm as well (2.62 KB, patch)
2013-03-25 20:06 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
idle-monitor: Don't leak the user active alarm on dispose (1.07 KB, patch)
2013-03-25 20:06 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
idle-monitor: Refactor code a bit (3.02 KB, patch)
2013-03-25 20:06 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
0001-monitor-Be-defensive-against-callbacks-unreffing-mon.patch (1015 bytes, patch)
2013-03-26 00:00 UTC, Colin Walters
none Details | Review
0001-monitor-Be-defensive-against-callbacks-unreffing-mon.patch (1.05 KB, patch)
2013-03-26 00:03 UTC, Colin Walters
committed Details | Review

Description Colin Walters 2013-03-24 23:18:07 UTC
Though gnome_idle_monitor_add_user_active_watch() returns a watch ID, it's a constant 1.  Internally the function calls g_hash_table_insert() which will overwrite the previous watch.
Comment 1 drago01 2013-03-24 23:32:21 UTC
Created attachment 239704 [details] [review]
idleMonitor: Properly increment watch id in add_user_active_watch

We should use get_next_watch_serial() to get a watch_id.

---

Does this help?
Comment 2 Colin Walters 2013-03-24 23:34:11 UTC
Review of attachment 239704 [details] [review]:

No, other places have USER_ACTIVE_WATCH_ID hardcoded.
Comment 3 drago01 2013-03-24 23:39:42 UTC
Created attachment 239705 [details] [review]
idleMonitor: Properly increment watch id in add_user_active_watch

We should use get_next_watch_serial() to get a watch_id.
Comment 4 drago01 2013-03-24 23:40:20 UTC
(In reply to comment #3)
> Created an attachment (id=239705) [details] [review]
> idleMonitor: Properly increment watch id in add_user_active_watch
> 
> We should use get_next_watch_serial() to get a watch_id.

OK how about this? (Only compiled tested).
Comment 5 Jasper St. Pierre (not reading bugmail) 2013-03-24 23:57:44 UTC
That shouldn't have compiled either, and it's also wrong, as we still use g_hash_table_find to run watches for an alarm, and now there's more than one watch for an alarm. Patch set incoming.
Comment 6 drago01 2013-03-25 00:03:08 UTC
(In reply to comment #5)
> That shouldn't have compiled either, and it's also wrong, as we still use
> g_hash_table_find to run watches for an alarm, and now there's more than one
> watch for an alarm. Patch set incoming.

That's not a reason for it not to compile but ok.
Comment 7 Jasper St. Pierre (not reading bugmail) 2013-03-25 00:04:29 UTC
It shouldn't have compiled because you didn't change the use of USER_ACTIVE_WATCH_ID in get_next_watch_serial.
Comment 8 Jasper St. Pierre (not reading bugmail) 2013-03-25 00:16:09 UTC
Created attachment 239706 [details] [review]
idle-monitor: Allow multiple watches for an alarm

This doesn't do anything yet as we don't have multiple watches
for one alarm, but we'll remove the special USER_ACTIVE_WATCH_ID
soon so we can have multiple watches on it.
Comment 9 Jasper St. Pierre (not reading bugmail) 2013-03-25 00:16:12 UTC
Created attachment 239707 [details] [review]
idle-monitor: Use an incrementing watch ID for the active alarm as well

This makes sure that:

    add_user_active_alarm (callback1);
    add_user_active_alarm (callback2);

doesn't remove callback1 from getting an alarm, as we won't overwrite
the alarm IDs.
Comment 10 Jasper St. Pierre (not reading bugmail) 2013-03-25 00:16:15 UTC
Created attachment 239708 [details] [review]
idle-monitor: Reindent
Comment 11 Jasper St. Pierre (not reading bugmail) 2013-03-25 00:16:17 UTC
Created attachment 239709 [details] [review]
idle-monitor: Refactor code a bit

Merge two similar methods.
Comment 12 drago01 2013-03-25 09:30:29 UTC
(In reply to comment #7)
> It shouldn't have compiled because you didn't change the use of
> USER_ACTIVE_WATCH_ID in get_next_watch_serial.

I didn't remove the constant.
Comment 13 Bastien Nocera 2013-03-25 10:13:00 UTC
Comment on attachment 239708 [details] [review]
idle-monitor: Reindent

Looks fine to commit to master.
Comment 14 Bastien Nocera 2013-03-25 10:14:57 UTC
Review of attachment 239706 [details] [review]:

::: libgnome-desktop/gnome-idle-monitor.c
@@ -54,3 @@
 typedef struct
 {
-	Display			 *display;

Can you remove this in a separate patch please?

@@ +168,3 @@
 	}
 
+	watches = g_hash_table_get_values (monitor->priv->watches);

Use g_hash_table_foreach() directly, avoids the temporary list.

@@ +252,2 @@
 	if (watch->id != USER_ACTIVE_WATCH_ID) {
+		XSyncDestroyAlarm (watch->monitor->priv->display, watch->xalarm);

Separate patch, as per above.
Comment 15 Bastien Nocera 2013-03-25 10:17:06 UTC
Review of attachment 239707 [details] [review]:

::: libgnome-desktop/gnome-idle-monitor.c
@@ +236,3 @@
 get_next_watch_serial (void)
 {
+	static guint32 serial = 1;

You can start at 0 as you increment it before returning it.

@@ +257,3 @@
 
+	if (watch->xalarm != monitor->priv->user_active_alarm) {
+		XSyncDestroyAlarm (monitor->priv->display, watch->xalarm);

This change (the ->display change) should have happened in the previous patch, though I asked for the changes to be split off.
Comment 16 Bastien Nocera 2013-03-25 10:18:00 UTC
Review of attachment 239709 [details] [review]:

Looks good for master.
Comment 17 Jasper St. Pierre (not reading bugmail) 2013-03-25 16:47:58 UTC
(In reply to comment #14)
> Review of attachment 239706 [details] [review]:
> 
> ::: libgnome-desktop/gnome-idle-monitor.c
> @@ +168,3 @@
>      }
> 
> +    watches = g_hash_table_get_values (monitor->priv->watches);
> 
> Use g_hash_table_foreach() directly, avoids the temporary list.

The caller may call gnome_idle_monitor_remove_watch in the callback, which will modify the hash table during the foreach, triggering an assert.
Comment 18 Bastien Nocera 2013-03-25 17:04:03 UTC
(In reply to comment #17)
> (In reply to comment #14)
> > Review of attachment 239706 [details] [review] [details]:
> > 
> > ::: libgnome-desktop/gnome-idle-monitor.c
> > @@ +168,3 @@
> >      }
> > 
> > +    watches = g_hash_table_get_values (monitor->priv->watches);
> > 
> > Use g_hash_table_foreach() directly, avoids the temporary list.
> 
> The caller may call gnome_idle_monitor_remove_watch in the callback, which will
> modify the hash table during the foreach, triggering an assert.

Can you make a comment to that effect above the call so nobody tries to "optimise" it later on?
Comment 19 Jasper St. Pierre (not reading bugmail) 2013-03-25 17:51:02 UTC
Created attachment 239803 [details] [review]
idle-monitor: Store the monitor in the private watch struct

Since we'll need to access more things than just the Display
on it, let's clean up the code for the access right now.
Comment 20 Jasper St. Pierre (not reading bugmail) 2013-03-25 17:51:05 UTC
Created attachment 239804 [details] [review]
idle-monitor: Allow multiple watches for an alarm

This doesn't do anything yet as we don't have multiple watches
for one alarm, but we'll remove the special USER_ACTIVE_WATCH_ID
soon so we can have multiple watches on it.
Comment 21 Jasper St. Pierre (not reading bugmail) 2013-03-25 17:51:08 UTC
Created attachment 239805 [details] [review]
idle-monitor: Use an incrementing watch ID for the active alarm as well

This makes sure that:

    add_user_active_alarm (callback1);
    add_user_active_alarm (callback2);

doesn't remove callback1 from getting an alarm, as we won't overwrite
the alarm IDs.
Comment 22 Jasper St. Pierre (not reading bugmail) 2013-03-25 17:51:11 UTC
Created attachment 239806 [details] [review]
idle-monitor: Don't leak the user active alarm on dispose
Comment 23 Jasper St. Pierre (not reading bugmail) 2013-03-25 17:51:14 UTC
Created attachment 239807 [details] [review]
idle-monitor: Reindent
Comment 24 Jasper St. Pierre (not reading bugmail) 2013-03-25 17:51:17 UTC
Created attachment 239808 [details] [review]
idle-monitor: Refactor code a bit

Merge two similar methods.
Comment 25 Colin Walters 2013-03-25 18:38:18 UTC
Review of attachment 239803 [details] [review]:

Looks safe and fine to me.
Comment 26 Colin Walters 2013-03-25 18:41:51 UTC
Review of attachment 239804 [details] [review]:

::: libgnome-desktop/gnome-idle-monitor.c
@@ +172,1 @@
 	}

Now we're rescheduling alarms even if we don't happen to have a watch set up for them.  The gnome-shell process has at least 3 of these.  While it's likely harmless for each Gnome.IdleMonitor to reschedule each other's user active watch, we should probably avoid it.  Right?
Comment 27 Colin Walters 2013-03-25 18:50:35 UTC
Review of attachment 239805 [details] [review]:

Looks correct.
Comment 28 Colin Walters 2013-03-25 18:50:57 UTC
Review of attachment 239806 [details] [review]:

Makes sense.
Comment 29 Colin Walters 2013-03-25 18:51:20 UTC
Review of attachment 239807 [details] [review]:

Ok.
Comment 30 Jasper St. Pierre (not reading bugmail) 2013-03-25 18:56:23 UTC
Created attachment 239812 [details] [review]
idle-monitor: Allow multiple watches for an alarm

This doesn't do anything yet as we don't have multiple watches
for one alarm, but we'll remove the special USER_ACTIVE_WATCH_ID
soon so we can have multiple watches on it.
Comment 31 Colin Walters 2013-03-25 18:56:24 UTC
Review of attachment 239808 [details] [review]:

This also looks right to me
Comment 32 Jasper St. Pierre (not reading bugmail) 2013-03-25 18:56:27 UTC
Created attachment 239813 [details] [review]
idle-monitor: Use an incrementing watch ID for the active alarm as well

This makes sure that:

    add_user_active_alarm (callback1);
    add_user_active_alarm (callback2);

doesn't remove callback1 from getting an alarm, as we won't overwrite
the alarm IDs.
Comment 33 Jasper St. Pierre (not reading bugmail) 2013-03-25 18:56:31 UTC
Created attachment 239814 [details] [review]
idle-monitor: Don't leak the user active alarm on dispose
Comment 34 Jasper St. Pierre (not reading bugmail) 2013-03-25 18:56:35 UTC
Created attachment 239815 [details] [review]
idle-monitor: Reindent
Comment 35 Jasper St. Pierre (not reading bugmail) 2013-03-25 18:56:40 UTC
Created attachment 239816 [details] [review]
idle-monitor: Refactor code a bit

Merge two similar methods.
Comment 36 Jasper St. Pierre (not reading bugmail) 2013-03-25 19:00:54 UTC
Attachment 239803 [details] pushed as 0939890 - idle-monitor: Store the monitor in the private watch struct
Attachment 239815 [details] pushed as 29f08dd - idle-monitor: Reindent


Let's push these two for now.
Comment 37 Colin Walters 2013-03-25 19:28:21 UTC
Review of attachment 239812 [details] [review]:

::: libgnome-desktop/gnome-idle-monitor.c
@@ +104,3 @@
+#else
+	return val;
+#endif

Urgh.  In practice, no system GNOME is going to run on ships with sizeof(long) < sizeof(gpointer).  Or to flip it around, only Win64 is "LLP".  If we really wanted to microoptimize, we'd probably provide a set of macros in GLib to optimize for the common case and just use NULL/g_direct_hash for 32 bit and LP64 (all known Unix variants), and only fall back to g_malloc() on Win64/LLP.

So let's drop this ugly stuff, add:
G_STATIC_ASSERT(sizeof(long) == sizeof(gpointer))
and just pass NULL, NULL to g_hash_table_new()?

@@ +328,3 @@
+		g_hash_table_destroy (monitor->priv->alarms);
+		monitor->priv->alarms = NULL;
+	}

g_clear_pointer (&monitor->priv->alarms, g_hash_table_destroy);
Comment 38 Jasper St. Pierre (not reading bugmail) 2013-03-25 20:06:28 UTC
Created attachment 239822 [details] [review]
idle-monitor: Use g_clear_pointer
Comment 39 Jasper St. Pierre (not reading bugmail) 2013-03-25 20:06:32 UTC
Created attachment 239823 [details] [review]
idle-monitor: Allow multiple watches for an alarm

This doesn't do anything yet as we don't have multiple watches
for one alarm, but we'll remove the special USER_ACTIVE_WATCH_ID
soon so we can have multiple watches on it.
Comment 40 Jasper St. Pierre (not reading bugmail) 2013-03-25 20:06:36 UTC
Created attachment 239824 [details] [review]
idle-monitor: Use an incrementing watch ID for the active alarm as well

This makes sure that:

    add_user_active_alarm (callback1);
    add_user_active_alarm (callback2);

doesn't remove callback1 from getting an alarm, as we won't overwrite
the alarm IDs.
Comment 41 Jasper St. Pierre (not reading bugmail) 2013-03-25 20:06:41 UTC
Created attachment 239825 [details] [review]
idle-monitor: Don't leak the user active alarm on dispose
Comment 42 Jasper St. Pierre (not reading bugmail) 2013-03-25 20:06:46 UTC
Created attachment 239826 [details] [review]
idle-monitor: Refactor code a bit

Merge two similar methods.
Comment 43 Colin Walters 2013-03-25 20:11:36 UTC
Review of attachment 239822 [details] [review]:

Looks good.
Comment 44 Colin Walters 2013-03-25 20:18:21 UTC
Review of attachment 239823 [details] [review]:

I only have one minor comment (and feel free to keep as is).

::: libgnome-desktop/gnome-idle-monitor.c
@@ +140,3 @@
 {
+	GnomeIdleMonitorWatch *watch = data;
+	XSyncAlarm *alarm = user_data;

Now that we're using casts we could do: XSyncAlarm alarm = (XSyncAlarm) user_data;

@@ +179,3 @@
+	g_list_foreach (watches,
+			fire_watch,
+			&alarm);

And we'd cast to (gpointer) here rather than using &.
Comment 45 Colin Walters 2013-03-25 20:19:31 UTC
Review of attachment 239824 [details] [review]:

This also looks right to me.
Comment 46 Colin Walters 2013-03-25 20:19:52 UTC
Review of attachment 239825 [details] [review]:

Right.
Comment 47 Colin Walters 2013-03-25 20:20:10 UTC
Review of attachment 239826 [details] [review]:

This one is still fine.
Comment 48 Jasper St. Pierre (not reading bugmail) 2013-03-25 21:27:25 UTC
Attachment 239822 [details] pushed as fffcc2b - idle-monitor: Use g_clear_pointer
Attachment 239823 [details] pushed as 634ef5e - idle-monitor: Allow multiple watches for an alarm
Attachment 239824 [details] pushed as 7baf585 - idle-monitor: Use an incrementing watch ID for the active alarm as well
Attachment 239825 [details] pushed as 0c60eec - idle-monitor: Don't leak the user active alarm on dispose
Attachment 239826 [details] pushed as 6654c59 - idle-monitor: Refactor code a bit
Comment 49 Colin Walters 2013-03-26 00:00:22 UTC
Created attachment 239845 [details] [review]
0001-monitor-Be-defensive-against-callbacks-unreffing-mon.patch
Comment 50 Colin Walters 2013-03-26 00:03:16 UTC
Created attachment 239846 [details] [review]
0001-monitor-Be-defensive-against-callbacks-unreffing-mon.patch

With less whitespace and a buglink
Comment 51 Jasper St. Pierre (not reading bugmail) 2013-03-26 00:16:32 UTC
Review of attachment 239846 [details] [review]:

Yes.
Comment 52 Colin Walters 2013-03-26 01:56:20 UTC
Comment on attachment 239846 [details] [review]
0001-monitor-Be-defensive-against-callbacks-unreffing-mon.patch

Ok, so I think at this point we should consider merging the patches to gnome-3-8.  Let's get r-t approval.
Comment 53 Matthias Clasen 2013-03-26 12:57:06 UTC
Patches look fine to me.

I wonder if we shouldn't have a patch to test-idle-monitor.c to test the behaviour change here, though.

Also, should there be a patch to add some details to the docs ? We've discovered quite a bit of subtle behaviour here that should really be mentioned in the docs.
Comment 54 Matthias Clasen 2013-03-26 20:28:05 UTC
cherry-picked for 3.8
Comment 55 Colin Walters 2013-03-27 17:16:36 UTC
See also https://bugzilla.gnome.org/show_bug.cgi?id=696719 for an important follow up patch.