Gentoo Archives: gentoo-commits

From: "Samuli Suominen (ssuominen)" <ssuominen@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in xfce-base/xfce4-session/files: xfce4-session-4.11.0-upower-0.99.0.patch
Date: Tue, 08 Jul 2014 13:58:44
Message-Id: 20140708135839.1F25F2004E@flycatcher.gentoo.org
1 ssuominen 14/07/08 13:58:39
2
3 Added: xfce4-session-4.11.0-upower-0.99.0.patch
4 Log:
5 Use updated UPower 0.99.0 patch from http://bugzilla.xfce.org/show_bug.cgi?id=9952#c20
6
7 (Portage version: 2.2.10/cvs/Linux x86_64, signed Manifest commit with key 4868F14D)
8
9 Revision Changes Path
10 1.1 xfce-base/xfce4-session/files/xfce4-session-4.11.0-upower-0.99.0.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/xfce-base/xfce4-session/files/xfce4-session-4.11.0-upower-0.99.0.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/xfce-base/xfce4-session/files/xfce4-session-4.11.0-upower-0.99.0.patch?rev=1.1&content-type=text/plain
14
15 Index: xfce4-session-4.11.0-upower-0.99.0.patch
16 ===================================================================
17 Patch from http://bugzilla.xfce.org/show_bug.cgi?id=9952 with modification
18 to edit configure.ac (release tarball) instead of configure.ac.in (git)
19
20 From 38afe446cdc889266f1e553952397cc4a876ecf8 Mon Sep 17 00:00:00 2001
21 From: Eric Koegel <eric.koegel@×××××.com>
22 Date: Mon, 7 Jul 2014 11:30:06 +0300
23 Subject: [PATCH] Add suspend/hibernate to shutdown-helper
24
25 Upower 0.99 dropped support for suspend/hibernate as an obsolete
26 feature in this commit:
27 http://cgit.freedesktop.org/upower/commit/?id=1ee642e705a63f5ad56a6b55e4bf5c4a64c959b8
28 Add that functionality into the shutdown-helper so these features
29 will work again. Additionally Upower is an optional build dependency
30 and the minimum required is 0.9.7 to support FreeBSD 9 and 10.
31 ---
32 configure.ac.in | 30 ++++++++
33 xfce4-session/Makefile.am | 4 +-
34 xfce4-session/xfsm-shutdown.c | 167 +++++++++++++++++++++++++++++++++++++++++-
35 xfce4-session/xfsm-upower.c | 8 +-
36 xfce4-session/xfsm-upower.h | 4 +
37 xfsm-shutdown-helper/main.c | 26 +++++++
38 6 files changed, 234 insertions(+), 5 deletions(-)
39
40 diff --git a/configure.ac b/configure.ac
41 index 910fd35..b9c9a90 100644
42 --- a/configure.ac
43 +++ b/configure.ac
44 @@ -96,6 +96,10 @@ XDT_CHECK_PACKAGE([DBUS], [dbus-1], [1.1.0])
45 XDT_CHECK_PACKAGE([DBUS_GLIB], [dbus-glib-1], [0.84])
46 XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.9.0])
47
48 +dnl Check for Upower
49 +XDT_CHECK_OPTIONAL_PACKAGE([UPOWER],[upower-glib], [0.9.7],
50 + [upower],[Upower support])
51 +
52 dnl Check for polkit / systemd integration
53 XDT_CHECK_OPTIONAL_PACKAGE([SYSTEMD], [polkit-gobject-1], [0.100],
54 [systemd], [Systemd support (through polit)])
55 @@ -157,6 +161,31 @@ if test "x$linux_ioprio_works" = "xyes"; then
56 [Defined if linux/ioprio.h not only exists, but works properly])
57 fi
58
59 +dnl Compile time default choice of backend
60 +AC_ARG_WITH([backend],
61 + AS_HELP_STRING([--with-backend=<option>],
62 + [Default backend to use linux, freebsd, openbsd]))
63 +# default to a sane option
64 +AC_CANONICAL_HOST
65 +if test x$with_backend = x; then
66 + AS_CASE([$host],
67 + [*-linux*], [with_backend=linux],
68 + [*-*freebsd*], [with_backend=freebsd],
69 + [*-openbsd*], [with_backend=openbsd])
70 +fi
71 +AC_DEFINE_UNQUOTED(BACKEND, "$with_backend", [backend])
72 +AC_SUBST(BACKEND, "$with_backend")
73 +
74 +if test x$with_backend = xlinux; then
75 + AC_DEFINE(BACKEND_TYPE_LINUX, 1, [Linux suspend/hibernate backend])
76 +fi
77 +if test x$with_backend = xfreebsd; then
78 + AC_DEFINE(BACKEND_TYPE_FREEBSD, 1, [FreeBSD suspend/hibernate backend])
79 +fi
80 +if test x$with_backend = xopenbsd; then
81 + AC_DEFINE(BACKEND_TYPE_OPENBSD, 1, [OpenBSD suspend/hibernate backend])
82 +fi
83 +
84 dnl check for location Xfce glade files were installed to
85 XFCE_GLADE_CATALOG_PATH="`pkg-config --variable glade_catalogdir libxfce4ui-1`"
86 XFCE_GLADE_PIXMAP_PATH="`pkg-config --variable glade_pixmapdir libxfce4ui-1`"
87 @@ -207,5 +236,6 @@ echo " * Gnome Keyring support: yes"
88 else
89 echo " * Gnome Keyring support: no"
90 fi
91 +echo " * Backend: ${with_backend}"
92
93 echo
94 diff --git a/xfce4-session/Makefile.am b/xfce4-session/Makefile.am
95 index 5472b33..6b5968e 100644
96 --- a/xfce4-session/Makefile.am
97 +++ b/xfce4-session/Makefile.am
98 @@ -83,7 +83,8 @@ xfce4_session_CFLAGS = \
99 $(SYSTEMD_CFLAGS) \
100 $(XFCONF_CFLAGS) \
101 $(GMODULE_CFLAGS) \
102 - $(PLATFORM_CFLAGS)
103 + $(PLATFORM_CFLAGS) \
104 + $(UPOWER_CFLAGS)
105
106 xfce4_session_LDFLAGS = \
107 -no-undefined \
108 @@ -102,6 +103,7 @@ xfce4_session_LDADD = \
109 $(LIBWNCK_LIBS) \
110 $(SYSTEMD_LIBS) \
111 $(XFCONF_LIBS) \
112 + $(UPOWER_LIBS) \
113 -lm
114
115 xfce4_session_DEPENDENCIES = \
116 diff --git a/xfce4-session/xfsm-shutdown.c b/xfce4-session/xfsm-shutdown.c
117 index 4c483a7..24b548e 100644
118 --- a/xfce4-session/xfsm-shutdown.c
119 +++ b/xfce4-session/xfsm-shutdown.c
120 @@ -57,6 +57,9 @@
121 #include <dbus/dbus-glib-lowlevel.h>
122 #include <libxfce4util/libxfce4util.h>
123 #include <gtk/gtk.h>
124 +#ifdef HAVE_UPOWER
125 +#include <upower.h>
126 +#endif
127
128 #include <libxfsm/xfsm-util.h>
129
130 @@ -76,6 +79,8 @@
131
132 static void xfsm_shutdown_finalize (GObject *object);
133 static void xfsm_shutdown_sudo_free (XfsmShutdown *shutdown);
134 +static gboolean xfsm_shutdown_fallback_can_hibernate (void);
135 +static gboolean xfsm_shutdown_fallback_can_suspend (void);
136
137
138
139 @@ -403,14 +408,16 @@ xfsm_shutdown_sudo_try_action (XfsmShutdown *shutdown,
140 g_return_val_if_fail (shutdown->helper_state == SUDO_AVAILABLE, FALSE);
141 g_return_val_if_fail (shutdown->helper_outfile != NULL, FALSE);
142 g_return_val_if_fail (shutdown->helper_infile != NULL, FALSE);
143 - g_return_val_if_fail (type == XFSM_SHUTDOWN_SHUTDOWN
144 - || type == XFSM_SHUTDOWN_RESTART, FALSE);
145
146 /* the command we send to sudo */
147 if (type == XFSM_SHUTDOWN_SHUTDOWN)
148 action = "POWEROFF";
149 else if (type == XFSM_SHUTDOWN_RESTART)
150 action = "REBOOT";
151 + else if (type == XFSM_SHUTDOWN_SUSPEND)
152 + action = "SUSPEND";
153 + else if (type == XFSM_SHUTDOWN_HIBERNATE)
154 + action = "HIBERNATE";
155 else
156 return FALSE;
157
158 @@ -692,7 +699,19 @@ xfsm_shutdown_try_suspend (XfsmShutdown *shutdown,
159 {
160 g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
161
162 +#ifdef HAVE_UPOWER
163 +#if !UP_CHECK_VERSION(0, 99, 0)
164 return xfsm_upower_try_suspend (shutdown->upower, error);
165 +#endif /* UP_CHECK_VERSION */
166 +#endif /* HAVE_UPOWER */
167 +
168 + if (shutdown->helper_state == SUDO_AVAILABLE)
169 + {
170 + xfsm_upower_lock_screen (shutdown->upower, "Suspend", error);
171 + return xfsm_shutdown_sudo_try_action (shutdown, XFSM_SHUTDOWN_SUSPEND, error);
172 + }
173 + else
174 + return FALSE;
175 }
176
177
178 @@ -703,7 +722,19 @@ xfsm_shutdown_try_hibernate (XfsmShutdown *shutdown,
179 {
180 g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
181
182 +#ifdef HAVE_UPOWER
183 +#if !UP_CHECK_VERSION(0, 99, 0)
184 return xfsm_upower_try_hibernate (shutdown->upower, error);
185 +#endif /* UP_CHECK_VERSION */
186 +#endif /* HAVE_UPOWER */
187 +
188 + if (shutdown->helper_state == SUDO_AVAILABLE)
189 + {
190 + xfsm_upower_lock_screen (shutdown->upower, "Hibernate", error);
191 + return xfsm_shutdown_sudo_try_action (shutdown, XFSM_SHUTDOWN_HIBERNATE, error);
192 + }
193 + else
194 + return FALSE;
195 }
196
197
198 @@ -784,8 +815,15 @@ xfsm_shutdown_can_suspend (XfsmShutdown *shutdown,
199 return TRUE;
200 }
201
202 +#ifdef HAVE_UPOWER
203 +#if !UP_CHECK_VERSION(0, 99, 0)
204 return xfsm_upower_can_suspend (shutdown->upower, can_suspend,
205 auth_suspend, error);
206 +#endif /* UP_CHECK_VERSION */
207 +#endif /* HAVE_UPOWER */
208 +
209 + *can_suspend = xfsm_shutdown_fallback_can_suspend ();
210 + return TRUE;
211 }
212
213
214 @@ -804,8 +842,15 @@ xfsm_shutdown_can_hibernate (XfsmShutdown *shutdown,
215 return TRUE;
216 }
217
218 +#ifdef HAVE_UPOWER
219 +#if !UP_CHECK_VERSION(0, 99, 0)
220 return xfsm_upower_can_hibernate (shutdown->upower, can_hibernate,
221 auth_hibernate, error);
222 +#endif /* UP_CHECK_VERSION */
223 +#endif /* HAVE_UPOWER */
224 +
225 + *can_hibernate = xfsm_shutdown_fallback_can_hibernate ();
226 + return TRUE;
227 }
228
229
230 @@ -816,3 +861,121 @@ xfsm_shutdown_can_save_session (XfsmShutdown *shutdown)
231 g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
232 return shutdown->kiosk_can_save_session;
233 }
234 +
235 +
236 +
237 +#ifdef BACKEND_TYPE_FREEBSD
238 +static gchar *
239 +get_string_sysctl (GError **err, const gchar *format, ...)
240 +{
241 + va_list args;
242 + gchar *name;
243 + size_t value_len;
244 + gchar *str = NULL;
245 +
246 + g_return_val_if_fail(format != NULL, FALSE);
247 +
248 + va_start (args, format);
249 + name = g_strdup_vprintf (format, args);
250 + va_end (args);
251 +
252 + if (sysctlbyname (name, NULL, &value_len, NULL, 0) == 0) {
253 + str = g_new (char, value_len + 1);
254 + if (sysctlbyname (name, str, &value_len, NULL, 0) == 0)
255 + str[value_len] = 0;
256 + else {
257 + g_free (str);
258 + str = NULL;
259 + }
260 + }
261 +
262 + if (!str)
263 + g_set_error (err, 0, 0, "%s", g_strerror(errno));
264 +
265 + g_free(name);
266 + return str;
267 +}
268 +
269 +
270 +
271 +static gboolean
272 +freebsd_supports_sleep_state (const gchar *state)
273 +{
274 + gboolean ret = FALSE;
275 + gchar *sleep_states;
276 +
277 + sleep_states = get_string_sysctl (NULL, "hw.acpi.supported_sleep_state");
278 + if (sleep_states != NULL)
279 + {
280 + if (strstr (sleep_states, state) != NULL)
281 + ret = TRUE;
282 + }
283 +
284 + g_free (sleep_states);
285 +
286 + return ret;
287 +}
288 +#endif /* BACKEND_TYPE_FREEBSD */
289 +
290 +
291 +
292 +#ifdef BACKEND_TYPE_LINUX
293 +static gboolean
294 +linux_supports_sleep_state (const gchar *state)
295 +{
296 + gboolean ret = FALSE;
297 + gchar *command;
298 + GError *error = NULL;
299 + gint exit_status;
300 +
301 + /* run script from pm-utils */
302 + command = g_strdup_printf ("/usr/bin/pm-is-supported --%s", state);
303 +
304 + ret = g_spawn_command_line_sync (command, NULL, NULL, &exit_status, &error);
305 + if (!ret)
306 + {
307 + g_warning ("failed to run script: %s", error->message);
308 + g_error_free (error);
309 + goto out;
310 + }
311 + ret = (WIFEXITED(exit_status) && (WEXITSTATUS(exit_status) == EXIT_SUCCESS));
312 +
313 +out:
314 + g_free (command);
315 +
316 + return ret;
317 +}
318 +#endif /* BACKEND_TYPE_LINUX */
319 +
320 +
321 +static gboolean
322 +xfsm_shutdown_fallback_can_suspend (void)
323 +{
324 +#ifdef BACKEND_TYPE_FREEBSD
325 + return freebsd_supports_sleep_state ("S3");
326 +#endif
327 +#ifdef BACKEND_TYPE_LINUX
328 + return linux_supports_sleep_state ("suspend");
329 +#endif
330 +#ifdef BACKEND_TYPE_OPENBSD
331 + return TRUE;
332 +#endif
333 +
334 + return FALSE;
335 +}
336 +
337 +static gboolean
338 +xfsm_shutdown_fallback_can_hibernate (void)
339 +{
340 +#ifdef BACKEND_TYPE_FREEBSD
341 + return freebsd_supports_sleep_state ("S4");
342 +#endif
343 +#ifdef BACKEND_TYPE_LINUX
344 + return linux_supports_sleep_state ("hibernate");
345 +#endif
346 +#ifdef BACKEND_TYPE_OPENBSD
347 + return FALSE;
348 +#endif
349 +
350 + return FALSE;
351 +}
352 diff --git a/xfce4-session/xfsm-upower.c b/xfce4-session/xfsm-upower.c
353 index 57402ec..2960943 100644
354 --- a/xfce4-session/xfsm-upower.c
355 +++ b/xfce4-session/xfsm-upower.c
356 @@ -21,6 +21,7 @@
357
358 #include <dbus/dbus-glib.h>
359 #include <dbus/dbus-glib-lowlevel.h>
360 +#include <upower.h>
361
362 #include <libxfsm/xfsm-util.h>
363 #include <xfce4-session/xfsm-upower.h>
364 @@ -283,14 +284,13 @@ xfsm_upower_try_method (XfsmUPower *upower,
365
366
367
368 -static gboolean
369 +gboolean
370 xfsm_upower_lock_screen (XfsmUPower *upower,
371 const gchar *sleep_kind,
372 GError **error)
373 {
374 XfconfChannel *channel;
375 gboolean ret = TRUE;
376 - GError *err = NULL;
377
378 g_return_val_if_fail (sleep_kind != NULL, FALSE);
379
380 @@ -299,6 +299,9 @@ xfsm_upower_lock_screen (XfsmUPower *upower,
381 {
382 if (xfsm_upower_proxy_ensure (upower, error))
383 {
384 +#if !UP_CHECK_VERSION(0, 99, 0)
385 + GError *err = NULL;
386 +
387 /* tell upower we're going to sleep, this saves some
388 * time while we sleep 1 second if xflock4 is spawned */
389 ret = dbus_g_proxy_call (upower->upower_proxy,
390 @@ -312,6 +315,7 @@ xfsm_upower_lock_screen (XfsmUPower *upower,
391 g_warning ("Couldn't sent that we were about to sleep: %s", err->message);
392 g_error_free (err);
393 }
394 +#endif
395 }
396 else
397 {
398 diff --git a/xfce4-session/xfsm-upower.h b/xfce4-session/xfsm-upower.h
399 index a492f7d..4e6a53b 100644
400 --- a/xfce4-session/xfsm-upower.h
401 +++ b/xfce4-session/xfsm-upower.h
402 @@ -51,4 +51,8 @@ gboolean xfsm_upower_can_hibernate (XfsmUPower *upower,
403 gboolean *auth_hibernate,
404 GError **error);
405
406 +gboolean xfsm_upower_lock_screen (XfsmUPower *upower,
407 + const gchar *sleep_kind,
408 + GError **error);
409 +
410 #endif /* !__XFSM_UPOWER_HELPER_H__ */
411 diff --git a/xfsm-shutdown-helper/main.c b/xfsm-shutdown-helper/main.c
412 index 667f288..60c621b 100644
413 --- a/xfsm-shutdown-helper/main.c
414 +++ b/xfsm-shutdown-helper/main.c
415 @@ -57,6 +57,12 @@
416 #ifdef REBOOT_CMD
417 #undef REBOOT_CMD
418 #endif
419 +#ifdef UP_BACKEND_SUSPEND_COMMAND
420 +#undef UP_BACKEND_SUSPEND_COMMAND
421 +#endif
422 +#ifdef UP_BACKEND_HIBERNATE_COMMAND
423 +#undef UP_BACKEND_HIBERNATE_COMMAND
424 +#endif
425
426 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
427 #define POWEROFF_CMD "/sbin/shutdown -p now"
428 @@ -68,6 +74,18 @@
429 #define POWEROFF_CMD "/sbin/shutdown -h now"
430 #define REBOOT_CMD "/sbin/shutdown -r now"
431 #endif
432 +#ifdef BACKEND_TYPE_FREEBSD
433 +#define UP_BACKEND_SUSPEND_COMMAND "/usr/sbin/zzz"
434 +#define UP_BACKEND_HIBERNATE_COMMAND "/usr/sbin/acpiconf -s 4"
435 +#endif
436 +#if BACKEND_TYPE_LINUX
437 +#define UP_BACKEND_SUSPEND_COMMAND "/usr/sbin/pm-suspend"
438 +#define UP_BACKEND_HIBERNATE_COMMAND "/usr/sbin/pm-hibernate"
439 +#endif
440 +#ifdef BACKEND_TYPE_OPENBSD
441 +#define UP_BACKEND_SUSPEND_COMMAND "/usr/sbin/zzz"
442 +#define UP_BACKEND_HIBERNATE_COMMAND "/dev/null"
443 +#endif
444
445
446 static gboolean
447 @@ -143,6 +161,14 @@ main (int argc, char **argv)
448 {
449 succeed = run (REBOOT_CMD);
450 }
451 + else if (strncasecmp (action, "SUSPEND", 7) == 0)
452 + {
453 + succeed = run (UP_BACKEND_SUSPEND_COMMAND);
454 + }
455 + else if (strncasecmp (action, "HIBERNATE", 9) == 0)
456 + {
457 + succeed = run (UP_BACKEND_HIBERNATE_COMMAND);
458 + }
459
460 if (succeed)
461 {
462 --
463 2.0.0