Merge lp:~laney/lightdm/logind into lp:lightdm

Proposed by Iain Lane
Status: Merged
Approved by: Robert Ancell
Approved revision: 1673
Merged at revision: 1651
Proposed branch: lp:~laney/lightdm/logind
Merge into: lp:lightdm
Diff against target: 1350 lines (+577/-159)
14 files modified
liblightdm-gobject/power.c (+110/-67)
liblightdm-qt/power.cpp (+34/-2)
src/Makefile.am (+2/-0)
src/login1.c (+137/-0)
src/login1.h (+29/-0)
src/session-child.c (+43/-28)
src/session.c (+40/-20)
src/xauthority.c (+1/-1)
src/xserver-local.c (+1/-0)
tests/scripts/console-kit.conf (+3/-0)
tests/scripts/power-no-console-kit.conf (+4/-4)
tests/scripts/power.conf (+4/-4)
tests/src/libsystem.c (+1/-0)
tests/src/test-runner.c (+168/-33)
To merge this branch: bzr merge lp:~laney/lightdm/logind
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Robert Ancell Needs Fixing
Review via email: mp+160089@code.launchpad.net

Commit message

Use everywhere instead of UPower and ConsoleKit - lock/unlock/suspend/hibernate.

Description of the change

Fully use logind in preference to ConsoleKit and UPower, since these two are both deprecated. This adds support for both logging in with logind tracking the session, without CK, and for using logind to suspend/resume in addition to reboot/shutdown that was recently merged to trunk.

We don't need to explicitly register the session with logind, since this is handled by the PAM module for us.

I also fixed some small problems that were mostly caught by -Wall -Werror.

I'm not entirely sure about the test coverage, so please review that closely.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:1668
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~laney/lightdm/logind/+merge/160089/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/lightdm-ci/23/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/lightdm-raring-amd64-ci/17

Click here to trigger a rebuild:
http://s-jenkins:8080/job/lightdm-ci/23/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:1668
http://jenkins.qa.ubuntu.com/job/lightdm-ci/24/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/lightdm-raring-amd64-ci/18

Click here to trigger a rebuild:
http://s-jenkins:8080/job/lightdm-ci/24/rebuild

review: Approve (continuous-integration)
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Thanks Iain!

The tests are wrong:
- You don't need to add a login1 test as it does nothing different to an autologin test, by default all logins will now uses login1 so all the other tests cover this.
- You need to add back the no-login1 and no-console-kit tests - these test that you can still log in if these services are not available. By removing them there's no checking for these cases

I think this should say "using login1". This should not be considered an error, use g_debug.

105 + g_printerr ("Can't suspend using lightdm; falling back to UPower: %s",
106 + (*error)->message);

174 + g_printerr ("Can't hibernate using lightdm; falling back to UPower: %s",
175 + (*error)->message);

Should be inside login1.h, not session.h. Also would prefer to be a function instead of a macro.

677 +#define LOGIND_RUNNING() (access ("/run/systemd/seats/", F_OK) >= 0)

Some minor issues using two spaces for indentation instead of four, use of // for comments instead of /* */.

Revision history for this message
Robert Ancell (robert-ancell) :
review: Needs Fixing
lp:~laney/lightdm/logind updated
1669. By Iain Lane

Fix copy and paste errors

 - Can't suspend using lightdm → logind
 - g_printerr → g_debug in above message; there is a fallback.

1670. By Iain Lane

Whitespace fixes

I'm sure there's more.

1671. By Iain Lane

Move LOGIND_RUNNING to login1.h

1672. By Iain Lane

Another comment fix

1673. By Iain Lane

Readd no-login1 and no-console-kit tests, remove login1 test.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:1673
http://jenkins.qa.ubuntu.com/job/lightdm-ci/26/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/lightdm-raring-amd64-ci/20

Click here to trigger a rebuild:
http://s-jenkins:8080/job/lightdm-ci/26/rebuild

review: Approve (continuous-integration)
Revision history for this message
Iain Lane (laney) wrote :

Hi, thanks for the review.

On Mon, Apr 22, 2013 at 11:23:25PM -0000, Robert Ancell wrote:
> Thanks Iain!
>
> The tests are wrong:
> - You don't need to add a login1 test as it does nothing different to an autologin test, by default all logins will now uses login1 so all the other tests cover this.
> - You need to add back the no-login1 and no-console-kit tests - these test that you can still log in if these services are not available. By removing them there's no checking for these cases

The no-console-kit test was the same as the login1 test. I'll put back the
other name though. I think that came from cavalier's branch.

laney@raring> diff -u no-console-kit.conf login1.conf
--- no-console-kit.conf 2013-04-23 15:18:55.722670000 +0100
+++ login1.conf 2013-04-22 12:05:01.628529093 +0100
@@ -1,5 +1,5 @@
 #
-# Check still works when ConsoleKit is not available
+# Check session can start with logind
 #

 [test-runner-config]

I think that test-no-login1 is the same as test-console-kit? Except with the
difference that console-kit checkes for the cookie being set too.

I have made these changes though; you can fix it up later on if you like.

>
> I think this should say "using login1". This should not be considered an error, use g_debug.
>
> 105 + g_printerr ("Can't suspend using lightdm; falling back to UPower: %s",
> 106 + (*error)->message);
>
> 174 + g_printerr ("Can't hibernate using lightdm; falling back to UPower: %s",
> 175 + (*error)->message);

Fixed. Thanks, good catch - copy&paste error.

>
> Should be inside login1.h, not session.h. Also would prefer to be a function instead of a macro.
>
> 677 +#define LOGIND_RUNNING() (access ("/run/systemd/seats/", F_OK) >= 0)

Moved but I've left it as a macro - this seems to be the standard way being
implemented in GNOME and other places, advocated by pitti and Lennart.

  https://mail.gnome.org/archives/desktop-devel-list/2013-March/msg00092.html

>
> Some minor issues using two spaces for indentation instead of four, use of // for comments instead of /* */.

Fixed some whitespace errors that I (and emacs) found. Not sure I caught them
all though.

--
Iain Lane [ <email address hidden> ]
Debian Developer [ <email address hidden> ]
Ubuntu Developer [ <email address hidden> ]

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'liblightdm-gobject/power.c'
--- liblightdm-gobject/power.c 2013-04-15 03:06:52 +0000
+++ liblightdm-gobject/power.c 2013-04-23 14:46:29 +0000
@@ -22,8 +22,6 @@
22static GVariant *22static GVariant *
23upower_call_function (const gchar *function, GError **error)23upower_call_function (const gchar *function, GError **error)
24{24{
25 GVariant *result;
26
27 if (!upower_proxy)25 if (!upower_proxy)
28 {26 {
29 upower_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,27 upower_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
@@ -47,6 +45,36 @@
47 error);45 error);
48}46}
4947
48static GVariant *
49login1_call_function (const gchar *function, GVariant *parameters, GError **error)
50{
51 GVariant *r;
52
53 if (!login1_proxy)
54 {
55 login1_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
56 G_DBUS_PROXY_FLAGS_NONE,
57 NULL,
58 "org.freedesktop.login1",
59 "/org/freedesktop/login1",
60 "org.freedesktop.login1.Manager",
61 NULL,
62 error);
63 if (!login1_proxy)
64 return NULL;
65 }
66
67 r = g_dbus_proxy_call_sync (login1_proxy,
68 function,
69 parameters,
70 G_DBUS_CALL_FLAGS_NONE,
71 -1,
72 NULL,
73 error);
74
75 return r;
76}
77
50/**78/**
51 * lightdm_get_can_suspend:79 * lightdm_get_can_suspend:
52 *80 *
@@ -57,16 +85,27 @@
57gboolean85gboolean
58lightdm_get_can_suspend (void)86lightdm_get_can_suspend (void)
59{87{
60 GVariant *result;
61 gboolean can_suspend = FALSE;88 gboolean can_suspend = FALSE;
6289 GVariant *r;
63 result = upower_call_function ("SuspendAllowed", NULL);90
64 if (!result)91 r = login1_call_function ("CanSuspend", NULL, NULL);
65 return FALSE;92 if (r)
6693 {
67 if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(b)")))94 gchar *result;
68 g_variant_get (result, "(b)", &can_suspend);95 if (g_variant_is_of_type (r, G_VARIANT_TYPE ("(s)")))
69 g_variant_unref (result);96 {
97 g_variant_get (r, "(&s)", &result);
98 can_suspend = g_strcmp0 (result, "yes") == 0;
99 }
100 }
101 else
102 {
103 r = upower_call_function ("SuspendAllowed", NULL);
104 if (r && g_variant_is_of_type (r, G_VARIANT_TYPE ("(b)")))
105 g_variant_get (r, "(b)", &can_suspend);
106 }
107 if (r)
108 g_variant_unref (r);
70109
71 return can_suspend;110 return can_suspend;
72}111}
@@ -76,21 +115,33 @@
76 * @error: return location for a #GError, or %NULL115 * @error: return location for a #GError, or %NULL
77 *116 *
78 * Triggers a system suspend.117 * Triggers a system suspend.
79 * 118 *
80 * Return value: #TRUE if suspend initiated.119 * Return value: #TRUE if suspend initiated.
81 **/120 **/
82gboolean121gboolean
83lightdm_suspend (GError **error)122lightdm_suspend (GError **error)
84{123{
85 GVariant *result;124 GVariant *result;
86 125 gboolean suspended;
87 result = upower_call_function ("Suspend", error);126
127 result = login1_call_function ("Suspend", g_variant_new("(b)", FALSE),
128 error);
129
88 if (!result)130 if (!result)
89 return FALSE;131 {
90132 if (error)
91 g_variant_unref (result);133 g_debug ("Can't suspend using logind; falling back to UPower: %s",
92134 (*error)->message);
93 return TRUE;135 g_clear_error (error);
136 result = upower_call_function ("Suspend", error);
137 }
138
139 suspended = result != NULL;
140 if (result)
141 g_variant_unref (result);
142
143 return suspended;
144
94}145}
95146
96/**147/**
@@ -103,16 +154,27 @@
103gboolean154gboolean
104lightdm_get_can_hibernate (void)155lightdm_get_can_hibernate (void)
105{156{
106 GVariant *result;
107 gboolean can_hibernate = FALSE;157 gboolean can_hibernate = FALSE;
108 158 GVariant *r;
109 result = upower_call_function ("HibernateAllowed", NULL);
110 if (!result)
111 return FALSE;
112159
113 if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(b)")))160 r = login1_call_function ("CanHibernate", NULL, NULL);
114 g_variant_get (result, "(b)", &can_hibernate);161 if (r)
115 g_variant_unref (result);162 {
163 gchar *result;
164 if (g_variant_is_of_type (r, G_VARIANT_TYPE ("(s)")))
165 {
166 g_variant_get (r, "(&s)", &result);
167 can_hibernate = g_strcmp0 (result, "yes") == 0;
168 }
169 }
170 else
171 {
172 r = upower_call_function ("HibernateAllowed", NULL);
173 if (r && g_variant_is_of_type (r, G_VARIANT_TYPE ("(b)")))
174 g_variant_get (r, "(b)", &can_hibernate);
175 }
176 if (r)
177 g_variant_unref (r);
116178
117 return can_hibernate;179 return can_hibernate;
118}180}
@@ -122,21 +184,32 @@
122 * @error: return location for a #GError, or %NULL184 * @error: return location for a #GError, or %NULL
123 *185 *
124 * Triggers a system hibernate.186 * Triggers a system hibernate.
125 * 187 *
126 * Return value: #TRUE if hibernate initiated.188 * Return value: #TRUE if hibernate initiated.
127 **/189 **/
128gboolean190gboolean
129lightdm_hibernate (GError **error)191lightdm_hibernate (GError **error)
130{192{
131 GVariant *result;193 GVariant *result;
132 194 gboolean hibernated;
133 result = upower_call_function ("Hibernate", error);195
196 result = login1_call_function ("Hibernate", g_variant_new("(b)", FALSE),
197 error);
198
134 if (!result)199 if (!result)
135 return FALSE;200 {
136201 if (error)
137 g_variant_unref (result);202 g_debug ("Can't hibernate using logind; falling back to UPower: %s",
138203 (*error)->message);
139 return TRUE;204 g_clear_error (error);
205 result = upower_call_function ("Hibernate", error);
206 }
207
208 hibernated = result != NULL;
209 if (result)
210 g_variant_unref (result);
211
212 return hibernated;
140}213}
141214
142static GVariant *215static GVariant *
@@ -169,37 +242,6 @@
169 return r;242 return r;
170}243}
171244
172static GVariant *
173login1_call_function (const gchar *function, GVariant *parameters, GError **error)
174{
175 GVariant *r;
176 gchar *str_result;
177
178 if (!login1_proxy)
179 {
180 login1_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
181 G_DBUS_PROXY_FLAGS_NONE,
182 NULL,
183 "org.freedesktop.login1",
184 "/org/freedesktop/login1",
185 "org.freedesktop.login1.Manager",
186 NULL,
187 error);
188 if (!login1_proxy)
189 return NULL;
190 }
191
192 r = g_dbus_proxy_call_sync (login1_proxy,
193 function,
194 parameters,
195 G_DBUS_CALL_FLAGS_NONE,
196 -1,
197 NULL,
198 error);
199
200 return r;
201}
202
203/**245/**
204 * lightdm_get_can_restart:246 * lightdm_get_can_restart:
205 *247 *
@@ -250,6 +292,7 @@
250 gboolean restarted;292 gboolean restarted;
251293
252 r = login1_call_function ("Reboot", g_variant_new("(b)", FALSE), error);294 r = login1_call_function ("Reboot", g_variant_new("(b)", FALSE), error);
295
253 if (!r)296 if (!r)
254 {297 {
255 g_clear_error (error);298 g_clear_error (error);
@@ -274,7 +317,7 @@
274{317{
275 gboolean can_shutdown = FALSE;318 gboolean can_shutdown = FALSE;
276 GVariant *r;319 GVariant *r;
277 320
278 r = login1_call_function ("CanPowerOff", NULL, NULL);321 r = login1_call_function ("CanPowerOff", NULL, NULL);
279 if (r)322 if (r)
280 {323 {
281324
=== modified file 'liblightdm-qt/power.cpp'
--- liblightdm-qt/power.cpp 2013-04-15 03:06:52 +0000
+++ liblightdm-qt/power.cpp 2013-04-23 14:46:29 +0000
@@ -51,6 +51,17 @@
5151
52bool PowerInterface::canSuspend()52bool PowerInterface::canSuspend()
53{53{
54 if (d->login1Interface->isValid())
55 {
56 QDBusReply<QString> reply = d->login1Interface->call("CanSuspend");
57 if (reply.isValid())
58 {
59 return reply.value() == "yes";
60 }
61 }
62
63 qWarning() << d->login1Interface->lastError();
64
54 QDBusReply<bool> reply = d->powerManagementInterface->call("SuspendAllowed");65 QDBusReply<bool> reply = d->powerManagementInterface->call("SuspendAllowed");
55 if (reply.isValid()) {66 if (reply.isValid()) {
56 return reply.value();67 return reply.value();
@@ -62,12 +73,28 @@
6273
63bool PowerInterface::suspend()74bool PowerInterface::suspend()
64{75{
65 QDBusReply<void> reply = d->powerManagementInterface->call("Suspend");76 QDBusReply<void> reply;
77 if (d->login1Interface->isValid())
78 reply = d->login1Interface->call("Suspend", false);
79 else
80 reply = d->powerManagementInterface->call("Suspend");
81
66 return reply.isValid ();82 return reply.isValid ();
67}83}
6884
69bool PowerInterface::canHibernate()85bool PowerInterface::canHibernate()
70{86{
87 if (d->login1Interface->isValid())
88 {
89 QDBusReply<QString> reply = d->login1Interface->call("CanHibernate");
90 if (reply.isValid())
91 {
92 return reply.value() == "yes";
93 }
94 }
95
96 qWarning() << d->login1Interface->lastError();
97
71 QDBusReply<bool> reply = d->powerManagementInterface->call("HibernateAllowed");98 QDBusReply<bool> reply = d->powerManagementInterface->call("HibernateAllowed");
72 if (reply.isValid()) {99 if (reply.isValid()) {
73 return reply.value();100 return reply.value();
@@ -79,7 +106,12 @@
79106
80bool PowerInterface::hibernate()107bool PowerInterface::hibernate()
81{108{
82 QDBusReply<void> reply = d->powerManagementInterface->call("Hibernate");109 QDBusReply<void> reply;
110 if (d->login1Interface->isValid())
111 reply = d->login1Interface->call("Hibernate", false);
112 else
113 reply = d->powerManagementInterface->call("Hibernate");
114
83 return reply.isValid ();115 return reply.isValid ();
84}116}
85117
86118
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2013-01-28 17:09:01 +0000
+++ src/Makefile.am 2013-04-23 14:46:29 +0000
@@ -28,6 +28,8 @@
28 lightdm.c \28 lightdm.c \
29 ldm-marshal.c \29 ldm-marshal.c \
30 ldm-marshal.h \30 ldm-marshal.h \
31 login1.c \
32 login1.h \
31 plymouth.c \33 plymouth.c \
32 plymouth.h \34 plymouth.h \
33 privileges.c \35 privileges.c \
3436
=== added file 'src/login1.c'
--- src/login1.c 1970-01-01 00:00:00 +0000
+++ src/login1.c 2013-04-23 14:46:29 +0000
@@ -0,0 +1,137 @@
1/* -*- Mode: C; indent-tabs-mode: nil; tab-width: 4 -*-
2 *
3 * Copyright (C) 2010-2011 Robert Ancell.
4 * Author: Robert Ancell <robert.ancell@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
9 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
10 * license.
11 */
12
13#include <gio/gio.h>
14
15#include "login1.h"
16
17gchar *
18login1_get_session_id (void)
19{
20 GDBusConnection *bus;
21 GVariant *result;
22 gchar *session_path;
23 GError *error = NULL;
24
25 bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
26 if (error)
27 g_warning ("Failed to get system bus: %s", error->message);
28 g_clear_error (&error);
29 if (!bus)
30 return NULL;
31 result = g_dbus_connection_call_sync (bus,
32 "org.freedesktop.login1",
33 "/org/freedesktop/login1",
34 "org.freedesktop.login1.Manager",
35 "GetSessionByPID",
36 g_variant_new ("(u)", getpid()),
37 G_VARIANT_TYPE ("(o)"),
38 G_DBUS_CALL_FLAGS_NONE,
39 -1,
40 NULL,
41 &error);
42 g_object_unref (bus);
43
44 if (error)
45 g_warning ("Failed to open login1 session: %s", error->message);
46 g_clear_error (&error);
47 if (!result)
48 return NULL;
49
50 g_variant_get (result, "(o)", &session_path);
51 g_variant_unref (result);
52 g_debug ("Got login1 session id: %s", session_path);
53
54 return session_path;
55}
56
57void
58login1_lock_session (const gchar *session_path)
59{
60 GDBusConnection *bus;
61 GError *error = NULL;
62
63 g_return_if_fail (session_path != NULL);
64
65 g_debug ("Locking login1 session %s", session_path);
66
67 bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
68 if (error)
69 g_warning ("Failed to get system bus: %s", error->message);
70 g_clear_error (&error);
71 if (!bus)
72 return;
73
74 if (session_path)
75 {
76 GVariant *result;
77
78 result = g_dbus_connection_call_sync (bus,
79 "org.freedesktop.login1",
80 session_path,
81 "org.freedesktop.login1.Session",
82 "Lock",
83 g_variant_new ("()"),
84 G_VARIANT_TYPE ("()"),
85 G_DBUS_CALL_FLAGS_NONE,
86 -1,
87 NULL,
88 &error);
89 if (error)
90 g_warning ("Error locking login1 session: %s", error->message);
91 g_clear_error (&error);
92 if (result)
93 g_variant_unref (result);
94 }
95 g_object_unref (bus);
96}
97
98void
99login1_unlock_session (const gchar *session_path)
100{
101 GDBusConnection *bus;
102 GError *error = NULL;
103
104 g_return_if_fail (session_path != NULL);
105
106 g_debug ("Unlocking login1 session %s", session_path);
107
108 bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
109 if (error)
110 g_warning ("Failed to get system bus: %s", error->message);
111 g_clear_error (&error);
112 if (!bus)
113 return;
114
115 if (session_path)
116 {
117 GVariant *result;
118
119 result = g_dbus_connection_call_sync (bus,
120 "org.freedesktop.login1",
121 session_path,
122 "org.freedesktop.login1.Session",
123 "Unlock",
124 g_variant_new ("()"),
125 G_VARIANT_TYPE ("()"),
126 G_DBUS_CALL_FLAGS_NONE,
127 -1,
128 NULL,
129 &error);
130 if (error)
131 g_warning ("Error unlocking login1 session: %s", error->message);
132 g_clear_error (&error);
133 if (result)
134 g_variant_unref (result);
135 }
136 g_object_unref (bus);
137}
0138
=== added file 'src/login1.h'
--- src/login1.h 1970-01-01 00:00:00 +0000
+++ src/login1.h 2013-04-23 14:46:29 +0000
@@ -0,0 +1,29 @@
1/*
2 * Copyright (C) 2010-2011 Robert Ancell.
3 * Author: Robert Ancell <robert.ancell@canonical.com>
4 *
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option) any later
8 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
9 * license.
10 */
11
12#ifndef _LOGIN1_H_
13#define _LOGIN1_H_
14
15#include <glib-object.h>
16
17#define LOGIND_RUNNING() (access ("/run/systemd/seats/", F_OK) >= 0)
18
19G_BEGIN_DECLS
20
21gchar *login1_get_session_id (void);
22
23void login1_lock_session (const gchar *session_path);
24
25void login1_unlock_session (const gchar *session_path);
26
27G_END_DECLS
28
29#endif /* _LOGIN1_H_ */
030
=== modified file 'src/session-child.c'
--- src/session-child.c 2013-04-18 23:06:32 +0000
+++ src/session-child.c 2013-04-23 14:46:29 +0000
@@ -1,3 +1,5 @@
1#include <config.h>
2
1#include <stdlib.h>3#include <stdlib.h>
2#include <stdio.h>4#include <stdio.h>
3#include <unistd.h>5#include <unistd.h>
@@ -14,9 +16,11 @@
14#include <utmpx.h>16#include <utmpx.h>
15#include <sys/mman.h>17#include <sys/mman.h>
1618
19#include "configuration.h"
17#include "session-child.h"20#include "session-child.h"
18#include "session.h"21#include "session.h"
19#include "console-kit.h"22#include "console-kit.h"
23#include "login1.h"
20#include "privileges.h"24#include "privileges.h"
21#include "xauthority.h"25#include "xauthority.h"
22#include "configuration.h"26#include "configuration.h"
@@ -190,7 +194,9 @@
190 XAuthority *xauthority = NULL;194 XAuthority *xauthority = NULL;
191 gchar *xauth_filename;195 gchar *xauth_filename;
192 GDBusConnection *bus;196 GDBusConnection *bus;
193 gchar *console_kit_cookie;197 gchar *console_kit_cookie = NULL;
198 gchar *login1_session = NULL;
199
194 const gchar *path;200 const gchar *path;
195 GError *error = NULL;201 GError *error = NULL;
196 const gchar *locale_value;202 const gchar *locale_value;
@@ -443,33 +449,42 @@
443 if (!bus)449 if (!bus)
444 return EXIT_FAILURE;450 return EXIT_FAILURE;
445451
446 /* Open a Console Kit session */452 if (LOGIND_RUNNING ())
447 g_variant_builder_init (&ck_parameters, G_VARIANT_TYPE ("(a(sv))"));453 {
448 g_variant_builder_open (&ck_parameters, G_VARIANT_TYPE ("a(sv)"));454 login1_session = login1_get_session_id ();
449 g_variant_builder_add (&ck_parameters, "(sv)", "unix-user", g_variant_new_int32 (user_get_uid (user)));455 write_string (login1_session);
450 if (g_strcmp0 (class, XDG_SESSION_CLASS_GREETER) == 0)456 }
451 g_variant_builder_add (&ck_parameters, "(sv)", "session-type", g_variant_new_string ("LoginWindow"));457
452 if (xdisplay)458 if (!login1_session)
453 {459 {
454 g_variant_builder_add (&ck_parameters, "(sv)", "x11-display", g_variant_new_string (xdisplay));460 /* Open a Console Kit session */
455 if (tty)461 g_variant_builder_init (&ck_parameters, G_VARIANT_TYPE ("(a(sv))"));
456 g_variant_builder_add (&ck_parameters, "(sv)", "x11-display-device", g_variant_new_string (tty));462 g_variant_builder_open (&ck_parameters, G_VARIANT_TYPE ("a(sv)"));
457 }463 g_variant_builder_add (&ck_parameters, "(sv)", "unix-user", g_variant_new_int32 (user_get_uid (user)));
458 if (remote_host_name)464 if (g_strcmp0 (class, XDG_SESSION_CLASS_GREETER) == 0)
459 {465 g_variant_builder_add (&ck_parameters, "(sv)", "session-type", g_variant_new_string ("LoginWindow"));
460 g_variant_builder_add (&ck_parameters, "(sv)", "is-local", g_variant_new_boolean (FALSE));466 if (xdisplay)
461 g_variant_builder_add (&ck_parameters, "(sv)", "remote-host-name", g_variant_new_string (remote_host_name));467 {
462 }468 g_variant_builder_add (&ck_parameters, "(sv)", "x11-display", g_variant_new_string (xdisplay));
463 else469 if (tty)
464 g_variant_builder_add (&ck_parameters, "(sv)", "is-local", g_variant_new_boolean (TRUE));470 g_variant_builder_add (&ck_parameters, "(sv)", "x11-display-device", g_variant_new_string (tty));
465 console_kit_cookie = ck_open_session (&ck_parameters);471 }
466 write_string (console_kit_cookie);472 if (remote_host_name)
467 if (console_kit_cookie)473 {
468 {474 g_variant_builder_add (&ck_parameters, "(sv)", "is-local", g_variant_new_boolean (FALSE));
469 gchar *value;475 g_variant_builder_add (&ck_parameters, "(sv)", "remote-host-name", g_variant_new_string (remote_host_name));
470 value = g_strdup_printf ("XDG_SESSION_COOKIE=%s", console_kit_cookie);476 }
471 pam_putenv (pam_handle, value);477 else
472 g_free (value);478 g_variant_builder_add (&ck_parameters, "(sv)", "is-local", g_variant_new_boolean (TRUE));
479 console_kit_cookie = ck_open_session (&ck_parameters);
480 write_string (console_kit_cookie);
481 if (console_kit_cookie)
482 {
483 gchar *value;
484 value = g_strdup_printf ("XDG_SESSION_COOKIE=%s", console_kit_cookie);
485 pam_putenv (pam_handle, value);
486 g_free (value);
487 }
473 }488 }
474489
475 /* Write X authority */490 /* Write X authority */
476491
=== modified file 'src/session.c'
--- src/session.c 2013-03-07 21:40:31 +0000
+++ src/session.c 2013-04-23 14:46:29 +0000
@@ -1,7 +1,7 @@
1/*1/*
2 * Copyright (C) 2010-2011 Robert Ancell.2 * Copyright (C) 2010-2011 Robert Ancell.
3 * Author: Robert Ancell <robert.ancell@canonical.com>3 * Author: Robert Ancell <robert.ancell@canonical.com>
4 * 4 *
5 * This program is free software: you can redistribute it and/or modify it under5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option) any later7 * Foundation, either version 3 of the License, or (at your option) any later
@@ -9,6 +9,8 @@
9 * license.9 * license.
10 */10 */
1111
12#include <config.h>
13
12#include <stdlib.h>14#include <stdlib.h>
13#include <string.h>15#include <string.h>
14#include <errno.h>16#include <errno.h>
@@ -22,6 +24,7 @@
22#include "session.h"24#include "session.h"
23#include "configuration.h"25#include "configuration.h"
24#include "console-kit.h"26#include "console-kit.h"
27#include "login1.h"
25#include "guest-account.h"28#include "guest-account.h"
2629
27enum {30enum {
@@ -62,16 +65,16 @@
62 gboolean authentication_complete;65 gboolean authentication_complete;
63 int authentication_result;66 int authentication_result;
64 gchar *authentication_result_string;67 gchar *authentication_result_string;
65 68
66 /* File to log to */69 /* File to log to */
67 gchar *log_filename;70 gchar *log_filename;
68 71
69 /* Seat class */72 /* Seat class */
70 gchar *class;73 gchar *class;
7174
72 /* tty this session is running on */75 /* tty this session is running on */
73 gchar *tty;76 gchar *tty;
74 77
75 /* X display connected to */78 /* X display connected to */
76 gchar *xdisplay;79 gchar *xdisplay;
77 XAuthority *xauthority;80 XAuthority *xauthority;
@@ -83,6 +86,9 @@
83 /* Console kit cookie */86 /* Console kit cookie */
84 gchar *console_kit_cookie;87 gchar *console_kit_cookie;
8588
89 /* login1 session */
90 gchar *login1_session;
91
86 /* Environment to set in child */92 /* Environment to set in child */
87 GList *env;93 GList *env;
88};94};
@@ -206,10 +212,10 @@
206 g_warning ("Invalid string length %d from child", length);212 g_warning ("Invalid string length %d from child", length);
207 return NULL;213 return NULL;
208 }214 }
209 215
210 value = g_malloc (sizeof (char) * (length + 1));216 value = g_malloc (sizeof (char) * (length + 1));
211 read_from_child (session, value, length);217 read_from_child (session, value, length);
212 value[length] = '\0'; 218 value[length] = '\0';
213219
214 return value;220 return value;
215}221}
@@ -220,7 +226,7 @@
220 Session *session = data;226 Session *session = data;
221227
222 session->priv->pid = 0;228 session->priv->pid = 0;
223 229
224 if (WIFEXITED (status))230 if (WIFEXITED (status))
225 g_debug ("Session %d exited with return value %d", pid, WEXITSTATUS (status));231 g_debug ("Session %d exited with return value %d", pid, WEXITSTATUS (status));
226 else if (WIFSIGNALED (status))232 else if (WIFSIGNALED (status))
@@ -234,7 +240,7 @@
234 session->priv->authentication_result = PAM_CONV_ERR;240 session->priv->authentication_result = PAM_CONV_ERR;
235 g_free (session->priv->authentication_result_string);241 g_free (session->priv->authentication_result_string);
236 session->priv->authentication_result_string = g_strdup ("Authentication stopped before completion");242 session->priv->authentication_result_string = g_strdup ("Authentication stopped before completion");
237 g_signal_emit (G_OBJECT (session), signals[AUTHENTICATION_COMPLETE], 0); 243 g_signal_emit (G_OBJECT (session), signals[AUTHENTICATION_COMPLETE], 0);
238 }244 }
239245
240 g_signal_emit (G_OBJECT (session), signals[STOPPED], 0);246 g_signal_emit (G_OBJECT (session), signals[STOPPED], 0);
@@ -311,14 +317,14 @@
311 for (i = 0; i < session->priv->messages_length; i++)317 for (i = 0; i < session->priv->messages_length; i++)
312 {318 {
313 struct pam_message *m = &session->priv->messages[i];319 struct pam_message *m = &session->priv->messages[i];
314 read_from_child (session, &m->msg_style, sizeof (m->msg_style)); 320 read_from_child (session, &m->msg_style, sizeof (m->msg_style));
315 m->msg = read_string_from_child (session);321 m->msg = read_string_from_child (session);
316 }322 }
317323
318 g_debug ("Session %d got %d message(s) from PAM", session->priv->pid, session->priv->messages_length);324 g_debug ("Session %d got %d message(s) from PAM", session->priv->pid, session->priv->messages_length);
319325
320 g_signal_emit (G_OBJECT (session), signals[GOT_MESSAGES], 0);326 g_signal_emit (G_OBJECT (session), signals[GOT_MESSAGES], 0);
321 } 327 }
322328
323 return TRUE;329 return TRUE;
324}330}
@@ -391,7 +397,7 @@
391 /* Close the ends of the pipes we don't need */397 /* Close the ends of the pipes we don't need */
392 close (to_child_output);398 close (to_child_output);
393 close (from_child_input);399 close (from_child_input);
394 400
395 /* Indicate what version of the protocol we are using */401 /* Indicate what version of the protocol we are using */
396 version = 0;402 version = 0;
397 write_data (session, &version, sizeof (version));403 write_data (session, &version, sizeof (version));
@@ -422,7 +428,7 @@
422 write_data (session, xauth_get_authorization_data (session->priv->xauthority), length);428 write_data (session, xauth_get_authorization_data (session->priv->xauthority), length);
423 }429 }
424 else430 else
425 write_string (session, NULL); 431 write_string (session, NULL);
426432
427 g_debug ("Started session %d with service '%s', username '%s'", session->priv->pid, service, username);433 g_debug ("Started session %d with service '%s', username '%s'", session->priv->pid, service, username);
428434
@@ -472,7 +478,7 @@
472 g_return_if_fail (session != NULL);478 g_return_if_fail (session != NULL);
473 g_return_if_fail (error != PAM_SUCCESS);479 g_return_if_fail (error != PAM_SUCCESS);
474480
475 write_data (session, &error, sizeof (error)); 481 write_data (session, &error, sizeof (error));
476}482}
477483
478int484int
@@ -529,7 +535,7 @@
529 {535 {
530 gchar *run_dir, *dir;536 gchar *run_dir, *dir;
531537
532 run_dir = config_get_string (config_get_instance (), "LightDM", "run-directory"); 538 run_dir = config_get_string (config_get_instance (), "LightDM", "run-directory");
533 dir = g_build_filename (run_dir, session->priv->username, NULL);539 dir = g_build_filename (run_dir, session->priv->username, NULL);
534 g_free (run_dir);540 g_free (run_dir);
535541
@@ -558,30 +564,43 @@
558 for (i = 0; i < argc; i++)564 for (i = 0; i < argc; i++)
559 write_string (session, argv[i]);565 write_string (session, argv[i]);
560566
561 session->priv->console_kit_cookie = read_string_from_child (session);567 if (LOGIND_RUNNING ())
568 session->priv->login1_session = read_string_from_child (session);
569 if (!session->priv->login1_session)
570 session->priv->console_kit_cookie = read_string_from_child (session);
562}571}
563572
564void573void
565session_lock (Session *session)574session_lock (Session *session)
566{ 575{
567 g_return_if_fail (session != NULL);576 g_return_if_fail (session != NULL);
568 if (getuid () == 0)577 if (getuid () == 0)
569 ck_lock_session (session->priv->console_kit_cookie);578 {
579 if (LOGIND_RUNNING ())
580 login1_lock_session (session->priv->login1_session);
581 if (!session->priv->login1_session)
582 ck_lock_session (session->priv->console_kit_cookie);
583 }
570}584}
571585
572void586void
573session_unlock (Session *session)587session_unlock (Session *session)
574{ 588{
575 g_return_if_fail (session != NULL);589 g_return_if_fail (session != NULL);
576 if (getuid () == 0)590 if (getuid () == 0)
577 ck_unlock_session (session->priv->console_kit_cookie);591 {
592 if (LOGIND_RUNNING ())
593 login1_unlock_session (session->priv->login1_session);
594 if (!session->priv->login1_session)
595 ck_unlock_session (session->priv->console_kit_cookie);
596 }
578}597}
579598
580void599void
581session_stop (Session *session)600session_stop (Session *session)
582{601{
583 g_return_if_fail (session != NULL);602 g_return_if_fail (session != NULL);
584 603
585 if (session->priv->pid > 0)604 if (session->priv->pid > 0)
586 {605 {
587 g_debug ("Session %d: Sending SIGTERM", session->priv->pid);606 g_debug ("Session %d: Sending SIGTERM", session->priv->pid);
@@ -631,6 +650,7 @@
631 if (self->priv->xauthority)650 if (self->priv->xauthority)
632 g_object_unref (self->priv->xauthority);651 g_object_unref (self->priv->xauthority);
633 g_free (self->priv->remote_host_name);652 g_free (self->priv->remote_host_name);
653 g_free (self->priv->login1_session);
634 g_free (self->priv->console_kit_cookie);654 g_free (self->priv->console_kit_cookie);
635 g_list_free_full (self->priv->env, g_free);655 g_list_free_full (self->priv->env, g_free);
636656
637657
=== modified file 'src/xauthority.c'
--- src/xauthority.c 2013-03-27 00:42:28 +0000
+++ src/xauthority.c 2013-04-23 14:46:29 +0000
@@ -329,7 +329,7 @@
329 }329 }
330 g_list_free (records);330 g_list_free (records);
331331
332 result = g_file_set_contents (filename, output->data, output->len, error);332 result = g_file_set_contents (filename, (gchar *)output->data, output->len, error);
333 g_byte_array_free (output, TRUE);333 g_byte_array_free (output, TRUE);
334334
335 return result;335 return result;
336336
=== modified file 'src/xserver-local.c'
--- src/xserver-local.c 2013-04-16 01:03:09 +0000
+++ src/xserver-local.c 2013-04-23 14:46:29 +0000
@@ -16,6 +16,7 @@
16#include <sys/stat.h>16#include <sys/stat.h>
17#include <errno.h>17#include <errno.h>
18#include <glib/gstdio.h>18#include <glib/gstdio.h>
19#include <stdlib.h>
1920
20#include "xserver-local.h"21#include "xserver-local.h"
21#include "configuration.h"22#include "configuration.h"
2223
=== modified file 'tests/scripts/console-kit.conf'
--- tests/scripts/console-kit.conf 2012-02-29 22:23:17 +0000
+++ tests/scripts/console-kit.conf 2013-04-23 14:46:29 +0000
@@ -2,6 +2,9 @@
2# Check ConsoleKit variable is set in session2# Check ConsoleKit variable is set in session
3#3#
44
5[test-runner-config]
6disable-login1=true
7
5[LightDM]8[LightDM]
6minimum-display-number=509minimum-display-number=50
710
811
=== modified file 'tests/scripts/power-no-console-kit.conf'
--- tests/scripts/power-no-console-kit.conf 2013-04-15 03:06:52 +0000
+++ tests/scripts/power-no-console-kit.conf 2013-04-23 14:46:29 +0000
@@ -26,21 +26,21 @@
2626
27# See if can suspend27# See if can suspend
28#?*GREETER :50 GET-CAN-SUSPEND28#?*GREETER :50 GET-CAN-SUSPEND
29#?UPOWER SUSPEND-ALLOWED29#?LOGIN1 CAN-SUSPEND
30#?GREETER :50 CAN-SUSPEND ALLOWED=TRUE30#?GREETER :50 CAN-SUSPEND ALLOWED=TRUE
3131
32# Suspend32# Suspend
33#?*GREETER :50 SUSPEND33#?*GREETER :50 SUSPEND
34#?UPOWER SUSPEND34#?LOGIN1 SUSPEND
3535
36# See if can hibernate36# See if can hibernate
37#?*GREETER :50 GET-CAN-HIBERNATE37#?*GREETER :50 GET-CAN-HIBERNATE
38#?UPOWER HIBERNATE-ALLOWED38#?LOGIN1 CAN-HIBERNATE
39#?GREETER :50 CAN-HIBERNATE ALLOWED=TRUE39#?GREETER :50 CAN-HIBERNATE ALLOWED=TRUE
4040
41# Hibernate41# Hibernate
42#?*GREETER :50 HIBERNATE42#?*GREETER :50 HIBERNATE
43#?UPOWER HIBERNATE43#?LOGIN1 HIBERNATE
4444
45# See if can restart45# See if can restart
46#?*GREETER :50 GET-CAN-RESTART46#?*GREETER :50 GET-CAN-RESTART
4747
=== modified file 'tests/scripts/power.conf'
--- tests/scripts/power.conf 2013-04-15 03:06:52 +0000
+++ tests/scripts/power.conf 2013-04-23 14:46:29 +0000
@@ -23,21 +23,21 @@
2323
24# See if can suspend24# See if can suspend
25#?*GREETER :50 GET-CAN-SUSPEND25#?*GREETER :50 GET-CAN-SUSPEND
26#?UPOWER SUSPEND-ALLOWED26#?LOGIN1 CAN-SUSPEND
27#?GREETER :50 CAN-SUSPEND ALLOWED=TRUE27#?GREETER :50 CAN-SUSPEND ALLOWED=TRUE
2828
29# Suspend29# Suspend
30#?*GREETER :50 SUSPEND30#?*GREETER :50 SUSPEND
31#?UPOWER SUSPEND31#?LOGIN1 SUSPEND
3232
33# See if can hibernate33# See if can hibernate
34#?*GREETER :50 GET-CAN-HIBERNATE34#?*GREETER :50 GET-CAN-HIBERNATE
35#?UPOWER HIBERNATE-ALLOWED35#?LOGIN1 CAN-HIBERNATE
36#?GREETER :50 CAN-HIBERNATE ALLOWED=TRUE36#?GREETER :50 CAN-HIBERNATE ALLOWED=TRUE
3737
38# Hibernate38# Hibernate
39#?*GREETER :50 HIBERNATE39#?*GREETER :50 HIBERNATE
40#?UPOWER HIBERNATE40#?LOGIN1 HIBERNATE
4141
42# See if can restart42# See if can restart
43#?*GREETER :50 GET-CAN-RESTART43#?*GREETER :50 GET-CAN-RESTART
4444
=== modified file 'tests/src/libsystem.c'
--- tests/src/libsystem.c 2013-03-06 22:35:36 +0000
+++ tests/src/libsystem.c 2013-04-23 14:46:29 +0000
@@ -4,6 +4,7 @@
4#include <sys/types.h>4#include <sys/types.h>
5#include <sys/stat.h>5#include <sys/stat.h>
6#include <pwd.h>6#include <pwd.h>
7#include <unistd.h>
7#include <grp.h>8#include <grp.h>
8#include <security/pam_appl.h>9#include <security/pam_appl.h>
9#include <fcntl.h>10#include <fcntl.h>
1011
=== modified file 'tests/src/test-runner.c'
--- tests/src/test-runner.c 2013-04-15 03:06:52 +0000
+++ tests/src/test-runner.c 2013-04-23 14:46:29 +0000
@@ -83,7 +83,7 @@
83} CKSession;83} CKSession;
84static GList *ck_sessions = NULL;84static GList *ck_sessions = NULL;
85static gint ck_session_index = 0;85static gint ck_session_index = 0;
86static void handle_ck_session_call (GDBusConnection *connection,86static void handle_session_call (GDBusConnection *connection,
87 const gchar *sender,87 const gchar *sender,
88 const gchar *object_path,88 const gchar *object_path,
89 const gchar *interface_name,89 const gchar *interface_name,
@@ -93,8 +93,18 @@
93 gpointer user_data);93 gpointer user_data);
94static const GDBusInterfaceVTable ck_session_vtable =94static const GDBusInterfaceVTable ck_session_vtable =
95{95{
96 handle_ck_session_call,96 handle_session_call,
97};97};
98
99typedef struct
100{
101 gchar *path;
102 guint pid;
103} Login1Session;
104
105static GList *login1_sessions = NULL;
106static gint login1_session_index = 0;
107
98typedef struct108typedef struct
99{109{
100 GSocket *socket;110 GSocket *socket;
@@ -134,7 +144,7 @@
134{144{
135 Process *process;145 Process *process;
136 gchar *status_text;146 gchar *status_text;
137 147
138 if (getenv ("DEBUG"))148 if (getenv ("DEBUG"))
139 {149 {
140 if (WIFEXITED (status))150 if (WIFEXITED (status))
@@ -173,7 +183,7 @@
173static Process *183static Process *
174watch_process (pid_t pid)184watch_process (pid_t pid)
175{185{
176 Process *process; 186 Process *process;
177187
178 process = g_malloc0 (sizeof (Process));188 process = g_malloc0 (sizeof (Process));
179 process->pid = pid;189 process->pid = pid;
@@ -360,7 +370,7 @@
360 else if (strcmp (name, "SWITCH-TO-USER") == 0)370 else if (strcmp (name, "SWITCH-TO-USER") == 0)
361 {371 {
362 gchar *status_text, *username;372 gchar *status_text, *username;
363 373
364 username = g_hash_table_lookup (params, "USERNAME");374 username = g_hash_table_lookup (params, "USERNAME");
365 g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),375 g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
366 "org.freedesktop.DisplayManager",376 "org.freedesktop.DisplayManager",
@@ -456,21 +466,21 @@
456 StatusClient *client = link->data;466 StatusClient *client = link->data;
457 int length;467 int length;
458 GError *error = NULL;468 GError *error = NULL;
459 469
460 length = strlen (command);470 length = strlen (command);
461 g_socket_send (client->socket, (gchar *) &length, sizeof (length), NULL, &error);471 g_socket_send (client->socket, (gchar *) &length, sizeof (length), NULL, &error);
462 g_socket_send (client->socket, command, strlen (command), NULL, &error);472 g_socket_send (client->socket, command, strlen (command), NULL, &error);
463 if (error)473 if (error)
464 g_printerr ("Failed to write to client socket: %s\n", error->message);474 g_printerr ("Failed to write to client socket: %s\n", error->message);
465 g_clear_error (&error);475 g_clear_error (&error);
466 } 476 }
467 }477 }
468 else478 else
469 {479 {
470 g_printerr ("Unknown command '%s'\n", name);480 g_printerr ("Unknown command '%s'\n", name);
471 quit (EXIT_FAILURE);481 quit (EXIT_FAILURE);
472 }482 }
473 483
474 g_free (name);484 g_free (name);
475 g_hash_table_unref (params);485 g_hash_table_unref (params);
476}486}
@@ -514,9 +524,9 @@
514524
515 if (stop)525 if (stop)
516 return;526 return;
517 527
518 statuses = g_list_append (statuses, g_strdup (status));528 statuses = g_list_append (statuses, g_strdup (status));
519 529
520 if (getenv ("DEBUG"))530 if (getenv ("DEBUG"))
521 g_print ("%s\n", status);531 g_print ("%s\n", status);
522532
@@ -528,7 +538,7 @@
528 result = g_regex_match_simple (full_pattern, status, 0, 0);538 result = g_regex_match_simple (full_pattern, status, 0, 0);
529 g_free (full_pattern);539 g_free (full_pattern);
530 }540 }
531 541
532 if (!result)542 if (!result)
533 {543 {
534 fail (NULL, pattern);544 fail (NULL, pattern);
@@ -686,7 +696,7 @@
686696
687 upower_info = g_dbus_node_info_new_for_xml (upower_interface, &error);697 upower_info = g_dbus_node_info_new_for_xml (upower_interface, &error);
688 if (error)698 if (error)
689 g_warning ("Failed to parse D-Bus interface: %s", error->message); 699 g_warning ("Failed to parse D-Bus interface: %s", error->message);
690 g_clear_error (&error);700 g_clear_error (&error);
691 if (!upower_info)701 if (!upower_info)
692 return;702 return;
@@ -829,15 +839,17 @@
829 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);839 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);
830}840}
831841
842
843/* Shared between CK and Login1 - identical signatures */
832static void844static void
833handle_ck_session_call (GDBusConnection *connection,845handle_session_call (GDBusConnection *connection,
834 const gchar *sender,846 const gchar *sender,
835 const gchar *object_path,847 const gchar *object_path,
836 const gchar *interface_name,848 const gchar *interface_name,
837 const gchar *method_name,849 const gchar *method_name,
838 GVariant *parameters,850 GVariant *parameters,
839 GDBusMethodInvocation *invocation,851 GDBusMethodInvocation *invocation,
840 gpointer user_data)852 gpointer user_data)
841{853{
842 if (strcmp (method_name, "Lock") == 0)854 if (strcmp (method_name, "Lock") == 0)
843 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));855 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
@@ -904,13 +916,13 @@
904916
905 ck_info = g_dbus_node_info_new_for_xml (ck_interface, &error);917 ck_info = g_dbus_node_info_new_for_xml (ck_interface, &error);
906 if (error)918 if (error)
907 g_warning ("Failed to parse D-Bus interface: %s", error->message); 919 g_warning ("Failed to parse D-Bus interface: %s", error->message);
908 g_clear_error (&error);920 g_clear_error (&error);
909 if (!ck_info)921 if (!ck_info)
910 return;922 return;
911 ck_session_info = g_dbus_node_info_new_for_xml (ck_session_interface, &error);923 ck_session_info = g_dbus_node_info_new_for_xml (ck_session_interface, &error);
912 if (error)924 if (error)
913 g_warning ("Failed to parse D-Bus interface: %s", error->message); 925 g_warning ("Failed to parse D-Bus interface: %s", error->message);
914 g_clear_error (&error);926 g_clear_error (&error);
915 if (!ck_session_info)927 if (!ck_session_info)
916 return;928 return;
@@ -944,6 +956,59 @@
944 NULL);956 NULL);
945}957}
946958
959static Login1Session *
960open_login1_session (GDBusConnection *connection,
961 GVariant *params)
962{
963 Login1Session *session;
964 GError *error = NULL;
965 GDBusNodeInfo *login1_session_info;
966
967 const gchar *login1_session_interface =
968 "<node>"
969 " <interface name='org.freedesktop.login1.Session'>"
970 " <method name='Lock'/>"
971 " <method name='Unlock'/>"
972 " </interface>"
973 "</node>";
974 static const GDBusInterfaceVTable login1_session_vtable =
975 {
976 handle_session_call,
977 };
978
979 session = g_malloc0 (sizeof (Login1Session));
980 login1_sessions = g_list_append (login1_sessions, session);
981
982 session->path = g_strdup_printf("/org/freedesktop/login1/Session/c%d",
983 login1_session_index++);
984
985
986
987 login1_session_info = g_dbus_node_info_new_for_xml (login1_session_interface,
988 &error);
989 if (error)
990 g_warning ("Failed to parse login1 session D-Bus interface: %s",
991 error->message);
992 g_clear_error (&error);
993 if (!login1_session_info)
994 return;
995
996 g_dbus_connection_register_object (connection,
997 session->path,
998 login1_session_info->interfaces[0],
999 &login1_session_vtable,
1000 session,
1001 NULL,
1002 &error);
1003 if (error)
1004 g_warning ("Failed to register login1 session: %s", error->message);
1005 g_clear_error (&error);
1006 g_dbus_node_info_unref (login1_session_info);
1007
1008 return session;
1009}
1010
1011
947static void1012static void
948handle_login1_call (GDBusConnection *connection,1013handle_login1_call (GDBusConnection *connection,
949 const gchar *sender,1014 const gchar *sender,
@@ -954,7 +1019,36 @@
954 GDBusMethodInvocation *invocation,1019 GDBusMethodInvocation *invocation,
955 gpointer user_data)1020 gpointer user_data)
956{1021{
957 if (strcmp (method_name, "CanReboot") == 0)1022
1023 if (strcmp (method_name, "GetSessionByPID") == 0)
1024 {
1025 /* Look for a session with our PID, and create one if we don't have one
1026 already. */
1027 GList *link;
1028 guint pid;
1029 Login1Session *ret = NULL;
1030
1031 g_variant_get (parameters, "(u)", &pid);
1032
1033 for (link = login1_sessions; link; link = link->next)
1034 {
1035 Login1Session *session;
1036 session = link->data;
1037 if (session->pid == pid)
1038 {
1039 ret = session;
1040 break;
1041 }
1042 }
1043 /* Not found */
1044 if (!ret)
1045 ret = open_login1_session (connection, parameters);
1046
1047 g_dbus_method_invocation_return_value (invocation,
1048 g_variant_new("(o)", ret->path));
1049
1050 }
1051 else if (strcmp (method_name, "CanReboot") == 0)
958 {1052 {
959 check_status ("LOGIN1 CAN-REBOOT");1053 check_status ("LOGIN1 CAN-REBOOT");
960 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));1054 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));
@@ -971,6 +1065,18 @@
971 check_status ("LOGIN1 CAN-POWER-OFF");1065 check_status ("LOGIN1 CAN-POWER-OFF");
972 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));1066 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));
973 }1067 }
1068 else if (strcmp (method_name, "Suspend") == 0)
1069 {
1070 gboolean interactive;
1071 g_variant_get (parameters, "(b)", &interactive);
1072 check_status ("LOGIN1 SUSPEND");
1073 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
1074 }
1075 else if (strcmp (method_name, "CanSuspend") == 0)
1076 {
1077 check_status ("LOGIN1 CAN-SUSPEND");
1078 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));
1079 }
974 else if (strcmp (method_name, "PowerOff") == 0)1080 else if (strcmp (method_name, "PowerOff") == 0)
975 {1081 {
976 gboolean interactive;1082 gboolean interactive;
@@ -978,6 +1084,18 @@
978 check_status ("LOGIN1 POWER-OFF");1084 check_status ("LOGIN1 POWER-OFF");
979 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));1085 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
980 }1086 }
1087 else if (strcmp (method_name, "CanHibernate") == 0)
1088 {
1089 check_status ("LOGIN1 CAN-HIBERNATE");
1090 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));
1091 }
1092 else if (strcmp (method_name, "Hibernate") == 0)
1093 {
1094 gboolean interactive;
1095 g_variant_get (parameters, "(b)", &interactive);
1096 check_status ("LOGIN1 HIBERNATE");
1097 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
1098 }
981 else1099 else
982 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);1100 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);
983}1101}
@@ -990,6 +1108,10 @@
990 const gchar *login1_interface =1108 const gchar *login1_interface =
991 "<node>"1109 "<node>"
992 " <interface name='org.freedesktop.login1.Manager'>"1110 " <interface name='org.freedesktop.login1.Manager'>"
1111 " <method name='GetSessionByPID'>"
1112 " <arg name='pid' type='u' direction='in'/>"
1113 " <arg name='session' type='o' direction='out'/>"
1114 " </method>"
993 " <method name='CanReboot'>"1115 " <method name='CanReboot'>"
994 " <arg name='result' direction='out' type='s'/>"1116 " <arg name='result' direction='out' type='s'/>"
995 " </method>"1117 " </method>"
@@ -1002,6 +1124,18 @@
1002 " <method name='PowerOff'>"1124 " <method name='PowerOff'>"
1003 " <arg name='interactive' direction='in' type='b'/>"1125 " <arg name='interactive' direction='in' type='b'/>"
1004 " </method>"1126 " </method>"
1127 " <method name='CanSuspend'>"
1128 " <arg name='result' direction='out' type='s'/>"
1129 " </method>"
1130 " <method name='Suspend'>"
1131 " <arg name='interactive' direction='in' type='b'/>"
1132 " </method>"
1133 " <method name='CanHibernate'>"
1134 " <arg name='result' direction='out' type='s'/>"
1135 " </method>"
1136 " <method name='Hibernate'>"
1137 " <arg name='interactive' direction='in' type='b'/>"
1138 " </method>"
1005 " </interface>"1139 " </interface>"
1006 "</node>";1140 "</node>";
1007 static const GDBusInterfaceVTable login1_vtable =1141 static const GDBusInterfaceVTable login1_vtable =
@@ -1013,7 +1147,7 @@
10131147
1014 login1_info = g_dbus_node_info_new_for_xml (login1_interface, &error);1148 login1_info = g_dbus_node_info_new_for_xml (login1_interface, &error);
1015 if (error)1149 if (error)
1016 g_warning ("Failed to parse D-Bus interface: %s", error->message); 1150 g_warning ("Failed to parse login1 D-Bus interface: %s", error->message);
1017 g_clear_error (&error);1151 g_clear_error (&error);
1018 if (!login1_info)1152 if (!login1_info)
1019 return;1153 return;
@@ -1150,7 +1284,7 @@
11501284
1151 g_variant_builder_init (&builder, G_VARIANT_TYPE ("ao"));1285 g_variant_builder_init (&builder, G_VARIANT_TYPE ("ao"));
11521286
1153 load_passwd_file (); 1287 load_passwd_file ();
1154 for (link = accounts_users; link; link = link->next)1288 for (link = accounts_users; link; link = link->next)
1155 {1289 {
1156 AccountsUser *user = link->data;1290 AccountsUser *user = link->data;
@@ -1183,7 +1317,7 @@
1183 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such user: %s", user_name);1317 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such user: %s", user_name);
1184 }1318 }
1185 else1319 else
1186 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name); 1320 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);
1187}1321}
11881322
1189static void1323static void
@@ -1292,13 +1426,13 @@
12921426
1293 accounts_info = g_dbus_node_info_new_for_xml (accounts_interface, &error);1427 accounts_info = g_dbus_node_info_new_for_xml (accounts_interface, &error);
1294 if (error)1428 if (error)
1295 g_warning ("Failed to parse D-Bus interface: %s", error->message); 1429 g_warning ("Failed to parse D-Bus interface: %s", error->message);
1296 g_clear_error (&error);1430 g_clear_error (&error);
1297 if (!accounts_info)1431 if (!accounts_info)
1298 return;1432 return;
1299 user_info = g_dbus_node_info_new_for_xml (user_interface, &error);1433 user_info = g_dbus_node_info_new_for_xml (user_interface, &error);
1300 if (error)1434 if (error)
1301 g_warning ("Failed to parse D-Bus interface: %s", error->message); 1435 g_warning ("Failed to parse D-Bus interface: %s", error->message);
1302 g_clear_error (&error);1436 g_clear_error (&error);
1303 if (!user_info)1437 if (!user_info)
1304 return;1438 return;
@@ -1424,7 +1558,7 @@
1424 g_critical ("Error getting current directory: %s", strerror (errno));1558 g_critical ("Error getting current directory: %s", strerror (errno));
1425 quit (EXIT_FAILURE);1559 quit (EXIT_FAILURE);
1426 }1560 }
1427 1561
1428 /* Don't contact our X server */1562 /* Don't contact our X server */
1429 g_unsetenv ("DISPLAY");1563 g_unsetenv ("DISPLAY");
14301564
@@ -1439,7 +1573,7 @@
1439 g_free (path);1573 g_free (path);
14401574
1441 /* Use locally built libraries */1575 /* Use locally built libraries */
1442 path1 = g_build_filename (BUILDDIR, "liblightdm-gobject", ".libs", NULL); 1576 path1 = g_build_filename (BUILDDIR, "liblightdm-gobject", ".libs", NULL);
1443 path2 = g_build_filename (BUILDDIR, "liblightdm-qt", ".libs", NULL);1577 path2 = g_build_filename (BUILDDIR, "liblightdm-qt", ".libs", NULL);
1444 ld_library_path = g_strdup_printf ("%s:%s", path1, path2);1578 ld_library_path = g_strdup_printf ("%s:%s", path1, path2);
1445 g_free (path1);1579 g_free (path1);
@@ -1510,7 +1644,7 @@
15101644
1511 /* Always copy the script */1645 /* Always copy the script */
1512 if (system (g_strdup_printf ("cp %s %s/script", config_path, temp_dir)))1646 if (system (g_strdup_printf ("cp %s %s/script", config_path, temp_dir)))
1513 perror ("Failed to copy configuration"); 1647 perror ("Failed to copy configuration");
15141648
1515 /* Copy over the greeter files */1649 /* Copy over the greeter files */
1516 if (system (g_strdup_printf ("cp -r %s/xsessions %s/usr/share", DATADIR, temp_dir)))1650 if (system (g_strdup_printf ("cp -r %s/xsessions %s/usr/share", DATADIR, temp_dir)))
@@ -1568,7 +1702,7 @@
1568 /* This account has a set of keyboard layouts */1702 /* This account has a set of keyboard layouts */
1569 {"have-layouts", "", TRUE, "Layouts User", NULL, "ru", "fr\toss;ru;", NULL, 1010},1703 {"have-layouts", "", TRUE, "Layouts User", NULL, "ru", "fr\toss;ru;", NULL, 1010},
1570 /* This account has a language set */1704 /* This account has a language set */
1571 {"have-language", "", TRUE, "Language User", NULL, NULL, NULL, "en_AU.utf8", 1011}, 1705 {"have-language", "", TRUE, "Language User", NULL, NULL, NULL, "en_AU.utf8", 1011},
1572 /* This account has a preconfigured session */1706 /* This account has a preconfigured session */
1573 {"have-session", "", TRUE, "Session User", "alternative", NULL, NULL, NULL, 1012},1707 {"have-session", "", TRUE, "Session User", "alternative", NULL, NULL, NULL, 1012},
1574 /* This account has the home directory mounted on login */1708 /* This account has the home directory mounted on login */
@@ -1642,6 +1776,7 @@
1642 {1776 {
1643 g_key_file_set_string (dmrc_file, "X-Accounts", "Layouts", users[i].dbus_layouts);1777 g_key_file_set_string (dmrc_file, "X-Accounts", "Layouts", users[i].dbus_layouts);
1644 save_dmrc = TRUE;1778 save_dmrc = TRUE;
1779
1645 }1780 }
1646 if (users[i].language)1781 if (users[i].language)
1647 {1782 {
@@ -1657,7 +1792,7 @@
1657 data = g_key_file_to_data (dmrc_file, NULL, NULL);1792 data = g_key_file_to_data (dmrc_file, NULL, NULL);
1658 g_file_set_contents (path, data, -1, NULL);1793 g_file_set_contents (path, data, -1, NULL);
1659 g_free (data);1794 g_free (data);
1660 g_free (path); 1795 g_free (path);
1661 }1796 }
16621797
1663 g_key_file_free (dmrc_file);1798 g_key_file_free (dmrc_file);

Subscribers

People subscribed via source and target branches