~ubuntu-branches/ubuntu/vivid/xfce4-session/vivid-proposed

« back to all changes in this revision

Viewing changes to .pc/02_runtime-logind-support.patch/xfce4-session/xfsm-systemd.c

  • Committer: Package Import Robot
  • Author(s): Sean Davis
  • Date: 2014-12-01 21:12:28 UTC
  • mfrom: (1.4.6) (4.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20141201211228-bqdgmiclbn2e9823
Tags: 4.11.1-0ubuntu1
* New upstream release.
* debian/patches:
  - Dropped 02_runtime-logind-support.patch and
    xubuntu_set-xdg-current-desktop.patch, included upstream.
  - Refreshed 01_fix-xrdb-call.patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * Copyright (C) 2012 Christian Hesse
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2, or (at your option)
7
 
 * any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17
 
 * MA 02110-1301 USA.
18
 
 */
19
 
 
20
 
#include <config.h>
21
 
 
22
 
#include <gio/gio.h>
23
 
#include <polkit/polkit.h>
24
 
#include <dbus/dbus-glib.h>
25
 
#include <dbus/dbus-glib-lowlevel.h>
26
 
 
27
 
#include <xfce4-session/xfsm-systemd.h>
28
 
 
29
 
 
30
 
 
31
 
#define SYSTEMD_DBUS_NAME               "org.freedesktop.login1"
32
 
#define SYSTEMD_DBUS_PATH               "/org/freedesktop/login1"
33
 
#define SYSTEMD_DBUS_INTERFACE          "org.freedesktop.login1.Manager"
34
 
#define SYSTEMD_REBOOT_ACTION           "Reboot"
35
 
#define SYSTEMD_POWEROFF_ACTION         "PowerOff"
36
 
#define SYSTEMD_REBOOT_TEST             "org.freedesktop.login1.reboot"
37
 
#define SYSTEMD_POWEROFF_TEST           "org.freedesktop.login1.power-off"
38
 
 
39
 
 
40
 
 
41
 
static void     xfsm_systemd_finalize     (GObject         *object);
42
 
 
43
 
 
44
 
 
45
 
struct _XfsmSystemdClass
46
 
{
47
 
  GObjectClass __parent__;
48
 
};
49
 
 
50
 
struct _XfsmSystemd
51
 
{
52
 
  GObject __parent__;
53
 
 
54
 
  PolkitAuthority *authority;
55
 
  PolkitSubject   *subject;
56
 
};
57
 
 
58
 
 
59
 
 
60
 
G_DEFINE_TYPE (XfsmSystemd, xfsm_systemd, G_TYPE_OBJECT)
61
 
 
62
 
 
63
 
 
64
 
static void
65
 
xfsm_systemd_class_init (XfsmSystemdClass *klass)
66
 
{
67
 
  GObjectClass *gobject_class;
68
 
 
69
 
  gobject_class = G_OBJECT_CLASS (klass);
70
 
  gobject_class->finalize = xfsm_systemd_finalize;
71
 
}
72
 
 
73
 
 
74
 
 
75
 
static void
76
 
xfsm_systemd_init (XfsmSystemd *systemd)
77
 
{
78
 
  systemd->authority = polkit_authority_get_sync (NULL, NULL);
79
 
  systemd->subject = polkit_unix_process_new (getpid());
80
 
}
81
 
 
82
 
 
83
 
 
84
 
static void
85
 
xfsm_systemd_finalize (GObject *object)
86
 
{
87
 
  XfsmSystemd *systemd = XFSM_SYSTEMD (object);
88
 
 
89
 
  g_object_unref (G_OBJECT (systemd->authority));
90
 
  g_object_unref (G_OBJECT (systemd->subject));
91
 
 
92
 
  (*G_OBJECT_CLASS (xfsm_systemd_parent_class)->finalize) (object);
93
 
}
94
 
 
95
 
 
96
 
static gboolean
97
 
xfsm_systemd_can_method (XfsmSystemd  *systemd,
98
 
                         gboolean     *can_method,
99
 
                         const gchar  *method,
100
 
                         GError      **error)
101
 
{
102
 
  PolkitAuthorizationResult *res;
103
 
  GError                    *local_error = NULL;
104
 
 
105
 
  *can_method = FALSE;
106
 
 
107
 
  res = polkit_authority_check_authorization_sync (systemd->authority,
108
 
                                                   systemd->subject,
109
 
                                                   method,
110
 
                                                   NULL,
111
 
                                                   POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE,
112
 
                                                   NULL,
113
 
                                                   &local_error);
114
 
 
115
 
  if (res == NULL)
116
 
    {
117
 
      g_propagate_error (error, local_error);
118
 
      return FALSE;
119
 
    }
120
 
 
121
 
  *can_method = polkit_authorization_result_get_is_authorized (res)
122
 
                || polkit_authorization_result_get_is_challenge (res);
123
 
 
124
 
  g_object_unref (G_OBJECT (res));
125
 
 
126
 
  return TRUE;
127
 
}
128
 
 
129
 
 
130
 
 
131
 
static gboolean
132
 
xfsm_systemd_try_method (XfsmSystemd  *systemd,
133
 
                         const gchar  *method,
134
 
                         GError      **error)
135
 
{
136
 
  GDBusConnection *bus;
137
 
  GError          *local_error = NULL;
138
 
 
139
 
  bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
140
 
  if (G_UNLIKELY (bus == NULL))
141
 
    return FALSE;
142
 
 
143
 
  g_dbus_connection_call_sync (bus,
144
 
                               SYSTEMD_DBUS_NAME,
145
 
                               SYSTEMD_DBUS_PATH,
146
 
                               SYSTEMD_DBUS_INTERFACE,
147
 
                               method,
148
 
                               g_variant_new ("(b)", TRUE),
149
 
                               NULL, 0, G_MAXINT, NULL,
150
 
                               &local_error);
151
 
 
152
 
  g_object_unref (G_OBJECT (bus));
153
 
 
154
 
  if (local_error != NULL)
155
 
    {
156
 
      g_propagate_error (error, local_error);
157
 
      return FALSE;
158
 
    }
159
 
 
160
 
  return TRUE;
161
 
}
162
 
 
163
 
 
164
 
 
165
 
XfsmSystemd *
166
 
xfsm_systemd_get (void)
167
 
{
168
 
  static XfsmSystemd *object = NULL;
169
 
 
170
 
  if (G_LIKELY (object != NULL))
171
 
    {
172
 
      g_object_ref (G_OBJECT (object));
173
 
    }
174
 
  else
175
 
    {
176
 
      object = g_object_new (XFSM_TYPE_SYSTEMD, NULL);
177
 
      g_object_add_weak_pointer (G_OBJECT (object), (gpointer) &object);
178
 
    }
179
 
 
180
 
  return object;
181
 
}
182
 
 
183
 
 
184
 
 
185
 
gboolean
186
 
xfsm_systemd_try_restart (XfsmSystemd  *systemd,
187
 
                          GError      **error)
188
 
{
189
 
  return xfsm_systemd_try_method (systemd,
190
 
                                  SYSTEMD_REBOOT_ACTION,
191
 
                                  error);
192
 
}
193
 
 
194
 
 
195
 
 
196
 
gboolean
197
 
xfsm_systemd_try_shutdown (XfsmSystemd  *systemd,
198
 
                           GError      **error)
199
 
{
200
 
  return xfsm_systemd_try_method (systemd,
201
 
                                  SYSTEMD_POWEROFF_ACTION,
202
 
                                  error);
203
 
}
204
 
 
205
 
 
206
 
 
207
 
gboolean
208
 
xfsm_systemd_can_restart (XfsmSystemd  *systemd,
209
 
                          gboolean     *can_restart,
210
 
                          GError      **error)
211
 
{
212
 
  return xfsm_systemd_can_method (systemd,
213
 
                                  can_restart,
214
 
                                  SYSTEMD_REBOOT_TEST,
215
 
                                  error);
216
 
}
217
 
 
218
 
 
219
 
 
220
 
gboolean
221
 
xfsm_systemd_can_shutdown (XfsmSystemd  *systemd,
222
 
                           gboolean     *can_shutdown,
223
 
                           GError      **error)
224
 
{
225
 
  return xfsm_systemd_can_method (systemd,
226
 
                                  can_shutdown,
227
 
                                  SYSTEMD_POWEROFF_TEST,
228
 
                                  error);
229
 
}