summaryrefslogtreecommitdiff
path: root/community/lightdm/lightdm-use-login1.patch
blob: cc3d5a5fd3760986acc98555e9ab137fadc7f60e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
=== modified file 'liblightdm-gobject/power.c'
--- liblightdm-gobject/power.c	2013-01-31 20:56:09 +0000
+++ liblightdm-gobject/power.c	2013-04-15 02:21:06 +0000
@@ -17,6 +17,7 @@
 
 static GDBusProxy *upower_proxy = NULL;
 static GDBusProxy *ck_proxy = NULL;
+static GDBusProxy *login1_proxy = NULL;
 
 static gboolean
 upower_call_function (const gchar *function, gboolean default_result, GError **error)
@@ -109,11 +110,10 @@
     return upower_call_function ("Hibernate", TRUE, error);
 }
 
-static gboolean
-ck_call_function (const gchar *function, gboolean default_result, GError **error)
+static GVariant *
+ck_call_function (const gchar *function, GError **error)
 {
-    GVariant *result;
-    gboolean function_result = FALSE;
+    GVariant *r;
 
     if (!ck_proxy)
     {
@@ -129,22 +129,46 @@
             return FALSE;
     }
 
-    result = g_dbus_proxy_call_sync (ck_proxy,
-                                     function,
-                                     NULL,
-                                     G_DBUS_CALL_FLAGS_NONE,
-                                     -1,
-                                     NULL,
-                                     error);
-
-    if (!result)
-        return default_result;
-
-    if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(b)")))
-        g_variant_get (result, "(b)", &function_result);
-
-    g_variant_unref (result);
-    return function_result;
+    r = g_dbus_proxy_call_sync (ck_proxy,
+                                function,
+                                NULL,
+                                G_DBUS_CALL_FLAGS_NONE,
+                                -1,
+                                NULL,
+                                error);
+
+    return r;
+}
+
+static GVariant *
+login1_call_function (const gchar *function, GVariant *parameters, GError **error)
+{
+    GVariant *r;
+    gchar *str_result;
+
+    if (!login1_proxy)
+    {
+        login1_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                                      G_DBUS_PROXY_FLAGS_NONE,
+                                                      NULL,
+                                                      "org.freedesktop.login1",
+                                                      "/org/freedesktop/login1",
+                                                      "org.freedesktop.login1.Manager",
+                                                      NULL,
+                                                      error);
+        if (!login1_proxy)
+            return NULL;
+    }
+
+    r = g_dbus_proxy_call_sync (login1_proxy,
+                                function,
+                                parameters,
+                                G_DBUS_CALL_FLAGS_NONE,
+                                -1,
+                                NULL,
+                                error);
+
+    return r;
 }
 
 /**
@@ -157,7 +181,29 @@
 gboolean
 lightdm_get_can_restart (void)
 {
-    return ck_call_function ("CanRestart", FALSE, NULL);
+    gboolean can_restart = FALSE;
+    GVariant *r;
+
+    r = login1_call_function ("CanReboot", NULL, NULL);
+    if (r)
+    {
+        gchar *result;
+        if (g_variant_is_of_type (r, G_VARIANT_TYPE ("(s)")))
+        {
+            g_variant_get (r, "(&s)", &result);
+            can_restart = g_strcmp0 (result, "yes") == 0;
+        }
+    }
+    else
+    {
+        r = ck_call_function ("CanRestart", NULL);
+        if (r && g_variant_is_of_type (r, G_VARIANT_TYPE ("(b)")))
+            g_variant_get (r, "(b)", &can_restart);
+    }
+    if (r)
+        g_variant_unref (r);
+
+    return can_restart;
 }
 
 /**
@@ -171,7 +217,20 @@
 gboolean
 lightdm_restart (GError **error)
 {
-    return ck_call_function ("Restart", TRUE, error);
+    GVariant *r;
+    gboolean restarted;
+
+    r = login1_call_function ("Reboot", g_variant_new("(b)", FALSE), error);
+    if (!r)
+    {
+        g_clear_error (error);
+        r = ck_call_function ("Restart", error);
+    }
+    restarted = r != NULL;
+    if (r)
+        g_variant_unref (r);
+
+    return restarted;
 }
 
 /**
@@ -184,7 +243,29 @@
 gboolean
 lightdm_get_can_shutdown (void)
 {
-    return ck_call_function ("CanStop", FALSE, NULL);
+    gboolean can_shutdown = FALSE;
+    GVariant *r;
+  
+    r = login1_call_function ("CanPowerOff", NULL, NULL);
+    if (r)
+    {
+        gchar *result;
+        if (g_variant_is_of_type (r, G_VARIANT_TYPE ("(s)")))
+        {
+            g_variant_get (r, "(&s)", &result);
+            can_shutdown = g_strcmp0 (result, "yes") == 0;
+        }
+    }
+    else
+    {
+        r = ck_call_function ("CanStop", NULL);
+        if (r && g_variant_is_of_type (r, G_VARIANT_TYPE ("(b)")))
+            g_variant_get (r, "(b)", &can_shutdown);
+    }
+    if (r)
+        g_variant_unref (r);
+
+    return can_shutdown;
 }
 
 /**
@@ -198,5 +279,18 @@
 gboolean
 lightdm_shutdown (GError **error)
 {
-    return ck_call_function ("Stop", TRUE, error);
+    GVariant *r;
+    gboolean shutdown;
+
+    r = login1_call_function ("PowerOff", g_variant_new("(b)", FALSE), error);
+    if (!r)
+    {
+        g_clear_error (error);
+        r = ck_call_function ("Stop", error);
+    }
+    shutdown = r != NULL;
+    if (r)
+        g_variant_unref (r);
+
+    return shutdown;
 }

=== modified file 'liblightdm-qt/power.cpp'
--- liblightdm-qt/power.cpp	2013-02-06 14:08:25 +0000
+++ liblightdm-qt/power.cpp	2013-04-14 23:00:34 +0000
@@ -15,6 +15,7 @@
 #include <QtCore/QVariant>
 #include <QtDBus/QDBusInterface>
 #include <QtDBus/QDBusReply>
+#include <QDebug>
 
 #include "config.h"
 
@@ -26,11 +27,13 @@
     PowerInterfacePrivate();
     QScopedPointer<QDBusInterface> powerManagementInterface;
     QScopedPointer<QDBusInterface> consoleKitInterface;
+    QScopedPointer<QDBusInterface> login1Interface;
 };
 
 PowerInterface::PowerInterfacePrivate::PowerInterfacePrivate() :
     powerManagementInterface(new QDBusInterface("org.freedesktop.UPower","/org/freedesktop/UPower", "org.freedesktop.UPower", QDBusConnection::systemBus())),
-    consoleKitInterface(new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus()))
+    consoleKitInterface(new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus())),
+    login1Interface(new QDBusInterface("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", QDBusConnection::systemBus()))
 {
 }
 
@@ -80,34 +83,54 @@
 
 bool PowerInterface::canShutdown()
 {
+    if (d->login1Interface->isValid()) {
+        QDBusReply<QString> reply1 = d->login1Interface->call("CanPowerOff");
+        if (reply1.isValid()) {
+            return reply1.value() == "yes";
+        }
+    }
+    qWarning() << d->login1Interface->lastError();
+
     QDBusReply<bool> reply = d->consoleKitInterface->call("CanStop");
     if (reply.isValid()) {
         return reply.value();
     }
-    else {
-        return false;
-    }
+
+    return false;
 }
 
 void PowerInterface::shutdown()
 {
-    d->consoleKitInterface->call("Stop");
+    if (d->login1Interface->isValid())
+        d->login1Interface->call("PowerOff", false);
+    else
+        d->consoleKitInterface->call("Stop");
 }
 
 bool PowerInterface::canRestart()
 {
+    if (d->login1Interface->isValid()) {
+        QDBusReply<QString> reply1 = d->login1Interface->call("CanReboot");
+        if (reply1.isValid()) {
+            return reply1.value() == "yes";
+        }
+    }
+    qWarning() << d->login1Interface->lastError();
+  
     QDBusReply<bool> reply = d->consoleKitInterface->call("CanRestart");
     if (reply.isValid()) {
         return reply.value();
     }
-    else {
-        return false;
-    }
+
+    return false;
 }
 
 void PowerInterface::restart()
 {
-    d->consoleKitInterface->call("Restart");
+    if (d->login1Interface->isValid())
+        d->login1Interface->call("Reboot", false);
+    else
+        d->consoleKitInterface->call("Restart");
 }
 
 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)

=== modified file 'tests/Makefile.am'
--- tests/Makefile.am	2013-04-12 03:46:06 +0000
+++ tests/Makefile.am	2013-04-14 22:54:54 +0000
@@ -135,6 +135,8 @@
 	test-no-accounts-service \
 	test-console-kit \
 	test-no-console-kit \
+	test-no-login1 \
+	test-no-console-kit-or-login1 \
 	test-open-file-descriptors \
 	test-xdmcp-open-file-descriptors
 
@@ -284,8 +286,10 @@
 	scripts/no-accounts-service.conf \
 	scripts/no-config.conf \
 	scripts/no-console-kit.conf \
+	scripts/no-console-kit-or-login1.conf \
 	scripts/no-keyboard-layout.conf \
 	scripts/no-language.conf \
+	scripts/no-login1.conf \
 	scripts/open-file-descriptors.conf \
 	scripts/pam.conf \
 	scripts/plymouth-active-vt.conf \

=== added file 'tests/scripts/no-console-kit-or-login1.conf'
--- tests/scripts/no-console-kit-or-login1.conf	1970-01-01 00:00:00 +0000
+++ tests/scripts/no-console-kit-or-login1.conf	2013-04-14 22:54:54 +0000
@@ -0,0 +1,34 @@
+#
+# Check still works when neither ConsoleKit or login1 is available
+#
+
+[test-runner-config]
+disable-console-kit=true
+disable-login1=true
+
+[LightDM]
+minimum-display-number=50
+
+[SeatDefaults]
+autologin-user=have-password1
+
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER :50 START
+#?XSERVER :50 INDICATE-READY
+
+# LightDM connects to X server
+#?XSERVER :50 ACCEPT-CONNECT
+
+# Session starts
+#?SESSION :50 START USER=have-password1
+#?XSERVER :50 ACCEPT-CONNECT
+#?SESSION :50 CONNECT-XSERVER
+
+# Cleanup
+#?*STOP-DAEMON
+# Don't know what order they will terminate
+#?(SESSION :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?(SESSION :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?RUNNER DAEMON-EXIT STATUS=0

=== added file 'tests/scripts/no-login1.conf'
--- tests/scripts/no-login1.conf	1970-01-01 00:00:00 +0000
+++ tests/scripts/no-login1.conf	2013-04-14 22:54:54 +0000
@@ -0,0 +1,33 @@
+#
+# Check still works when login1 is not available
+#
+
+[test-runner-config]
+disable-login1=true
+
+[LightDM]
+minimum-display-number=50
+
+[SeatDefaults]
+autologin-user=have-password1
+
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER :50 START
+#?XSERVER :50 INDICATE-READY
+
+# LightDM connects to X server
+#?XSERVER :50 ACCEPT-CONNECT
+
+# Session starts
+#?SESSION :50 START USER=have-password1
+#?XSERVER :50 ACCEPT-CONNECT
+#?SESSION :50 CONNECT-XSERVER
+
+# Cleanup
+#?*STOP-DAEMON
+# Don't know what order they will terminate
+#?(SESSION :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?(SESSION :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?RUNNER DAEMON-EXIT STATUS=0

=== modified file 'tests/src/test-runner.c'
--- tests/src/test-runner.c	2013-03-27 00:48:48 +0000
+++ tests/src/test-runner.c	2013-04-14 22:54:54 +0000
@@ -1464,6 +1464,101 @@ accounts_user_set_hidden (AccountsUser *
 }
 
 static void
+handle_login1_call (GDBusConnection       *connection,
+                    const gchar           *sender,
+                    const gchar           *object_path,
+                    const gchar           *interface_name,
+                    const gchar           *method_name,
+                    GVariant              *parameters,
+                    GDBusMethodInvocation *invocation,
+                    gpointer               user_data)
+{
+    if (strcmp (method_name, "CanReboot") == 0)
+        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));
+    else if (strcmp (method_name, "Reboot") == 0)
+    {
+        gboolean interactive;
+        g_variant_get (parameters, "(b)", &interactive);
+        g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
+    }
+    if (strcmp (method_name, "CanPowerOff") == 0)
+        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));
+    else if (strcmp (method_name, "PowerOff") == 0)
+    {
+        gboolean interactive;
+        g_variant_get (parameters, "(b)", &interactive);
+        g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
+    }
+    else
+        g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);
+}
+
+static void
+login1_name_acquired_cb (GDBusConnection *connection,
+                         const gchar     *name,
+                         gpointer         user_data)
+{
+    const gchar *login1_interface =
+        "<node>"
+        "  <interface name='org.freedesktop.login1.Manager'>"
+        "    <method name='CanReboot'>"
+        "      <arg name='result' direction='out' type='s'/>"
+        "    </method>"
+        "    <method name='Reboot'>"
+        "      <arg name='interactive' direction='in' type='b'/>"
+        "    </method>"
+        "    <method name='CanPowerOff'>"
+        "      <arg name='result' direction='out' type='s'/>"
+        "    </method>"
+        "    <method name='PowerOff'>"
+        "      <arg name='interactive' direction='in' type='b'/>"
+        "    </method>"
+        "  </interface>"
+        "</node>";
+    static const GDBusInterfaceVTable login1_vtable =
+    {
+        handle_login1_call,
+    };
+    GDBusNodeInfo *login1_info;
+    GError *error = NULL;
+
+    login1_info = g_dbus_node_info_new_for_xml (login1_interface, &error);
+    if (error)
+        g_warning ("Failed to parse D-Bus interface: %s", error->message);  
+    g_clear_error (&error);
+    if (!login1_info)
+        return;
+    g_dbus_connection_register_object (connection,
+                                       "/org/freedesktop/login1",
+                                       login1_info->interfaces[0],
+                                       &login1_vtable,
+                                       NULL, NULL,
+                                       &error);
+    if (error)
+        g_warning ("Failed to register login1 service: %s", error->message);
+    g_clear_error (&error);
+    g_dbus_node_info_unref (login1_info);
+
+    service_count--;
+    if (service_count == 0)
+        run_lightdm ();
+}
+
+static void
+start_login1_daemon ()
+{
+    service_count++;
+    g_bus_own_name (G_BUS_TYPE_SYSTEM,
+                    "org.freedesktop.login1",
+                    G_BUS_NAME_OWNER_FLAGS_NONE,
+                    login1_name_acquired_cb,
+                    NULL,
+                    NULL,
+                    NULL,
+                    NULL);
+}
+
+static void
 load_passwd_file (void)
 {
     gchar *path, *data, **lines;

=== added file 'tests/test-no-console-kit-or-login1'
--- tests/test-no-console-kit-or-login1	1970-01-01 00:00:00 +0000
+++ tests/test-no-console-kit-or-login1	2013-04-14 22:54:54 +0000
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner no-console-kit-or-login1 test-gobject-greeter

=== added file 'tests/test-no-login1'
--- tests/test-no-login1	1970-01-01 00:00:00 +0000
+++ tests/test-no-login1	2013-04-14 22:54:54 +0000
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner no-login1 test-gobject-greeter