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 677694 - optionally listen to systemd for sleeping/resuming notification
optionally listen to systemd for sleeping/resuming notification
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Dan Williams
NetworkManager maintainer(s)
Depends on:
Blocks: systemd
 
 
Reported: 2012-06-08 11:17 UTC by Matthias Clasen
Modified: 2012-10-13 14:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
factor out sleep monitor (12.28 KB, patch)
2012-06-08 11:18 UTC, Matthias Clasen
none Details | Review
systemd sleep monitor implementation (30.78 KB, patch)
2012-06-08 11:18 UTC, Matthias Clasen
none Details | Review
factor out sleep monitor (12.30 KB, patch)
2012-10-09 05:18 UTC, Matthias Clasen
none Details | Review
add a systemd sleep monitor (20.29 KB, patch)
2012-10-09 05:18 UTC, Matthias Clasen
none Details | Review

Description Matthias Clasen 2012-06-08 11:17:50 UTC
When suspend/resume are done using systemd, the upower signals never come. Here is a proof-of-concept patch.

Is build-time decision between upower or systemd good enough for you ? One could imagine writing a NmSleepMonitor implementation that monitors both systemd and upower, but that would be a bit more messy than the current approach.

Also, I couldn't figure out fd-passing with dbus-glib, so I've left the GDBus code in here. Maybe you know how do to this with dbus-glib ?
Comment 1 Matthias Clasen 2012-06-08 11:18:12 UTC
Created attachment 215930 [details] [review]
factor out sleep monitor
Comment 2 Matthias Clasen 2012-06-08 11:18:31 UTC
Created attachment 215931 [details] [review]
systemd sleep monitor implementation
Comment 3 Matthias Clasen 2012-06-08 15:18:45 UTC
Review of attachment 215931 [details] [review]:

::: src/nm-sleep-monitor-systemd.c
@@ +77,3 @@
+	GUnixFDList *fd_list;
+
+	res = g_dbus_proxy_call_with_unix_fd_list_finish (sd_proxy, &fd_list, result, &error);

Comments from davidz: res is the index in the fd_list, should actually use it like that. Ie its type will be (h)
Comment 4 Dan Williams 2012-06-08 15:58:11 UTC
I'd like to table this until Lennart gets back from hiking and can explain a bit why he designed the API with fd passing instead of just D-Bus methods and tracking when clients fall off the bus to clear their inhibitor.  Thanks for the patches though, to be continued...
Comment 5 Colin Walters 2012-06-08 16:00:53 UTC
Using timerfd_create() for a year ahead is kind of gross.  It will work, and if the goal here is to drop upower, then I think it's an OK intermediate step.

However, what we really want is to be event-driven, and schedule wakeups only for when we need to wake up.

This gets us into the question: Why exactly does NM need to be notified when the system resumes?  Looking at do_sleep_wake(),

		/* Ensure rfkill state is up-to-date since we don't respond to state
		 * changes during sleep.
		 */
		nm_manager_rfkill_update (self, RFKILL_TYPE_UNKNOWN);

Seems like this kind of thing the kernel should be fixed to check device state on resume and send out uevents?  I mean, it will send out events if a device got unplugged while suspended, right?  Why not check rfkill state too?

Then there's a lot that happens in nm_manager_update_state()...I can't say.  But I think the point stands here that the long term fix is to be driven by individual events, rather than trying to handle some global system suspend/resume event.
Comment 6 Matthias Clasen 2012-07-08 02:50:27 UTC
Alternatively, nm could install a script in /usr/lib/systemd/system-sleep like the one discussed in https://bugs.freedesktop.org/show_bug.cgi?id=51305 and get resume notification that way.
Comment 7 Matthias Clasen 2012-10-09 05:18:23 UTC
Created attachment 226098 [details] [review]
factor out sleep monitor
Comment 8 Matthias Clasen 2012-10-09 05:18:56 UTC
Created attachment 226099 [details] [review]
add a systemd sleep monitor
Comment 9 Matthias Clasen 2012-10-09 11:08:18 UTC
New patches; simplified: no more timerfd, instead we rely on the before/after emissions of PrepareForSleep. See http://www.freedesktop.org/wiki/Software/systemd/inhibit
Comment 10 Dan Williams 2012-10-12 19:33:27 UTC
Patches look good except for code style issues (indentation and {} on same line as if/else).  But I can fix that up when applying I suppose.
Comment 11 Dan Williams 2012-10-13 14:17:56 UTC
Pushed as:

64fd8eea7706038e5d38c8463a1c765ed9331db2
ea0c3a3e0fcbe400a704692d3b436d4733d348a1

Thanks!