]> git.pld-linux.org Git - packages/polkit.git/blob - systemd-fallback.patch
- updated gettext BR
[packages/polkit.git] / systemd-fallback.patch
1 diff -urN polkit-0.107.old/configure.ac polkit-0.107/configure.ac
2 --- polkit-0.107.old/configure.ac       2012-10-07 21:31:48.402911710 +0200
3 +++ polkit-0.107/configure.ac   2012-10-07 22:27:11.041586743 +0200
4 @@ -163,7 +163,7 @@
5                [enable_libsystemd_login=auto])
6  if test "$enable_libsystemd_login" != "no"; then
7    PKG_CHECK_MODULES(LIBSYSTEMD_LOGIN,
8 -                    [libsystemd-login],
9 +                    [libsystemd-login libsystemd-daemon],
10                      have_libsystemd_login=yes,
11                      have_libsystemd_login=no)
12    if test "$have_libsystemd_login" = "yes"; then
13 diff -urN polkit-0.107.old/src/polkit/Makefile.am polkit-0.107/src/polkit/Makefile.am
14 --- polkit-0.107.old/src/polkit/Makefile.am     2012-10-07 21:31:48.379578504 +0200
15 +++ polkit-0.107/src/polkit/Makefile.am 2012-10-07 21:51:14.746593099 +0200
16 @@ -79,15 +79,8 @@
17         polkitimplicitauthorization.c           polkitimplicitauthorization.h           \
18         polkittemporaryauthorization.c          polkittemporaryauthorization.h          \
19         polkitpermission.c                      polkitpermission.h                      \
20 -        $(NULL)
21 -
22 -if HAVE_LIBSYSTEMD_LOGIN
23 -libpolkit_gobject_1_la_SOURCES += \
24 -       polkitunixsession-systemd.c             polkitunixsession.h
25 -else
26 -libpolkit_gobject_1_la_SOURCES += \
27 -       polkitunixsession.c                     polkitunixsession.h
28 -endif
29 +       polkitunixsession.c                     polkitunixsession.h                     \
30 +       $(NULL)
31  
32  libpolkit_gobject_1_la_CFLAGS =                                                \
33          -D_POLKIT_COMPILATION                                                  \
34 diff -urN polkit-0.107.old/src/polkit/polkitunixsession.c polkit-0.107/src/polkit/polkitunixsession.c
35 --- polkit-0.107.old/src/polkit/polkitunixsession.c     2012-10-07 21:31:48.376245189 +0200
36 +++ polkit-0.107/src/polkit/polkitunixsession.c 2012-10-07 22:44:55.042489220 +0200
37 @@ -29,6 +29,12 @@
38  #include "polkiterror.h"
39  #include "polkitprivate.h"
40  
41 +#ifdef HAVE_LIBSYSTEMD_LOGIN
42 +#  include <stdlib.h>
43 +#  include <systemd/sd-daemon.h>
44 +#  include <systemd/sd-login.h>
45 +#endif
46 +
47  /**
48   * SECTION:polkitunixsession
49   * @title: PolkitUnixSession
50 @@ -363,35 +369,49 @@
51  {
52    PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject);
53    GDBusConnection *connection;
54 -  GVariant *result;
55 +  GVariant *result = NULL;
56    gboolean ret;
57  
58 +  connection = NULL;
59    ret = FALSE;
60  
61 -  connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
62 -  if (connection == NULL)
63 -    goto out;
64 +#ifdef HAVE_LIBSYSTEMD_LOGIN
65 +  uid_t uid;
66  
67 -  result = g_dbus_connection_call_sync (connection,
68 -                                        "org.freedesktop.ConsoleKit",           /* name */
69 -                                        session->session_id,                    /* object path */
70 -                                        "org.freedesktop.ConsoleKit.Session",   /* interface name */
71 -                                        "GetUser",                              /* method */
72 -                                        NULL, /* parameters */
73 -                                        G_VARIANT_TYPE ("(u)"),
74 -                                        G_DBUS_CALL_FLAGS_NONE,
75 -                                        -1,
76 -                                        cancellable,
77 -                                        error);
78 -  if (result == NULL)
79 -    goto out;
80 +  if (sd_booted () > 0)
81 +    {
82 +      if (sd_session_get_uid (session->session_id, &uid) == 0)
83 +        ret = TRUE;
84 +    }
85 +  else
86 +#endif /* HAVE_LIBSYSTEMD_LOGIN */
87 +    {
88 +      connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
89 +      if (connection == NULL)
90 +        goto out;
91 +
92 +      result = g_dbus_connection_call_sync (connection,
93 +                                            "org.freedesktop.ConsoleKit",           /* name */
94 +                                            session->session_id,                    /* object path */
95 +                                            "org.freedesktop.ConsoleKit.Session",   /* interface name */
96 +                                            "GetUser",                              /* method */
97 +                                            NULL, /* parameters */
98 +                                            G_VARIANT_TYPE ("(u)"),
99 +                                            G_DBUS_CALL_FLAGS_NONE,
100 +                                            -1,
101 +                                            cancellable,
102 +                                            error);
103 +      if (result == NULL)
104 +        goto out;
105  
106 -  ret = TRUE;
107 -  g_variant_unref (result);
108 +      ret = TRUE;
109 +      g_variant_unref (result);
110 +    }
111  
112   out:
113    if (connection != NULL)
114      g_object_unref (connection);
115 +
116    return ret;
117  }
118  
119 @@ -474,6 +494,7 @@
120    GVariant *result;
121    gboolean ret;
122  
123 +  result = NULL;
124    connection = NULL;
125    ret = FALSE;
126  
127 @@ -484,28 +505,51 @@
128        goto out;
129      }
130  
131 -  connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
132 -  if (connection == NULL)
133 -    goto out;
134 -
135 -  result = g_dbus_connection_call_sync (connection,
136 -                                        "org.freedesktop.ConsoleKit",           /* name */
137 -                                        "/org/freedesktop/ConsoleKit/Manager",  /* object path */
138 -                                        "org.freedesktop.ConsoleKit.Manager",   /* interface name */
139 -                                        "GetSessionForUnixProcess",             /* method */
140 -                                        g_variant_new ("(u)", session->pid),    /* parameters */
141 -                                        G_VARIANT_TYPE ("(o)"),
142 -                                        G_DBUS_CALL_FLAGS_NONE,
143 -                                        -1,
144 -                                        cancellable,
145 -                                        error);
146 -  if (result == NULL)
147 -    goto out;
148 +#ifdef HAVE_LIBSYSTEMD_LOGIN
149 +  char *s;
150 +  
151 +  if (sd_booted () > 0)
152 +    {
153 +      if (sd_pid_get_session (session->pid, &s) == 0)
154 +        {
155 +          session->session_id = g_strdup (s);
156 +          free (s);
157 +          ret = TRUE;
158 +          goto out;
159 +        }
160 +
161 +      g_set_error (error,
162 +                   POLKIT_ERROR,
163 +                   POLKIT_ERROR_FAILED,
164 +                   "No session for pid %d",
165 +                   (gint) session->pid);
166 +    }
167 +  else
168 +#endif /* HAVE_LIBSYSTEMD_LOGIN */
169 +    {
170 +      connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
171 +      if (connection == NULL)
172 +        goto out;
173 +
174 +      result = g_dbus_connection_call_sync (connection,
175 +                                            "org.freedesktop.ConsoleKit",           /* name */
176 +                                            "/org/freedesktop/ConsoleKit/Manager",  /* object path */
177 +                                            "org.freedesktop.ConsoleKit.Manager",   /* interface name */
178 +                                            "GetSessionForUnixProcess",             /* method */
179 +                                            g_variant_new ("(u)", session->pid),    /* parameters */
180 +                                            G_VARIANT_TYPE ("(o)"),
181 +                                            G_DBUS_CALL_FLAGS_NONE,
182 +                                            -1,
183 +                                            cancellable,
184 +                                            error);
185 +      if (result == NULL)
186 +       goto out;
187  
188 -  g_variant_get (result, "(o)", &session->session_id);
189 -  g_variant_unref (result);
190 +      g_variant_get (result, "(o)", &session->session_id);
191 +      g_variant_unref (result);
192  
193 -  ret = TRUE;
194 +      ret = TRUE;
195 +    }
196  
197   out:
198    if (connection != NULL)
199 diff -urN polkit-0.107.old/src/polkit/polkitunixsession-systemd.c polkit-0.107/src/polkit/polkitunixsession-systemd.c
200 --- polkit-0.107.old/src/polkit/polkitunixsession-systemd.c     2012-10-07 21:31:48.379578504 +0200
201 +++ polkit-0.107/src/polkit/polkitunixsession-systemd.c 1970-01-01 01:00:00.000000000 +0100
202 @@ -1,490 +0,0 @@
203 -/*
204 - * Copyright (C) 2011 Red Hat, Inc.
205 - *
206 - * This library is free software; you can redistribute it and/or
207 - * modify it under the terms of the GNU Lesser General Public
208 - * License as published by the Free Software Foundation; either
209 - * version 2 of the License, or (at your option) any later version.
210 - *
211 - * This library is distributed in the hope that it will be useful,
212 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
213 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
214 - * Lesser General Public License for more details.
215 - *
216 - * You should have received a copy of the GNU Lesser General
217 - * Public License along with this library; if not, write to the
218 - * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
219 - * Boston, MA 02111-1307, USA.
220 - *
221 - * Author: Matthias Clasen
222 - */
223 -
224 -#ifdef HAVE_CONFIG_H
225 -#  include "config.h"
226 -#endif
227 -
228 -#include <stdlib.h>
229 -#include <string.h>
230 -#include "polkitunixsession.h"
231 -#include "polkitsubject.h"
232 -#include "polkiterror.h"
233 -#include "polkitprivate.h"
234 -
235 -#include <systemd/sd-login.h>
236 -
237 -/**
238 - * SECTION:polkitunixsession
239 - * @title: PolkitUnixSession
240 - * @short_description: Unix sessions
241 - *
242 - * An object that represents an user session.
243 - *
244 - * The session id is an opaque string obtained from ConsoleKit.
245 - */
246 -
247 -/**
248 - * PolkitUnixSession:
249 - *
250 - * The #PolkitUnixSession struct should not be accessed directly.
251 - */
252 -struct _PolkitUnixSession
253 -{
254 -  GObject parent_instance;
255 -
256 -  gchar *session_id;
257 -
258 -  gint pid;
259 -};
260 -
261 -struct _PolkitUnixSessionClass
262 -{
263 -  GObjectClass parent_class;
264 -};
265 -
266 -enum
267 -{
268 -  PROP_0,
269 -  PROP_SESSION_ID,
270 -  PROP_PID,
271 -};
272 -
273 -static void subject_iface_init        (PolkitSubjectIface *subject_iface);
274 -static void initable_iface_init       (GInitableIface *initable_iface);
275 -static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface);
276 -
277 -G_DEFINE_TYPE_WITH_CODE (PolkitUnixSession, polkit_unix_session, G_TYPE_OBJECT,
278 -                         G_IMPLEMENT_INTERFACE (POLKIT_TYPE_SUBJECT, subject_iface_init)
279 -                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)
280 -                         G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init)
281 -                         );
282 -
283 -static void
284 -polkit_unix_session_init (PolkitUnixSession *session)
285 -{
286 -}
287 -
288 -static void
289 -polkit_unix_session_finalize (GObject *object)
290 -{
291 -  PolkitUnixSession *session = POLKIT_UNIX_SESSION (object);
292 -
293 -  g_free (session->session_id);
294 -
295 -  if (G_OBJECT_CLASS (polkit_unix_session_parent_class)->finalize != NULL)
296 -    G_OBJECT_CLASS (polkit_unix_session_parent_class)->finalize (object);
297 -}
298 -
299 -static void
300 -polkit_unix_session_get_property (GObject    *object,
301 -                                  guint       prop_id,
302 -                                  GValue     *value,
303 -                                  GParamSpec *pspec)
304 -{
305 -  PolkitUnixSession *session = POLKIT_UNIX_SESSION (object);
306 -
307 -  switch (prop_id)
308 -    {
309 -    case PROP_SESSION_ID:
310 -      g_value_set_string (value, session->session_id);
311 -      break;
312 -
313 -    default:
314 -      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
315 -      break;
316 -    }
317 -}
318 -
319 -static void
320 -polkit_unix_session_set_property (GObject      *object,
321 -                                  guint         prop_id,
322 -                                  const GValue *value,
323 -                                  GParamSpec   *pspec)
324 -{
325 -  PolkitUnixSession *session = POLKIT_UNIX_SESSION (object);
326 -
327 -  switch (prop_id)
328 -    {
329 -    case PROP_SESSION_ID:
330 -      polkit_unix_session_set_session_id (session, g_value_get_string (value));
331 -      break;
332 -
333 -    case PROP_PID:
334 -      session->pid = g_value_get_int (value);
335 -      break;
336 -
337 -    default:
338 -      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
339 -      break;
340 -    }
341 -}
342 -
343 -static void
344 -polkit_unix_session_class_init (PolkitUnixSessionClass *klass)
345 -{
346 -  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
347 -
348 -  gobject_class->finalize     = polkit_unix_session_finalize;
349 -  gobject_class->get_property = polkit_unix_session_get_property;
350 -  gobject_class->set_property = polkit_unix_session_set_property;
351 -
352 -  /**
353 -   * PolkitUnixSession:session-id:
354 -   *
355 -   * The UNIX session id.
356 -   */
357 -  g_object_class_install_property (gobject_class,
358 -                                   PROP_SESSION_ID,
359 -                                   g_param_spec_string ("session-id",
360 -                                                        "Session ID",
361 -                                                        "The UNIX session ID",
362 -                                                        NULL,
363 -                                                        G_PARAM_CONSTRUCT |
364 -                                                        G_PARAM_READWRITE |
365 -                                                        G_PARAM_STATIC_NAME |
366 -                                                        G_PARAM_STATIC_BLURB |
367 -                                                        G_PARAM_STATIC_NICK));
368 -
369 -
370 -  /**
371 -   * PolkitUnixSession:pid:
372 -   *
373 -   * The UNIX process id to look up the session.
374 -   */
375 -  g_object_class_install_property (gobject_class,
376 -                                   PROP_PID,
377 -                                   g_param_spec_int ("pid",
378 -                                                     "Process ID",
379 -                                                     "Process ID to use for looking up the session",
380 -                                                     0,
381 -                                                     G_MAXINT,
382 -                                                     0,
383 -                                                     G_PARAM_CONSTRUCT_ONLY |
384 -                                                     G_PARAM_WRITABLE |
385 -                                                     G_PARAM_STATIC_NAME |
386 -                                                     G_PARAM_STATIC_BLURB |
387 -                                                     G_PARAM_STATIC_NICK));
388 -
389 -}
390 -
391 -/**
392 - * polkit_unix_session_get_session_id:
393 - * @session: A #PolkitUnixSession.
394 - *
395 - * Gets the session id for @session.
396 - *
397 - * Returns: The session id for @session. Do not free this string, it
398 - * is owned by @session.
399 - **/
400 -const gchar *
401 -polkit_unix_session_get_session_id (PolkitUnixSession *session)
402 -{
403 -  g_return_val_if_fail (POLKIT_IS_UNIX_SESSION (session), NULL);
404 -  return session->session_id;
405 -}
406 -
407 -/**
408 - * polkit_unix_session_set_session_id:
409 - * @session: A #PolkitUnixSession.
410 - * @session_id: The session id.
411 - *
412 - * Sets the session id for @session to @session_id.
413 - **/
414 -void
415 -polkit_unix_session_set_session_id (PolkitUnixSession *session,
416 -                                    const gchar       *session_id)
417 -{
418 -  g_return_if_fail (POLKIT_IS_UNIX_SESSION (session));
419 -  /*g_return_if_fail (session_id != NULL);*/
420 -  g_free (session->session_id);
421 -  session->session_id = g_strdup (session_id);
422 -}
423 -
424 -/**
425 - * polkit_unix_session_new:
426 - * @session_id: The session id.
427 - *
428 - * Creates a new #PolkitUnixSession for @session_id.
429 - *
430 - * Returns: (transfer full): A #PolkitUnixSession. Free with g_object_unref().
431 - **/
432 -PolkitSubject *
433 -polkit_unix_session_new (const gchar *session_id)
434 -{
435 -  return POLKIT_SUBJECT (g_object_new (POLKIT_TYPE_UNIX_SESSION,
436 -                                       "session-id", session_id,
437 -                                       NULL));
438 -}
439 -
440 -/**
441 - * polkit_unix_session_new_for_process:
442 - * @pid: The process id of the process to get the session for.
443 - * @cancellable: (allow-none): A #GCancellable or %NULL.
444 - * @callback: A #GAsyncReadyCallback to call when the request is satisfied
445 - * @user_data: The data to pass to @callback.
446 - *
447 - * Asynchronously creates a new #PolkitUnixSession object for the
448 - * process with process id @pid.
449 - *
450 - * When the operation is finished, @callback will be invoked in the
451 - * <link linkend="g-main-context-push-thread-default">thread-default
452 - * main loop</link> of the thread you are calling this method
453 - * from. You can then call
454 - * polkit_unix_session_new_for_process_finish() to get the result of
455 - * the operation.
456 - *
457 - * This method constructs the object asynchronously, for the synchronous and blocking version
458 - * use polkit_unix_session_new_for_process_sync().
459 - **/
460 -void
461 -polkit_unix_session_new_for_process (gint                pid,
462 -                                     GCancellable       *cancellable,
463 -                                     GAsyncReadyCallback callback,
464 -                                     gpointer            user_data)
465 -{
466 -  g_async_initable_new_async (POLKIT_TYPE_UNIX_SESSION,
467 -                              G_PRIORITY_DEFAULT,
468 -                              cancellable,
469 -                              callback,
470 -                              user_data,
471 -                              "pid", pid,
472 -                              NULL);
473 -}
474 -
475 -/**
476 - * polkit_unix_session_new_for_process_finish:
477 - * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to polkit_unix_session_new_for_process().
478 - * @error: (allow-none): Return location for error.
479 - *
480 - * Finishes constructing a #PolkitSubject for a process id.
481 - *
482 - * Returns: (transfer full) (allow-none): A #PolkitUnixSession for the @pid passed to
483 - *     polkit_unix_session_new_for_process() or %NULL if @error is
484 - *     set. Free with g_object_unref().
485 - **/
486 -PolkitSubject *
487 -polkit_unix_session_new_for_process_finish (GAsyncResult   *res,
488 -                                            GError        **error)
489 -{
490 -  GObject *object;
491 -  GObject *source_object;
492 -
493 -  source_object = g_async_result_get_source_object (res);
494 -  g_assert (source_object != NULL);
495 -
496 -  object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
497 -                                        res,
498 -                                        error);
499 -  g_object_unref (source_object);
500 -
501 -  if (object != NULL)
502 -    return POLKIT_SUBJECT (object);
503 -  else
504 -    return NULL;
505 -}
506 -
507 -
508 -/**
509 - * polkit_unix_session_new_for_process_sync:
510 - * @pid: The process id of the process to get the session for.
511 - * @cancellable: (allow-none): A #GCancellable or %NULL.
512 - * @error: (allow-none): Return location for error.
513 - *
514 - * Creates a new #PolkitUnixSession for the process with process id @pid.
515 - *
516 - * This is a synchronous call - the calling thread is blocked until a
517 - * reply is received. For the asynchronous version, see
518 - * polkit_unix_session_new_for_process().
519 - *
520 - * Returns: (allow-none) (transfer full): A #PolkitUnixSession for
521 - * @pid or %NULL if @error is set. Free with g_object_unref().
522 - **/
523 -PolkitSubject *
524 -polkit_unix_session_new_for_process_sync (gint           pid,
525 -                                          GCancellable  *cancellable,
526 -                                          GError       **error)
527 -{
528 -  return POLKIT_SUBJECT (g_initable_new (POLKIT_TYPE_UNIX_SESSION,
529 -                                         cancellable,
530 -                                         error,
531 -                                         "pid", pid,
532 -                                         NULL));
533 -}
534 -
535 -static guint
536 -polkit_unix_session_hash (PolkitSubject *subject)
537 -{
538 -  PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject);
539 -
540 -  return g_str_hash (session->session_id);
541 -}
542 -
543 -static gboolean
544 -polkit_unix_session_equal (PolkitSubject *a,
545 -                           PolkitSubject *b)
546 -{
547 -  PolkitUnixSession *session_a;
548 -  PolkitUnixSession *session_b;
549 -
550 -  session_a = POLKIT_UNIX_SESSION (a);
551 -  session_b = POLKIT_UNIX_SESSION (b);
552 -
553 -  return g_strcmp0 (session_a->session_id, session_b->session_id) == 0;
554 -}
555 -
556 -static gchar *
557 -polkit_unix_session_to_string (PolkitSubject *subject)
558 -{
559 -  PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject);
560 -
561 -  return g_strdup_printf ("unix-session:%s", session->session_id);
562 -}
563 -
564 -static gboolean
565 -polkit_unix_session_exists_sync (PolkitSubject   *subject,
566 -                                 GCancellable    *cancellable,
567 -                                 GError         **error)
568 -{
569 -  PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject);
570 -  gboolean ret = FALSE;
571 -  uid_t uid;
572 -
573 -  if (sd_session_get_uid (session->session_id, &uid) == 0)
574 -    ret = TRUE;
575 -
576 -  return ret;
577 -}
578 -
579 -static void
580 -exists_in_thread_func (GSimpleAsyncResult *res,
581 -                       GObject            *object,
582 -                       GCancellable       *cancellable)
583 -{
584 -  GError *error;
585 -  error = NULL;
586 -  if (!polkit_unix_session_exists_sync (POLKIT_SUBJECT (object),
587 -                                        cancellable,
588 -                                        &error))
589 -    {
590 -      g_simple_async_result_set_from_error (res, error);
591 -      g_error_free (error);
592 -    }
593 -}
594 -
595 -static void
596 -polkit_unix_session_exists (PolkitSubject       *subject,
597 -                            GCancellable        *cancellable,
598 -                            GAsyncReadyCallback  callback,
599 -                            gpointer             user_data)
600 -{
601 -  GSimpleAsyncResult *simple;
602 -
603 -  g_return_if_fail (POLKIT_IS_UNIX_SESSION (subject));
604 -
605 -  simple = g_simple_async_result_new (G_OBJECT (subject),
606 -                                      callback,
607 -                                      user_data,
608 -                                      polkit_unix_session_exists);
609 -  g_simple_async_result_run_in_thread (simple,
610 -                                       exists_in_thread_func,
611 -                                       G_PRIORITY_DEFAULT,
612 -                                       cancellable);
613 -  g_object_unref (simple);
614 -}
615 -
616 -static gboolean
617 -polkit_unix_session_exists_finish (PolkitSubject  *subject,
618 -                                      GAsyncResult   *res,
619 -                                      GError        **error)
620 -{
621 -  GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
622 -  gboolean ret;
623 -
624 -  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_unix_session_exists);
625 -
626 -  ret = FALSE;
627 -
628 -  if (g_simple_async_result_propagate_error (simple, error))
629 -    goto out;
630 -
631 -  ret = g_simple_async_result_get_op_res_gboolean (simple);
632 -
633 - out:
634 -  return ret;
635 -}
636 -
637 -static void
638 -subject_iface_init (PolkitSubjectIface *subject_iface)
639 -{
640 -  subject_iface->hash          = polkit_unix_session_hash;
641 -  subject_iface->equal         = polkit_unix_session_equal;
642 -  subject_iface->to_string     = polkit_unix_session_to_string;
643 -  subject_iface->exists        = polkit_unix_session_exists;
644 -  subject_iface->exists_finish = polkit_unix_session_exists_finish;
645 -  subject_iface->exists_sync   = polkit_unix_session_exists_sync;
646 -}
647 -
648 -static gboolean
649 -polkit_unix_session_initable_init (GInitable     *initable,
650 -                                   GCancellable  *cancellable,
651 -                                   GError       **error)
652 -{
653 -  PolkitUnixSession *session = POLKIT_UNIX_SESSION (initable);
654 -  gboolean ret = FALSE;
655 -  char *s;
656 -
657 -  if (session->session_id != NULL)
658 -    {
659 -      /* already set, nothing to do */
660 -      ret = TRUE;
661 -      goto out;
662 -    }
663 -
664 -  if (sd_pid_get_session (session->pid, &s) == 0)
665 -    {
666 -      session->session_id = g_strdup (s);
667 -      free (s);
668 -      ret = TRUE;
669 -      goto out;
670 -    }
671 -
672 -  g_set_error (error,
673 -               POLKIT_ERROR,
674 -               POLKIT_ERROR_FAILED,
675 -               "No session for pid %d",
676 -               (gint) session->pid);
677 -
678 -out:
679 -  return ret;
680 -}
681 -
682 -static void
683 -initable_iface_init (GInitableIface *initable_iface)
684 -{
685 -  initable_iface->init = polkit_unix_session_initable_init;
686 -}
687 -
688 -static void
689 -async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
690 -{
691 -  /* use default implementation to run GInitable code in a thread */
692 -}
693 diff -urN polkit-0.107.old/src/polkitbackend/Makefile.am polkit-0.107/src/polkitbackend/Makefile.am
694 --- polkit-0.107.old/src/polkitbackend/Makefile.am      2012-10-07 21:31:48.382911819 +0200
695 +++ polkit-0.107/src/polkitbackend/Makefile.am  2012-10-07 21:53:38.455814545 +0200
696 @@ -36,15 +36,8 @@
697         polkitbackendactionpool.h               polkitbackendactionpool.c               \
698         polkitbackendconfigsource.h             polkitbackendconfigsource.c             \
699         polkitbackendactionlookup.h             polkitbackendactionlookup.c             \
700 -        $(NULL)
701 -
702 -if HAVE_LIBSYSTEMD_LOGIN
703 -libpolkit_backend_1_la_SOURCES += \
704 -       polkitbackendsessionmonitor.h           polkitbackendsessionmonitor-systemd.c
705 -else
706 -libpolkit_backend_1_la_SOURCES += \
707 -       polkitbackendsessionmonitor.h           polkitbackendsessionmonitor.c
708 -endif
709 +       polkitbackendsessionmonitor.h           polkitbackendsessionmonitor.c           \
710 +       $(NULL)
711  
712  libpolkit_backend_1_la_CFLAGS =                                                \
713          -D_POLKIT_COMPILATION                                                  \
714 diff -urN polkit-0.107.old/src/polkitbackend/polkitbackendjsauthority.c polkit-0.107/src/polkitbackend/polkitbackendjsauthority.c
715 --- polkit-0.107.old/src/polkitbackend/polkitbackendjsauthority.c       2012-10-07 21:31:48.382911819 +0200
716 +++ polkit-0.107/src/polkitbackend/polkitbackendjsauthority.c   2012-10-07 21:52:58.786029455 +0200
717 @@ -35,6 +35,7 @@
718  #include <polkit/polkitprivate.h>
719  
720  #ifdef HAVE_LIBSYSTEMD_LOGIN
721 +#include <systemd/sd-daemon.h>
722  #include <systemd/sd-login.h>
723  #endif /* HAVE_LIBSYSTEMD_LOGIN */
724  
725 @@ -731,11 +732,14 @@
726      }
727  
728  #ifdef HAVE_LIBSYSTEMD_LOGIN
729 -  if (sd_pid_get_session (pid, &session_str) == 0)
730 +  if (sd_booted () > 0)
731      {
732 -      if (sd_session_get_seat (session_str, &seat_str) == 0)
733 +      if (sd_pid_get_session (pid, &session_str) == 0)
734          {
735 -          /* do nothing */
736 +          if (sd_session_get_seat (session_str, &seat_str) == 0)
737 +            {
738 +              /* do nothing */
739 +            }
740          }
741      }
742  #endif /* HAVE_LIBSYSTEMD_LOGIN */
743 diff -urN polkit-0.107.old/src/polkitbackend/polkitbackendsessionmonitor.c polkit-0.107/src/polkitbackend/polkitbackendsessionmonitor.c
744 --- polkit-0.107.old/src/polkitbackend/polkitbackendsessionmonitor.c    2012-10-07 21:31:48.379578504 +0200
745 +++ polkit-0.107/src/polkitbackend/polkitbackendsessionmonitor.c        2012-10-07 22:25:54.305335789 +0200
746 @@ -26,6 +26,12 @@
747  #include <string.h>
748  #include <glib/gstdio.h>
749  
750 +#ifdef HAVE_LIBSYSTEMD_LOGIN
751 +#  include <stdlib.h>
752 +#  include <systemd/sd-daemon.h>
753 +#  include <systemd/sd-login.h>
754 +#endif /* HAVE_LIBSYSTEMD_LOGIN */
755 +
756  #include <polkit/polkit.h>
757  #include "polkitbackendsessionmonitor.h"
758  
759 @@ -39,6 +45,88 @@
760   * The #PolkitBackendSessionMonitor class is a utility class to track and monitor sessions.
761   */
762  
763 +#ifdef HAVE_LIBSYSTEMD_LOGIN
764 +typedef struct
765 +{
766 +  GSource source;
767 +  GPollFD pollfd;
768 +  sd_login_monitor *monitor;
769 +} SdSource;
770 +
771 +static gboolean
772 +sd_source_prepare (GSource *source,
773 +                   gint    *timeout)
774 +{
775 +  *timeout = -1;
776 +  return FALSE;
777 +}
778 +
779 +static gboolean
780 +sd_source_check (GSource *source)
781 +{
782 +  SdSource *sd_source = (SdSource *)source;
783 +
784 +  return sd_source->pollfd.revents != 0;
785 +}
786 +
787 +static gboolean
788 +sd_source_dispatch (GSource     *source,
789 +                    GSourceFunc  callback,
790 +                    gpointer     user_data)
791 +
792 +{
793 +  SdSource *sd_source = (SdSource *)source;
794 +  gboolean ret;
795 +
796 +  g_warn_if_fail (callback != NULL);
797 +
798 +  ret = (*callback) (user_data);
799 +
800 +  sd_login_monitor_flush (sd_source->monitor);
801 +
802 +  return ret;
803 +}
804 +
805 +static void
806 +sd_source_finalize (GSource *source)
807 +{
808 +  SdSource *sd_source = (SdSource*)source;
809 +
810 +  sd_login_monitor_unref (sd_source->monitor);
811 +}
812 +
813 +static GSourceFuncs sd_source_funcs = {
814 +  sd_source_prepare,
815 +  sd_source_check,
816 +  sd_source_dispatch,
817 +  sd_source_finalize
818 +};
819 +
820 +static GSource *
821 +sd_source_new (void)
822 +{
823 +  GSource *source;
824 +  SdSource *sd_source;
825 +  int ret;
826 +
827 +  source = g_source_new (&sd_source_funcs, sizeof (SdSource));
828 +  sd_source = (SdSource *)source;
829 +
830 +  if ((ret = sd_login_monitor_new (NULL, &sd_source->monitor)) < 0)
831 +    {
832 +      g_printerr ("Error getting login monitor: %d", ret);
833 +    }
834 +  else
835 +    {
836 +      sd_source->pollfd.fd = sd_login_monitor_get_fd (sd_source->monitor);
837 +      sd_source->pollfd.events = G_IO_IN;
838 +      g_source_add_poll (source, &sd_source->pollfd);
839 +    }
840 +
841 +  return source;
842 +}
843 +#endif /* HAVE_LIBSYSTEMD_LOGIN */
844 +
845  struct _PolkitBackendSessionMonitor
846  {
847    GObject parent_instance;
848 @@ -48,6 +136,10 @@
849    GKeyFile *database;
850    GFileMonitor *database_monitor;
851    time_t database_mtime;
852 +
853 +#ifdef HAVE_LIBSYSTEMD_LOGIN
854 +  GSource *sd_source;
855 +#endif /* HAVE_LIBSYSTEMD_LOGIN */
856  };
857  
858  struct _PolkitBackendSessionMonitorClass
859 @@ -70,6 +162,18 @@
860  
861  /* ---------------------------------------------------------------------------------------------------- */
862  
863 +#ifdef HAVE_LIBSYSTEMD_LOGIN
864 +static gboolean
865 +sessions_changed (gpointer user_data)
866 +{
867 +  PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data);
868 +
869 +  g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0);
870 +
871 +  return TRUE;
872 +}
873 +#endif /* HAVE_LIBSYSTEMD_LOGIN */
874 +
875  static gboolean
876  reload_database (PolkitBackendSessionMonitor  *monitor,
877                   GError                      **error)
878 @@ -176,31 +280,47 @@
879        g_error_free (error);
880      }
881  
882 -  error = NULL;
883 -  if (!ensure_database (monitor, &error))
884 +#ifdef HAVE_LIBSYSTEMD_LOGIN
885 +  monitor->sd_source = NULL;
886 +
887 +  if (sd_booted () > 0)
888      {
889 -      g_printerr ("Error loading " CKDB_PATH ": %s", error->message);
890 -      g_error_free (error);
891 +      monitor->sd_source = sd_source_new ();
892 +      g_source_set_callback (monitor->sd_source, sessions_changed, monitor, NULL);
893 +      g_source_attach (monitor->sd_source, NULL);
894 +
895 +      monitor->database_monitor = NULL;
896 +      monitor->database = NULL;
897      }
898 +  else
899 +#endif /* HAVE_LIBSYSTEMD_LOGIN */
900 +    {
901 +      error = NULL;
902 +      if (!ensure_database (monitor, &error))
903 +        {
904 +          g_printerr ("Error loading " CKDB_PATH ": %s", error->message);
905 +          g_error_free (error);
906 +        }
907  
908 -  error = NULL;
909 -  file = g_file_new_for_path (CKDB_PATH);
910 -  monitor->database_monitor = g_file_monitor_file (file,
911 +      error = NULL;
912 +      file = g_file_new_for_path (CKDB_PATH);
913 +      monitor->database_monitor = g_file_monitor_file (file,
914                                                     G_FILE_MONITOR_NONE,
915                                                     NULL,
916                                                     &error);
917 -  g_object_unref (file);
918 -  if (monitor->database_monitor == NULL)
919 -    {
920 -      g_printerr ("Error monitoring " CKDB_PATH ": %s", error->message);
921 -      g_error_free (error);
922 -    }
923 -  else
924 -    {
925 -      g_signal_connect (monitor->database_monitor,
926 -                        "changed",
927 -                        G_CALLBACK (on_file_monitor_changed),
928 -                        monitor);
929 +      g_object_unref (file);
930 +      if (monitor->database_monitor == NULL)
931 +        {
932 +          g_printerr ("Error monitoring " CKDB_PATH ": %s", error->message);
933 +          g_error_free (error);
934 +        }
935 +      else
936 +        {
937 +          g_signal_connect (monitor->database_monitor,
938 +                            "changed",
939 +                            G_CALLBACK (on_file_monitor_changed),
940 +                            monitor);
941 +        }
942      }
943  }
944  
945 @@ -218,6 +338,12 @@
946    if (monitor->database != NULL)
947      g_key_file_free (monitor->database);
948  
949 +  if (monitor->sd_source != NULL)
950 +    {
951 +      g_source_destroy (monitor->sd_source);
952 +      g_source_unref (monitor->sd_source);
953 +    }
954 +
955    if (G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize != NULL)
956      G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize (object);
957  }
958 @@ -328,22 +454,38 @@
959      }
960    else if (POLKIT_IS_UNIX_SESSION (subject))
961      {
962 -      if (!ensure_database (monitor, error))
963 +#ifdef HAVE_LIBSYSTEMD_LOGIN
964 +      if (monitor->sd_source != NULL)
965          {
966 -          g_prefix_error (error, "Error getting user for session: Error ensuring CK database at " CKDB_PATH ": ");
967 -          goto out;
968 +          if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0)
969 +            {
970 +              g_set_error (error,
971 +                          POLKIT_ERROR,
972 +                          POLKIT_ERROR_FAILED,
973 +                          "Error getting uid for session");
974 +              goto out;
975 +            }
976          }
977 -
978 -      group = g_strdup_printf ("Session %s", polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)));
979 -      local_error = NULL;
980 -      uid = g_key_file_get_integer (monitor->database, group, "uid", &local_error);
981 -      if (local_error != NULL)
982 +      else
983 +#endif /* HAVE_LIBSYSTEMD_LOGIN */
984          {
985 -          g_propagate_prefixed_error (error, local_error, "Error getting uid using " CKDB_PATH ": ");
986 +          if (!ensure_database (monitor, error))
987 +            {
988 +              g_prefix_error (error, "Error getting user for session: Error ensuring CK database at " CKDB_PATH ": ");
989 +              goto out;
990 +            }
991 +
992 +          group = g_strdup_printf ("Session %s", polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)));
993 +          local_error = NULL;
994 +          uid = g_key_file_get_integer (monitor->database, group, "uid", &local_error);
995 +          if (local_error != NULL)
996 +            {
997 +              g_propagate_prefixed_error (error, local_error, "Error getting uid using " CKDB_PATH ": ");
998 +              g_free (group);
999 +              goto out;
1000 +            }
1001            g_free (group);
1002 -          goto out;
1003          }
1004 -      g_free (group);
1005  
1006        ret = polkit_unix_user_new (uid);
1007      }
1008 @@ -373,29 +515,46 @@
1009  
1010    if (POLKIT_IS_UNIX_PROCESS (subject))
1011      {
1012 -      const gchar *session_id;
1013 -      GVariant *result;
1014 -      result = g_dbus_connection_call_sync (monitor->system_bus,
1015 -                                            "org.freedesktop.ConsoleKit",
1016 -                                            "/org/freedesktop/ConsoleKit/Manager",
1017 -                                            "org.freedesktop.ConsoleKit.Manager",
1018 -                                            "GetSessionForUnixProcess",
1019 -                                            g_variant_new ("(u)", polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject))),
1020 -                                            G_VARIANT_TYPE ("(o)"),
1021 -                                            G_DBUS_CALL_FLAGS_NONE,
1022 -                                            -1, /* timeout_msec */
1023 -                                            NULL, /* GCancellable */
1024 -                                            error);
1025 -      if (result == NULL)
1026 -        goto out;
1027 -      g_variant_get (result, "(&o)", &session_id);
1028 -      session = polkit_unix_session_new (session_id);
1029 -      g_variant_unref (result);
1030 +#ifdef HAVE_LIBSYSTEMD_LOGIN
1031 +      if (monitor->sd_source != NULL)
1032 +        {
1033 +          gchar *session_id;
1034 +          pid_t pid;
1035 +
1036 +          pid = polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject));
1037 +          if (sd_pid_get_session (pid, &session_id) < 0)
1038 +            goto out;
1039 +
1040 +          session = polkit_unix_session_new (session_id);
1041 +          free (session_id);
1042 +        }
1043 +      else
1044 +#endif /* HAVE_LIBSYSTEMD_LOGIN */
1045 +        {
1046 +          const gchar *session_id;
1047 +          GVariant *result;
1048 +          result = g_dbus_connection_call_sync (monitor->system_bus,
1049 +                                                "org.freedesktop.ConsoleKit",
1050 +                                                "/org/freedesktop/ConsoleKit/Manager",
1051 +                                                "org.freedesktop.ConsoleKit.Manager",
1052 +                                                "GetSessionForUnixProcess",
1053 +                                                g_variant_new ("(u)", polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject))),
1054 +                                                G_VARIANT_TYPE ("(o)"),
1055 +                                                G_DBUS_CALL_FLAGS_NONE,
1056 +                                                -1, /* timeout_msec */
1057 +                                                NULL, /* GCancellable */
1058 +                                                error);
1059 +          if (result == NULL)
1060 +            goto out;
1061 +          g_variant_get (result, "(&o)", &session_id);
1062 +          session = polkit_unix_session_new (session_id);
1063 +          g_variant_unref (result);
1064 +        }
1065      }
1066    else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
1067      {
1068        guint32 pid;
1069 -      const gchar *session_id;
1070 +      gchar *session_id;
1071        GVariant *result;
1072  
1073        result = g_dbus_connection_call_sync (monitor->system_bus,
1074 @@ -414,22 +573,35 @@
1075        g_variant_get (result, "(u)", &pid);
1076        g_variant_unref (result);
1077  
1078 -      result = g_dbus_connection_call_sync (monitor->system_bus,
1079 -                                            "org.freedesktop.ConsoleKit",
1080 -                                            "/org/freedesktop/ConsoleKit/Manager",
1081 -                                            "org.freedesktop.ConsoleKit.Manager",
1082 -                                            "GetSessionForUnixProcess",
1083 -                                            g_variant_new ("(u)", pid),
1084 -                                            G_VARIANT_TYPE ("(o)"),
1085 -                                            G_DBUS_CALL_FLAGS_NONE,
1086 -                                            -1, /* timeout_msec */
1087 -                                            NULL, /* GCancellable */
1088 -                                            error);
1089 -      if (result == NULL)
1090 -        goto out;
1091 -      g_variant_get (result, "(&o)", &session_id);
1092 -      session = polkit_unix_session_new (session_id);
1093 -      g_variant_unref (result);
1094 +#ifdef HAVE_LIBSYSTEMD_LOGIN
1095 +      if (monitor->sd_source != NULL)
1096 +        {
1097 +          if (sd_pid_get_session (pid, &session_id) < 0)
1098 +            goto out;
1099 +
1100 +          session = polkit_unix_session_new (session_id);
1101 +          free (session_id);
1102 +        }
1103 +      else
1104 +#endif /* HAVE_LIBSYSTEMD_LOGIN */
1105 +        {
1106 +          result = g_dbus_connection_call_sync (monitor->system_bus,
1107 +                                                "org.freedesktop.ConsoleKit",
1108 +                                                "/org/freedesktop/ConsoleKit/Manager",
1109 +                                                "org.freedesktop.ConsoleKit.Manager",
1110 +                                                "GetSessionForUnixProcess",
1111 +                                                g_variant_new ("(u)", pid),
1112 +                                                G_VARIANT_TYPE ("(o)"),
1113 +                                                G_DBUS_CALL_FLAGS_NONE,
1114 +                                                -1, /* timeout_msec */
1115 +                                                NULL, /* GCancellable */
1116 +                                                error);
1117 +          if (result == NULL)
1118 +            goto out;
1119 +          g_variant_get (result, "(&o)", &session_id);
1120 +          session = polkit_unix_session_new (session_id);
1121 +          g_variant_unref (result);
1122 +        }
1123      }
1124    else
1125      {
1126 @@ -490,7 +662,22 @@
1127  polkit_backend_session_monitor_is_session_local  (PolkitBackendSessionMonitor *monitor,
1128                                                    PolkitSubject               *session)
1129  {
1130 -  return get_boolean (monitor, session, "is_local");
1131 +#ifdef HAVE_LIBSYSTEMD_LOGIN
1132 +  if (monitor->sd_source != NULL)
1133 +    {
1134 +      char *seat;
1135 +
1136 +      if (!sd_session_get_seat (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session)), &seat))
1137 +        {
1138 +          free (seat);
1139 +          return TRUE;
1140 +        }
1141 +
1142 +      return FALSE;
1143 +    }
1144 +  else
1145 +#endif /* HAVE_LIBSYSTEMD_LOGIN */
1146 +    return get_boolean (monitor, session, "is_local");
1147  }
1148  
1149  
1150 @@ -498,6 +685,11 @@
1151  polkit_backend_session_monitor_is_session_active (PolkitBackendSessionMonitor *monitor,
1152                                                    PolkitSubject               *session)
1153  {
1154 -  return get_boolean (monitor, session, "is_active");
1155 +#ifdef HAVE_LIBSYSTEMD_LOGIN
1156 +  if (monitor->sd_source != NULL)
1157 +    return sd_session_is_active (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session)));
1158 +  else
1159 +#endif /* HAVE_LIBSYSTEMD_LOGIN */
1160 +    return get_boolean (monitor, session, "is_active");
1161  }
1162  
1163 diff -urN polkit-0.107.old/src/polkitbackend/polkitbackendsessionmonitor-systemd.c polkit-0.107/src/polkitbackend/polkitbackendsessionmonitor-systemd.c
1164 --- polkit-0.107.old/src/polkitbackend/polkitbackendsessionmonitor-systemd.c    2012-10-07 21:31:48.382911819 +0200
1165 +++ polkit-0.107/src/polkitbackend/polkitbackendsessionmonitor-systemd.c        1970-01-01 01:00:00.000000000 +0100
1166 @@ -1,414 +0,0 @@
1167 -/*
1168 - * Copyright (C) 2011 Red Hat, Inc.
1169 - *
1170 - * This library is free software; you can redistribute it and/or
1171 - * modify it under the terms of the GNU Lesser General Public
1172 - * License as published by the Free Software Foundation; either
1173 - * version 2 of the License, or (at your option) any later version.
1174 - *
1175 - * This library is distributed in the hope that it will be useful,
1176 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1177 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1178 - * Lesser General Public License for more details.
1179 - *
1180 - * You should have received a copy of the GNU Lesser General
1181 - * Public License along with this library; if not, write to the
1182 - * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
1183 - * Boston, MA 02111-1307, USA.
1184 - *
1185 - * Author: Matthias Clasen
1186 - */
1187 -
1188 -#include "config.h"
1189 -#include <errno.h>
1190 -#include <pwd.h>
1191 -#include <grp.h>
1192 -#include <string.h>
1193 -#include <glib/gstdio.h>
1194 -#include <systemd/sd-login.h>
1195 -#include <stdlib.h>
1196 -
1197 -#include <polkit/polkit.h>
1198 -#include "polkitbackendsessionmonitor.h"
1199 -
1200 -/* <internal>
1201 - * SECTION:polkitbackendsessionmonitor
1202 - * @title: PolkitBackendSessionMonitor
1203 - * @short_description: Monitor sessions
1204 - *
1205 - * The #PolkitBackendSessionMonitor class is a utility class to track and monitor sessions.
1206 - */
1207 -
1208 -typedef struct
1209 -{
1210 -  GSource source;
1211 -  GPollFD pollfd;
1212 -  sd_login_monitor *monitor;
1213 -} SdSource;
1214 -
1215 -static gboolean
1216 -sd_source_prepare (GSource *source,
1217 -                   gint    *timeout)
1218 -{
1219 -  *timeout = -1;
1220 -  return FALSE;
1221 -}
1222 -
1223 -static gboolean
1224 -sd_source_check (GSource *source)
1225 -{
1226 -  SdSource *sd_source = (SdSource *)source;
1227 -
1228 -  return sd_source->pollfd.revents != 0;
1229 -}
1230 -
1231 -static gboolean
1232 -sd_source_dispatch (GSource     *source,
1233 -                    GSourceFunc  callback,
1234 -                    gpointer     user_data)
1235 -
1236 -{
1237 -  SdSource *sd_source = (SdSource *)source;
1238 -  gboolean ret;
1239 -
1240 -  g_warn_if_fail (callback != NULL);
1241 -
1242 -  ret = (*callback) (user_data);
1243 -
1244 -  sd_login_monitor_flush (sd_source->monitor);
1245 -
1246 -  return ret;
1247 -}
1248 -
1249 -static void
1250 -sd_source_finalize (GSource *source)
1251 -{
1252 -  SdSource *sd_source = (SdSource*)source;
1253 -
1254 -  sd_login_monitor_unref (sd_source->monitor);
1255 -}
1256 -
1257 -static GSourceFuncs sd_source_funcs = {
1258 -  sd_source_prepare,
1259 -  sd_source_check,
1260 -  sd_source_dispatch,
1261 -  sd_source_finalize
1262 -};
1263 -
1264 -static GSource *
1265 -sd_source_new (void)
1266 -{
1267 -  GSource *source;
1268 -  SdSource *sd_source;
1269 -  int ret;
1270 -
1271 -  source = g_source_new (&sd_source_funcs, sizeof (SdSource));
1272 -  sd_source = (SdSource *)source;
1273 -
1274 -  if ((ret = sd_login_monitor_new (NULL, &sd_source->monitor)) < 0)
1275 -    {
1276 -      g_printerr ("Error getting login monitor: %d", ret);
1277 -    }
1278 -  else
1279 -    {
1280 -      sd_source->pollfd.fd = sd_login_monitor_get_fd (sd_source->monitor);
1281 -      sd_source->pollfd.events = G_IO_IN;
1282 -      g_source_add_poll (source, &sd_source->pollfd);
1283 -    }
1284 -
1285 -  return source;
1286 -}
1287 -
1288 -struct _PolkitBackendSessionMonitor
1289 -{
1290 -  GObject parent_instance;
1291 -
1292 -  GDBusConnection *system_bus;
1293 -
1294 -  GSource *sd_source;
1295 -};
1296 -
1297 -struct _PolkitBackendSessionMonitorClass
1298 -{
1299 -  GObjectClass parent_class;
1300 -
1301 -  void (*changed) (PolkitBackendSessionMonitor *monitor);
1302 -};
1303 -
1304 -
1305 -enum
1306 -{
1307 -  CHANGED_SIGNAL,
1308 -  LAST_SIGNAL,
1309 -};
1310 -
1311 -static guint signals[LAST_SIGNAL] = {0};
1312 -
1313 -G_DEFINE_TYPE (PolkitBackendSessionMonitor, polkit_backend_session_monitor, G_TYPE_OBJECT);
1314 -
1315 -/* ---------------------------------------------------------------------------------------------------- */
1316 -
1317 -static gboolean
1318 -sessions_changed (gpointer user_data)
1319 -{
1320 -  PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data);
1321 -
1322 -  g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0);
1323 -
1324 -  return TRUE;
1325 -}
1326 -
1327 -
1328 -static void
1329 -polkit_backend_session_monitor_init (PolkitBackendSessionMonitor *monitor)
1330 -{
1331 -  GError *error;
1332 -
1333 -  error = NULL;
1334 -  monitor->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
1335 -  if (monitor->system_bus == NULL)
1336 -    {
1337 -      g_printerr ("Error getting system bus: %s", error->message);
1338 -      g_error_free (error);
1339 -    }
1340 -
1341 -  monitor->sd_source = sd_source_new ();
1342 -  g_source_set_callback (monitor->sd_source, sessions_changed, monitor, NULL);
1343 -  g_source_attach (monitor->sd_source, NULL);
1344 -}
1345 -
1346 -static void
1347 -polkit_backend_session_monitor_finalize (GObject *object)
1348 -{
1349 -  PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (object);
1350 -
1351 -  if (monitor->system_bus != NULL)
1352 -    g_object_unref (monitor->system_bus);
1353 -
1354 -  if (monitor->sd_source != NULL)
1355 -    {
1356 -      g_source_destroy (monitor->sd_source);
1357 -      g_source_unref (monitor->sd_source);
1358 -    }
1359 -
1360 -  if (G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize != NULL)
1361 -    G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize (object);
1362 -}
1363 -
1364 -static void
1365 -polkit_backend_session_monitor_class_init (PolkitBackendSessionMonitorClass *klass)
1366 -{
1367 -  GObjectClass *gobject_class;
1368 -
1369 -  gobject_class = G_OBJECT_CLASS (klass);
1370 -
1371 -  gobject_class->finalize = polkit_backend_session_monitor_finalize;
1372 -
1373 -  /**
1374 -   * PolkitBackendSessionMonitor::changed:
1375 -   * @monitor: A #PolkitBackendSessionMonitor
1376 -   *
1377 -   * Emitted when something changes.
1378 -   */
1379 -  signals[CHANGED_SIGNAL] = g_signal_new ("changed",
1380 -                                          POLKIT_BACKEND_TYPE_SESSION_MONITOR,
1381 -                                          G_SIGNAL_RUN_LAST,
1382 -                                          G_STRUCT_OFFSET (PolkitBackendSessionMonitorClass, changed),
1383 -                                          NULL,                   /* accumulator      */
1384 -                                          NULL,                   /* accumulator data */
1385 -                                          g_cclosure_marshal_VOID__VOID,
1386 -                                          G_TYPE_NONE,
1387 -                                          0);
1388 -}
1389 -
1390 -PolkitBackendSessionMonitor *
1391 -polkit_backend_session_monitor_new (void)
1392 -{
1393 -  PolkitBackendSessionMonitor *monitor;
1394 -
1395 -  monitor = POLKIT_BACKEND_SESSION_MONITOR (g_object_new (POLKIT_BACKEND_TYPE_SESSION_MONITOR, NULL));
1396 -
1397 -  return monitor;
1398 -}
1399 -
1400 -/* ---------------------------------------------------------------------------------------------------- */
1401 -
1402 -GList *
1403 -polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monitor)
1404 -{
1405 -  /* TODO */
1406 -  return NULL;
1407 -}
1408 -
1409 -/* ---------------------------------------------------------------------------------------------------- */
1410 -
1411 -/**
1412 - * polkit_backend_session_monitor_get_user:
1413 - * @monitor: A #PolkitBackendSessionMonitor.
1414 - * @subject: A #PolkitSubject.
1415 - * @error: Return location for error.
1416 - *
1417 - * Gets the user corresponding to @subject or %NULL if no user exists.
1418 - *
1419 - * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref().
1420 - */
1421 -PolkitIdentity *
1422 -polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor  *monitor,
1423 -                                                     PolkitSubject                *subject,
1424 -                                                     GError                      **error)
1425 -{
1426 -  PolkitIdentity *ret;
1427 -  guint32 uid;
1428 -
1429 -  ret = NULL;
1430 -
1431 -  if (POLKIT_IS_UNIX_PROCESS (subject))
1432 -    {
1433 -      uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject));
1434 -      if ((gint) uid == -1)
1435 -        {
1436 -          g_set_error (error,
1437 -                       POLKIT_ERROR,
1438 -                       POLKIT_ERROR_FAILED,
1439 -                       "Unix process subject does not have uid set");
1440 -          goto out;
1441 -        }
1442 -      ret = polkit_unix_user_new (uid);
1443 -    }
1444 -  else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
1445 -    {
1446 -      GVariant *result;
1447 -
1448 -      result = g_dbus_connection_call_sync (monitor->system_bus,
1449 -                                            "org.freedesktop.DBus",
1450 -                                            "/org/freedesktop/DBus",
1451 -                                            "org.freedesktop.DBus",
1452 -                                            "GetConnectionUnixUser",
1453 -                                            g_variant_new ("(s)", polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject))),
1454 -                                            G_VARIANT_TYPE ("(u)"),
1455 -                                            G_DBUS_CALL_FLAGS_NONE,
1456 -                                            -1, /* timeout_msec */
1457 -                                            NULL, /* GCancellable */
1458 -                                            error);
1459 -      if (result == NULL)
1460 -        goto out;
1461 -      g_variant_get (result, "(u)", &uid);
1462 -      g_variant_unref (result);
1463 -
1464 -      ret = polkit_unix_user_new (uid);
1465 -    }
1466 -  else if (POLKIT_IS_UNIX_SESSION (subject))
1467 -    {
1468 -
1469 -      if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0)
1470 -        {
1471 -          g_set_error (error,
1472 -                       POLKIT_ERROR,
1473 -                       POLKIT_ERROR_FAILED,
1474 -                       "Error getting uid for session");
1475 -          goto out;
1476 -        }
1477 -
1478 -      ret = polkit_unix_user_new (uid);
1479 -    }
1480 -
1481 - out:
1482 -  return ret;
1483 -}
1484 -
1485 -/**
1486 - * polkit_backend_session_monitor_get_session_for_subject:
1487 - * @monitor: A #PolkitBackendSessionMonitor.
1488 - * @subject: A #PolkitSubject.
1489 - * @error: Return location for error.
1490 - *
1491 - * Gets the session corresponding to @subject or %NULL if no session exists.
1492 - *
1493 - * Returns: %NULL if @error is set otherwise a #PolkitUnixSession that should be freed with g_object_unref().
1494 - */
1495 -PolkitSubject *
1496 -polkit_backend_session_monitor_get_session_for_subject (PolkitBackendSessionMonitor *monitor,
1497 -                                                        PolkitSubject               *subject,
1498 -                                                        GError                     **error)
1499 -{
1500 -  PolkitSubject *session;
1501 -
1502 -  session = NULL;
1503 -
1504 -  if (POLKIT_IS_UNIX_PROCESS (subject))
1505 -    {
1506 -      gchar *session_id;
1507 -      pid_t pid;
1508 -
1509 -      pid = polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject));
1510 -      if (sd_pid_get_session (pid, &session_id) < 0)
1511 -        goto out;
1512 -
1513 -      session = polkit_unix_session_new (session_id);
1514 -      free (session_id);
1515 -    }
1516 -  else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
1517 -    {
1518 -      guint32 pid;
1519 -      gchar *session_id;
1520 -      GVariant *result;
1521 -
1522 -      result = g_dbus_connection_call_sync (monitor->system_bus,
1523 -                                            "org.freedesktop.DBus",
1524 -                                            "/org/freedesktop/DBus",
1525 -                                            "org.freedesktop.DBus",
1526 -                                            "GetConnectionUnixProcessID",
1527 -                                            g_variant_new ("(s)", polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject))),
1528 -                                            G_VARIANT_TYPE ("(u)"),
1529 -                                            G_DBUS_CALL_FLAGS_NONE,
1530 -                                            -1, /* timeout_msec */
1531 -                                            NULL, /* GCancellable */
1532 -                                            error);
1533 -      if (result == NULL)
1534 -        goto out;
1535 -      g_variant_get (result, "(u)", &pid);
1536 -      g_variant_unref (result);
1537 -
1538 -      if (sd_pid_get_session (pid, &session_id) < 0)
1539 -        goto out;
1540 -
1541 -      session = polkit_unix_session_new (session_id);
1542 -      free (session_id);
1543 -    }
1544 -  else
1545 -    {
1546 -      g_set_error (error,
1547 -                   POLKIT_ERROR,
1548 -                   POLKIT_ERROR_NOT_SUPPORTED,
1549 -                   "Cannot get user for subject of type %s",
1550 -                   g_type_name (G_TYPE_FROM_INSTANCE (subject)));
1551 -    }
1552 -
1553 - out:
1554 -
1555 -  return session;
1556 -}
1557 -
1558 -gboolean
1559 -polkit_backend_session_monitor_is_session_local (PolkitBackendSessionMonitor *monitor,
1560 -                                                 PolkitSubject               *session)
1561 -{
1562 -  char *seat;
1563 -
1564 -  if (!sd_session_get_seat (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session)), &seat))
1565 -    {
1566 -      free (seat);
1567 -      return TRUE;
1568 -    }
1569 -
1570 -  return FALSE;
1571 -}
1572 -
1573 -
1574 -gboolean
1575 -polkit_backend_session_monitor_is_session_active (PolkitBackendSessionMonitor *monitor,
1576 -                                                  PolkitSubject               *session)
1577 -{
1578 -  return sd_session_is_active (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session)));
1579 -}
1580 -
This page took 0.137512 seconds and 3 git commands to generate.