summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2009-11-04 19:37:23 +0100
committerMichael Biebl <biebl@debian.org>2009-11-04 19:37:23 +0100
commit6f64702386210741d62f3394e27b1b6695dde698 (patch)
tree676906a73270831fbc42be9ea0f267756cb0031d /src
parent6e7c6dfda732880e6feaef53f8ff0aaf23b4d4d4 (diff)
downloadconsolekit-6f64702386210741d62f3394e27b1b6695dde698.tar.gz
Imported Upstream version 0.4.1upstream/0.4.1
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/Makefile.in10
-rw-r--r--src/ck-log-event.c42
-rw-r--r--src/ck-log-event.h3
-rw-r--r--src/ck-manager-glue.h10
-rw-r--r--src/ck-manager.c94
-rw-r--r--src/ck-marshal.c37
-rw-r--r--src/ck-marshal.h8
-rw-r--r--src/ck-marshal.list1
-rw-r--r--src/ck-run-programs.h3
-rw-r--r--src/ck-seat-glue.h4
-rw-r--r--src/ck-seat.c196
-rw-r--r--src/ck-seat.h10
-rw-r--r--src/ck-session-glue.h6
-rw-r--r--src/ck-session-leader.c1
-rw-r--r--src/ck-session.c8
-rw-r--r--src/ck-session.h3
-rw-r--r--src/ck-sysdeps-solaris.c1
18 files changed, 345 insertions, 94 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index cbe8a09..6ab05c8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -205,5 +205,7 @@ MAINTAINERCLEANFILES = \
install-data-local:
-mkdir -p $(DESTDIR)$(sysconfdir)/ConsoleKit/run-session.d
-mkdir -p $(DESTDIR)$(prefix)/lib/ConsoleKit/run-session.d
+ -mkdir -p $(DESTDIR)$(sysconfdir)/ConsoleKit/run-seat.d
+ -mkdir -p $(DESTDIR)$(prefix)/lib/ConsoleKit/run-seat.d
-mkdir -p $(DESTDIR)$(localstatedir)/run/ConsoleKit
-mkdir -p $(DESTDIR)$(localstatedir)/log/ConsoleKit
diff --git a/src/Makefile.in b/src/Makefile.in
index 36bd4a2..c979ab3 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.2 from Makefile.am.
+# Makefile.in generated by automake 1.10.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -469,8 +469,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
- && { if test -f $@; then exit 0; else break; fi; }; \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
exit 1;; \
esac; \
done; \
@@ -703,7 +703,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
@@ -936,6 +936,8 @@ ck-marshal.h: ck-marshal.list
install-data-local:
-mkdir -p $(DESTDIR)$(sysconfdir)/ConsoleKit/run-session.d
-mkdir -p $(DESTDIR)$(prefix)/lib/ConsoleKit/run-session.d
+ -mkdir -p $(DESTDIR)$(sysconfdir)/ConsoleKit/run-seat.d
+ -mkdir -p $(DESTDIR)$(prefix)/lib/ConsoleKit/run-seat.d
-mkdir -p $(DESTDIR)$(localstatedir)/run/ConsoleKit
-mkdir -p $(DESTDIR)$(localstatedir)/log/ConsoleKit
# Tell versions [3.59,3.63) of GNU make to not export all variables.
diff --git a/src/ck-log-event.c b/src/ck-log-event.c
index 965a036..66f439c 100644
--- a/src/ck-log-event.c
+++ b/src/ck-log-event.c
@@ -63,6 +63,8 @@ static void
event_system_start_free (CkLogSystemStartEvent *event)
{
g_assert (event != NULL);
+ g_free (event->kernel_release);
+ g_free (event->boot_arguments);
}
static void
@@ -196,6 +198,9 @@ event_system_start_copy (CkLogSystemStartEvent *event,
{
g_assert (event != NULL);
g_assert (event_copy != NULL);
+
+ event_copy->kernel_release = g_strdup (event->kernel_release);
+ event_copy->boot_arguments = g_strdup (event->boot_arguments);
}
static void
@@ -470,6 +475,10 @@ add_log_for_system_start (GString *str,
CkLogSystemStartEvent *e;
e = (CkLogSystemStartEvent *)event;
+ g_string_append_printf (str,
+ "kernel-release='%s' boot-arguments='%s'",
+ e->kernel_release ? e->kernel_release : "",
+ e->boot_arguments ? e->boot_arguments : "");
}
static void
@@ -855,23 +864,54 @@ parse_log_for_system_restart (const GString *str,
static gboolean
parse_log_for_system_start (const GString *str,
- CkLogEvent *event)
+ CkLogEvent *event)
{
gboolean ret;
const char *s;
+ GRegex *re;
+ GMatchInfo *match_info;
+ gboolean res;
+ GError *error;
CkLogSystemStartEvent *e;
ret = FALSE;
+ re = NULL;
+ match_info = NULL;
s = skip_header (str->str, str->len);
if (s == NULL) {
goto out;
}
+ /* kernel-release and boot-arguments are attributes added in 0.4 */
+ error = NULL;
+ re = g_regex_new ("(kernel-release='(?P<release>[^']+)')?[ ]?(boot-arguments='(?P<arguments>.*)')?", 0, 0, &error);
+ if (re == NULL) {
+ g_warning (error->message);
+ goto out;
+ }
+
+ g_regex_match (re, s, 0, &match_info);
+
+ res = g_match_info_matches (match_info);
+ if (! res) {
+ g_warning ("Unable to parse system start event: %s", s);
+ goto out;
+ }
+
e = (CkLogSystemStartEvent *)event;
+ e->kernel_release = g_match_info_fetch_named (match_info, "release");
+ e->boot_arguments = g_match_info_fetch_named (match_info, "arguments");
+
ret = TRUE;
out:
+ if (match_info != NULL) {
+ g_match_info_free (match_info);
+ }
+ if (re != NULL) {
+ g_regex_unref (re);
+ }
return ret;
}
diff --git a/src/ck-log-event.h b/src/ck-log-event.h
index 0c04c1d..65571f0 100644
--- a/src/ck-log-event.h
+++ b/src/ck-log-event.h
@@ -60,7 +60,8 @@ typedef struct
typedef struct
{
- gpointer dummy;
+ char *kernel_release;
+ char *boot_arguments;
} CkLogSystemStartEvent;
typedef struct
diff --git a/src/ck-manager-glue.h b/src/ck-manager-glue.h
index a60d5c9..aa360ee 100644
--- a/src/ck-manager-glue.h
+++ b/src/ck-manager-glue.h
@@ -53,7 +53,7 @@ G_BEGIN_DECLS
#endif /* !G_ENABLE_DEBUG */
-/* NONE:STRING,POINTER (/tmp/dbus-binding-tool-c-marshallers.2MBKXU:1) */
+/* NONE:STRING,POINTER (/tmp/dbus-binding-tool-c-marshallers.CGY3YU:1) */
extern void dbus_glib_marshal_ck_manager_VOID__STRING_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
@@ -97,7 +97,7 @@ dbus_glib_marshal_ck_manager_VOID__STRING_POINTER (GClosure *closure,
}
#define dbus_glib_marshal_ck_manager_NONE__STRING_POINTER dbus_glib_marshal_ck_manager_VOID__STRING_POINTER
-/* BOOLEAN:POINTER,POINTER (/tmp/dbus-binding-tool-c-marshallers.2MBKXU:2) */
+/* BOOLEAN:POINTER,POINTER (/tmp/dbus-binding-tool-c-marshallers.CGY3YU:2) */
extern void dbus_glib_marshal_ck_manager_BOOLEAN__POINTER_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
@@ -144,15 +144,15 @@ dbus_glib_marshal_ck_manager_BOOLEAN__POINTER_POINTER (GClosure *closure,
g_value_set_boolean (return_value, v_return);
}
-/* NONE:UINT,POINTER (/tmp/dbus-binding-tool-c-marshallers.2MBKXU:3) */
+/* NONE:UINT,POINTER (/tmp/dbus-binding-tool-c-marshallers.CGY3YU:3) */
#define dbus_glib_marshal_ck_manager_VOID__UINT_POINTER g_cclosure_marshal_VOID__UINT_POINTER
#define dbus_glib_marshal_ck_manager_NONE__UINT_POINTER dbus_glib_marshal_ck_manager_VOID__UINT_POINTER
-/* NONE:POINTER (/tmp/dbus-binding-tool-c-marshallers.2MBKXU:4) */
+/* NONE:POINTER (/tmp/dbus-binding-tool-c-marshallers.CGY3YU:4) */
#define dbus_glib_marshal_ck_manager_VOID__POINTER g_cclosure_marshal_VOID__POINTER
#define dbus_glib_marshal_ck_manager_NONE__POINTER dbus_glib_marshal_ck_manager_VOID__POINTER
-/* NONE:BOXED,POINTER (/tmp/dbus-binding-tool-c-marshallers.2MBKXU:5) */
+/* NONE:BOXED,POINTER (/tmp/dbus-binding-tool-c-marshallers.CGY3YU:5) */
extern void dbus_glib_marshal_ck_manager_VOID__BOXED_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
diff --git a/src/ck-manager.c b/src/ck-manager.c
index bb65d73..99693a3 100644
--- a/src/ck-manager.c
+++ b/src/ck-manager.c
@@ -200,7 +200,7 @@ ck_manager_dump (CkManager *manager)
return;
}
- fd = g_open (filename_tmp, O_CREAT | O_WRONLY, 0600);
+ fd = g_open (filename_tmp, O_CREAT | O_WRONLY, 0644);
if (fd == -1) {
g_warning ("Cannot create file %s: %s", filename_tmp, g_strerror (errno));
goto error;
@@ -810,12 +810,9 @@ check_polkit_permissions (CkManager *manager,
AuthorizedCallback callback)
{
const char *sender;
- GError *error;
PolkitSubject *subject;
AuthorizedCallbackData *data;
- error = NULL;
-
g_debug ("constructing polkit data");
/* Check that caller is privileged */
@@ -837,6 +834,7 @@ check_polkit_permissions (CkManager *manager,
NULL,
(GAsyncReadyCallback)auth_ready_callback,
data);
+ g_object_unref (subject);
}
static void
@@ -873,14 +871,12 @@ get_polkit_permissions (CkManager *manager,
{
const char *sender;
PolkitSubject *subject;
- GError *error;
g_debug ("get permissions for action %s", action);
sender = dbus_g_method_get_sender (context);
subject = polkit_system_bus_name_new (sender);
- error = NULL;
polkit_authority_check_authorization (manager->priv->pol_ctx,
subject,
action,
@@ -890,7 +886,6 @@ get_polkit_permissions (CkManager *manager,
(GAsyncReadyCallback) ready_cb,
context);
g_object_unref (subject);
-
}
#endif
@@ -1228,29 +1223,50 @@ ck_manager_can_stop (CkManager *manager,
}
static void
-on_seat_active_session_changed (CkSeat *seat,
- const char *ssid,
- CkManager *manager)
+on_seat_active_session_changed_full (CkSeat *seat,
+ CkSession *old_session,
+ CkSession *session,
+ CkManager *manager)
{
+ char *ssid = NULL;
+
+ if (session != NULL) {
+ ck_session_get_id (session, &ssid, NULL);
+ }
+
ck_manager_dump (manager);
+ ck_seat_run_programs (seat, old_session, session, "seat_active_session_changed");
+
log_seat_active_session_changed_event (manager, seat, ssid);
}
static void
-on_seat_session_added (CkSeat *seat,
- const char *ssid,
- CkManager *manager)
+on_seat_session_added_full (CkSeat *seat,
+ CkSession *session,
+ CkManager *manager)
{
+ char *ssid = NULL;
+
+ ck_session_get_id (session, &ssid, NULL);
+
ck_manager_dump (manager);
+ ck_session_run_programs (session, "session_added");
+
log_seat_session_added_event (manager, seat, ssid);
}
static void
-on_seat_session_removed (CkSeat *seat,
- const char *ssid,
- CkManager *manager)
+on_seat_session_removed_full (CkSeat *seat,
+ CkSession *session,
+ CkManager *manager)
{
+ char *ssid = NULL;
+
+ ck_session_get_id (session, &ssid, NULL);
+
ck_manager_dump (manager);
+ ck_session_run_programs (session, "session_removed");
+
log_seat_session_removed_event (manager, seat, ssid);
}
@@ -1276,9 +1292,9 @@ static void
connect_seat_signals (CkManager *manager,
CkSeat *seat)
{
- g_signal_connect (seat, "active-session-changed", G_CALLBACK (on_seat_active_session_changed), manager);
- g_signal_connect (seat, "session-added", G_CALLBACK (on_seat_session_added), manager);
- g_signal_connect (seat, "session-removed", G_CALLBACK (on_seat_session_removed), manager);
+ g_signal_connect (seat, "active-session-changed-full", G_CALLBACK (on_seat_active_session_changed_full), manager);
+ g_signal_connect (seat, "session-added-full", G_CALLBACK (on_seat_session_added_full), manager);
+ g_signal_connect (seat, "session-removed-full", G_CALLBACK (on_seat_session_removed_full), manager);
g_signal_connect (seat, "device-added", G_CALLBACK (on_seat_device_added), manager);
g_signal_connect (seat, "device-removed", G_CALLBACK (on_seat_device_removed), manager);
}
@@ -1287,9 +1303,9 @@ static void
disconnect_seat_signals (CkManager *manager,
CkSeat *seat)
{
- g_signal_handlers_disconnect_by_func (seat, on_seat_active_session_changed, manager);
- g_signal_handlers_disconnect_by_func (seat, on_seat_session_added, manager);
- g_signal_handlers_disconnect_by_func (seat, on_seat_session_removed, manager);
+ g_signal_handlers_disconnect_by_func (seat, on_seat_active_session_changed_full, manager);
+ g_signal_handlers_disconnect_by_func (seat, on_seat_session_added_full, manager);
+ g_signal_handlers_disconnect_by_func (seat, on_seat_session_removed_full, manager);
g_signal_handlers_disconnect_by_func (seat, on_seat_device_added, manager);
g_signal_handlers_disconnect_by_func (seat, on_seat_device_removed, manager);
}
@@ -1304,25 +1320,34 @@ add_new_seat (CkManager *manager,
sid = generate_seat_id (manager);
seat = ck_seat_new (sid, kind);
- if (seat == NULL) {
- /* returns null if connection to bus fails */
- g_free (sid);
- goto out;
- }
+
+ /* First we connect our own signals to the seat, followed by
+ * the D-Bus signal hookup to make sure we can first dump the
+ * database and only then send out the D-Bus signals for
+ * it. GObject guarantees us that the signal handlers are
+ * called in the same order as they are registered. */
connect_seat_signals (manager, seat);
+ if (!ck_seat_register (seat)) {
+ /* returns false if connection to bus fails */
+ disconnect_seat_signals (manager, seat);
+ g_object_unref (seat);
+ g_free (sid);
+ return NULL;
+ }
g_hash_table_insert (manager->priv->seats, sid, seat);
g_debug ("Added seat: %s kind:%d", sid, kind);
ck_manager_dump (manager);
+ ck_seat_run_programs (seat, NULL, NULL, "seat_added");
+ g_debug ("Emitting seat-added: %s", sid);
g_signal_emit (manager, signals [SEAT_ADDED], 0, sid);
log_seat_added_event (manager, seat);
- out:
return seat;
}
@@ -1359,6 +1384,7 @@ remove_seat (CkManager *manager,
}
ck_manager_dump (manager);
+ ck_seat_run_programs (seat, NULL, NULL, "seat_removed");
g_debug ("Emitting seat-removed: %s", sid);
g_signal_emit (manager, signals [SEAT_REMOVED], 0, sid);
@@ -2407,20 +2433,24 @@ add_seat_for_file (CkManager *manager,
sid = generate_seat_id (manager);
seat = ck_seat_new_from_file (sid, filename);
- if (seat == NULL) {
- /* returns null if connection to bus fails */
+
+ connect_seat_signals (manager, seat);
+ if (!ck_seat_register (seat)) {
+ /* returns false if connection to bus fails */
+ disconnect_seat_signals (manager, seat);
+ g_object_unref (seat);
g_free (sid);
return;
}
- connect_seat_signals (manager, seat);
-
g_hash_table_insert (manager->priv->seats, sid, seat);
g_debug ("Added seat: %s", sid);
ck_manager_dump (manager);
+ ck_seat_run_programs (seat, NULL, NULL, "seat_added");
+ g_debug ("Emitting seat-added: %s", sid);
g_signal_emit (manager, signals [SEAT_ADDED], 0, sid);
log_seat_added_event (manager, seat);
diff --git a/src/ck-marshal.c b/src/ck-marshal.c
index 8b08794..06dc9b3 100644
--- a/src/ck-marshal.c
+++ b/src/ck-marshal.c
@@ -124,3 +124,40 @@ ck_marshal_BOOLEAN__POINTER (GClosure *closure,
g_value_set_boolean (return_value, v_return);
}
+/* VOID:OBJECT,OBJECT (ck-marshal.list:3) */
+void
+ck_marshal_VOID__OBJECT_OBJECT (GClosure *closure,
+ GValue *return_value G_GNUC_UNUSED,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint G_GNUC_UNUSED,
+ gpointer marshal_data)
+{
+ typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT) (gpointer data1,
+ gpointer arg_1,
+ gpointer arg_2,
+ gpointer data2);
+ register GMarshalFunc_VOID__OBJECT_OBJECT callback;
+ register GCClosure *cc = (GCClosure*) closure;
+ register gpointer data1, data2;
+
+ g_return_if_fail (n_param_values == 3);
+
+ if (G_CCLOSURE_SWAP_DATA (closure))
+ {
+ data1 = closure->data;
+ data2 = g_value_peek_pointer (param_values + 0);
+ }
+ else
+ {
+ data1 = g_value_peek_pointer (param_values + 0);
+ data2 = closure->data;
+ }
+ callback = (GMarshalFunc_VOID__OBJECT_OBJECT) (marshal_data ? marshal_data : cc->callback);
+
+ callback (data1,
+ g_marshal_value_peek_object (param_values + 1),
+ g_marshal_value_peek_object (param_values + 2),
+ data2);
+}
+
diff --git a/src/ck-marshal.h b/src/ck-marshal.h
index 7553810..e817ae0 100644
--- a/src/ck-marshal.h
+++ b/src/ck-marshal.h
@@ -22,6 +22,14 @@ extern void ck_marshal_BOOLEAN__POINTER (GClosure *closure,
gpointer invocation_hint,
gpointer marshal_data);
+/* VOID:OBJECT,OBJECT (ck-marshal.list:3) */
+extern void ck_marshal_VOID__OBJECT_OBJECT (GClosure *closure,
+ GValue *return_value,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint,
+ gpointer marshal_data);
+
G_END_DECLS
#endif /* __ck_marshal_MARSHAL_H__ */
diff --git a/src/ck-marshal.list b/src/ck-marshal.list
index f9eed10..7f60efc 100644
--- a/src/ck-marshal.list
+++ b/src/ck-marshal.list
@@ -1,2 +1,3 @@
VOID:UINT,STRING
BOOLEAN:POINTER
+VOID:OBJECT,OBJECT
diff --git a/src/ck-run-programs.h b/src/ck-run-programs.h
index 77cdf48..07f4086 100644
--- a/src/ck-run-programs.h
+++ b/src/ck-run-programs.h
@@ -30,9 +30,6 @@ G_BEGIN_DECLS
void ck_run_programs (const char *dirpath, const char *action, char **extra_env);
-void ck_session_run_programs (CkSession *session, const char *action);
-
-
G_END_DECLS
#endif /* __CK_RUN_PROGRAMS_H */
diff --git a/src/ck-seat-glue.h b/src/ck-seat-glue.h
index a9db6f2..316d929 100644
--- a/src/ck-seat-glue.h
+++ b/src/ck-seat-glue.h
@@ -53,7 +53,7 @@ G_BEGIN_DECLS
#endif /* !G_ENABLE_DEBUG */
-/* BOOLEAN:POINTER,POINTER (/tmp/dbus-binding-tool-c-marshallers.RK8LXU:1) */
+/* BOOLEAN:POINTER,POINTER (/tmp/dbus-binding-tool-c-marshallers.SGA4YU:1) */
extern void dbus_glib_marshal_ck_seat_BOOLEAN__POINTER_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
@@ -100,7 +100,7 @@ dbus_glib_marshal_ck_seat_BOOLEAN__POINTER_POINTER (GClosure *closure,
g_value_set_boolean (return_value, v_return);
}
-/* NONE:BOXED,POINTER (/tmp/dbus-binding-tool-c-marshallers.RK8LXU:2) */
+/* NONE:BOXED,POINTER (/tmp/dbus-binding-tool-c-marshallers.SGA4YU:2) */
extern void dbus_glib_marshal_ck_seat_VOID__BOXED_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
diff --git a/src/ck-seat.c b/src/ck-seat.c
index c2f70da..fedd900 100644
--- a/src/ck-seat.c
+++ b/src/ck-seat.c
@@ -67,8 +67,11 @@ struct CkSeatPrivate
enum {
ACTIVE_SESSION_CHANGED,
- SESSION_ADDED,
+ ACTIVE_SESSION_CHANGED_FULL,
+ SESSION_ADDED, /* Carries the session as path for D-Bus */
+ SESSION_ADDED_FULL, /* Carries the session as CkSession for other uses */
SESSION_REMOVED,
+ SESSION_REMOVED_FULL,
DEVICE_ADDED,
DEVICE_REMOVED,
LAST_SIGNAL
@@ -480,15 +483,17 @@ static void
change_active_session (CkSeat *seat,
CkSession *session)
{
- char *ssid;
+ char *ssid;
+ CkSession *old_session;
if (seat->priv->active_session == session) {
return;
}
- if (seat->priv->active_session != NULL) {
- ck_session_set_active (seat->priv->active_session, FALSE, NULL);
- g_object_unref (seat->priv->active_session);
+ old_session = seat->priv->active_session;
+
+ if (old_session != NULL) {
+ ck_session_set_active (old_session, FALSE, NULL);
}
seat->priv->active_session = session;
@@ -502,8 +507,21 @@ change_active_session (CkSeat *seat,
g_debug ("Active session changed: %s", ssid ? ssid : "(null)");
+ /* The order of signal emission matters here. The manager
+ * dumps the database when receiving the
+ * 'active-session-changed-full' signal and does callout
+ * handling. dbus-glib will then send out a D-Bus on the
+ * 'active-session-changed' signal. Since the D-Bus signal
+ * must be sent when the database dump is finished it is
+ * important that the '-full' signalled is emitted first. */
+
+ g_signal_emit (seat, signals [ACTIVE_SESSION_CHANGED_FULL], 0, old_session, session);
g_signal_emit (seat, signals [ACTIVE_SESSION_CHANGED], 0, ssid);
+ if (old_session != NULL) {
+ g_object_unref (old_session);
+ }
+
g_free (ssid);
}
@@ -586,9 +604,13 @@ ck_seat_remove_session (CkSeat *seat,
* unref until the signal is emitted */
g_hash_table_steal (seat->priv->sessions, ssid);
- ck_session_run_programs (session, "session_removed");
-
g_debug ("Emitting session-removed: %s", ssid);
+
+ /* The order of signal emission matters here, too, for similar
+ * reasons as for 'session-added'/'session-added-full'. See
+ * above. */
+
+ g_signal_emit (seat, signals [SESSION_REMOVED_FULL], 0, session);
g_signal_emit (seat, signals [SESSION_REMOVED], 0, ssid);
/* try to change the active session */
@@ -624,10 +646,12 @@ ck_seat_add_session (CkSeat *seat,
g_signal_connect_object (session, "activate", G_CALLBACK (session_activate), seat, 0);
/* FIXME: attach to property notify signals? */
- ck_session_run_programs (session, "session_added");
-
g_debug ("Emitting added signal: %s", ssid);
+ /* The order of signal emission matters here, too. See
+ * above. */
+
+ g_signal_emit (seat, signals [SESSION_ADDED_FULL], 0, session);
g_signal_emit (seat, signals [SESSION_ADDED], 0, ssid);
maybe_update_active_session (seat);
@@ -741,8 +765,8 @@ active_vt_changed (CkVtMonitor *vt_monitor,
update_active_vt (seat, num);
}
-static gboolean
-register_seat (CkSeat *seat)
+gboolean
+ck_seat_register (CkSeat *seat)
{
GError *error = NULL;
@@ -920,6 +944,15 @@ ck_seat_class_init (CkSeatClass *klass)
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE,
1, G_TYPE_STRING);
+ signals [ACTIVE_SESSION_CHANGED_FULL] = g_signal_new ("active-session-changed-full",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ ck_marshal_VOID__OBJECT_OBJECT,
+ G_TYPE_NONE,
+ 2, CK_TYPE_SESSION, CK_TYPE_SESSION);
signals [SESSION_ADDED] = g_signal_new ("session-added",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
@@ -929,6 +962,15 @@ ck_seat_class_init (CkSeatClass *klass)
g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE,
1, DBUS_TYPE_G_OBJECT_PATH);
+ signals [SESSION_ADDED_FULL] = g_signal_new ("session-added-full",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1, CK_TYPE_SESSION);
signals [SESSION_REMOVED] = g_signal_new ("session-removed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
@@ -938,7 +980,15 @@ ck_seat_class_init (CkSeatClass *klass)
g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE,
1, DBUS_TYPE_G_OBJECT_PATH);
-
+ signals [SESSION_REMOVED_FULL] = g_signal_new ("session-removed-full",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1, CK_TYPE_SESSION);
signals [DEVICE_ADDED] = g_signal_new ("device-added",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
@@ -1023,19 +1073,12 @@ ck_seat_new (const char *sid,
CkSeatKind kind)
{
GObject *object;
- gboolean res;
object = g_object_new (CK_TYPE_SEAT,
"id", sid,
"kind", kind,
NULL);
- res = register_seat (CK_SEAT (object));
- if (! res) {
- g_object_unref (object);
- return NULL;
- }
-
return CK_SEAT (object);
}
@@ -1045,7 +1088,6 @@ ck_seat_new_with_devices (const char *sid,
GPtrArray *devices)
{
GObject *object;
- gboolean res;
int i;
object = g_object_new (CK_TYPE_SEAT,
@@ -1059,12 +1101,6 @@ ck_seat_new_with_devices (const char *sid,
}
}
- res = register_seat (CK_SEAT (object));
- if (! res) {
- g_object_unref (object);
- return NULL;
- }
-
return CK_SEAT (object);
}
@@ -1083,6 +1119,8 @@ ck_seat_new_from_file (const char *sid,
gsize ndevices;
gsize i;
+ seat = NULL;
+
key_file = g_key_file_new ();
error = NULL;
res = g_key_file_load_from_file (key_file,
@@ -1092,24 +1130,24 @@ ck_seat_new_from_file (const char *sid,
if (! res) {
g_warning ("Unable to load seats from file %s: %s", path, error->message);
g_error_free (error);
- return NULL;
+ goto out;
}
group = g_key_file_get_start_group (key_file);
if (group == NULL || strcmp (group, "Seat Entry") != 0) {
g_warning ("Not a seat file: %s", path);
- return NULL;
+ goto out;
}
hidden = g_key_file_get_boolean (key_file, group, "Hidden", NULL);
if (hidden) {
g_debug ("Seat is hidden");
- return NULL;
+ goto out;
}
device_list = g_key_file_get_string_list (key_file, group, "Devices", &ndevices, NULL);
- g_debug ("Creating seat %s with %d devices", sid, ndevices);
+ g_debug ("Creating seat %s with %zd devices", sid, ndevices);
devices = g_ptr_array_sized_new (ndevices);
@@ -1137,17 +1175,110 @@ ck_seat_new_from_file (const char *sid,
g_strfreev (split);
}
-
+ g_strfreev (device_list);
g_free (group);
seat = ck_seat_new_with_devices (sid, CK_SEAT_KIND_STATIC, devices);
-
g_ptr_array_free (devices, TRUE);
+out:
+
+ g_key_file_free (key_file);
+
return seat;
}
static void
+env_add_session_info (CkSession *session,
+ const char *prefix,
+ char **extra_env,
+ int *n)
+{
+ char *s;
+ gboolean b;
+ guint u;
+
+ if (session == NULL) {
+ return;
+ }
+
+ if (ck_session_get_id (session, &s, NULL) && s != NULL && *s != '\0') {
+ extra_env[(*n)++] = g_strdup_printf ("%sID=%s", prefix, s);
+ g_free (s);
+ }
+
+ if (ck_session_get_session_type (session, &s, NULL) && s != NULL && *s != '\0') {
+ extra_env[(*n)++] = g_strdup_printf ("%sTYPE=%s", prefix, s);
+ g_free (s);
+ }
+
+ if (ck_session_get_unix_user (session, &u, NULL)) {
+ extra_env[(*n)++] = g_strdup_printf ("%sUSER_UID=%u", prefix, u);
+ }
+
+ if (ck_session_get_display_device (session, &s, NULL) && s != NULL && *s != '\0') {
+ extra_env[(*n)++] = g_strdup_printf ("%sDISPLAY_DEVICE=%s", prefix, s);
+ g_free (s);
+ }
+
+ if (ck_session_get_x11_display_device (session, &s, NULL) && s != NULL && *s != '\0') {
+ extra_env[(*n)++] = g_strdup_printf ("%sX11_DISPLAY_DEVICE=%s", prefix, s);
+ g_free (s);
+ }
+
+ if (ck_session_get_x11_display (session, &s, NULL) && s != NULL && *s != '\0') {
+ extra_env[(*n)++] = g_strdup_printf ("%sX11_DISPLAY=%s", prefix, s);
+ g_free (s);
+ }
+
+ if (ck_session_get_remote_host_name (session, &s, NULL) && s != NULL && *s != '\0') {
+ extra_env[(*n)++] = g_strdup_printf ("%sREMOTE_HOST_NAME=%s", prefix, s);
+ g_free (s);
+ }
+
+ if (ck_session_is_local (session, &b, NULL))
+ extra_env[(*n)++] = g_strdup_printf ("%sIS_LOCAL=%s", prefix, b ? "true" : "false");
+}
+
+void
+ck_seat_run_programs (CkSeat *seat,
+ CkSession *old_session,
+ CkSession *new_session,
+ const char *action)
+{
+ int n;
+ char *extra_env[18]; /* be sure to adjust this as needed when
+ * you add more variables to the callout's
+ * environment */
+
+ n = 0;
+
+ extra_env[n++] = g_strdup_printf ("CK_SEAT_ID=%s", seat->priv->id);
+
+ /* Callout scripts/binaries should check if CK_SEAT_SESSION_ID
+ * resp. CK_SEAT_OLD_SESSON_ID is set to figure out if there
+ * will be an active session after the switch, or if there was
+ * one before. At least one of those environment variables
+ * will be set, possibly both. Only after checking these
+ * variables the script should check for the other session
+ * property variables. */
+
+ env_add_session_info (old_session, "CK_SEAT_OLD_SESSION_", extra_env, &n);
+ env_add_session_info (new_session, "CK_SEAT_SESSION_", extra_env, &n);
+
+ extra_env[n++] = NULL;
+
+ g_assert(n <= G_N_ELEMENTS(extra_env));
+
+ ck_run_programs (SYSCONFDIR "/ConsoleKit/run-seat.d", action, extra_env);
+ ck_run_programs (PREFIX "/lib/ConsoleKit/run-seat.d", action, extra_env);
+
+ for (n = 0; extra_env[n] != NULL; n++) {
+ g_free (extra_env[n]);
+ }
+}
+
+static void
dump_seat_session_iter (char *id,
CkSession *session,
GString *str)
@@ -1232,4 +1363,3 @@ ck_seat_dump (CkSeat *seat,
g_free (group_name);
}
-
diff --git a/src/ck-seat.h b/src/ck-seat.h
index 5977781..fb9a955 100644
--- a/src/ck-seat.h
+++ b/src/ck-seat.h
@@ -91,6 +91,13 @@ CkSeat * ck_seat_new_with_devices (const char *sid,
CkSeatKind kind,
GPtrArray *devices);
+gboolean ck_seat_register (CkSeat *seat);
+
+void ck_seat_run_programs (CkSeat *seat,
+ CkSession *old_session,
+ CkSession *new_session,
+ const char *action);
+
void ck_seat_dump (CkSeat *seat,
GKeyFile *key_file);
@@ -103,9 +110,6 @@ gboolean ck_seat_add_session (CkSeat *seat,
gboolean ck_seat_remove_session (CkSeat *seat,
CkSession *session,
GError **error);
-gboolean ck_seat_set_active_session (CkSeat *seat,
- CkSession *session,
- GError **error);
gboolean ck_seat_add_device (CkSeat *seat,
GValueArray *device,
GError **error);
diff --git a/src/ck-session-glue.h b/src/ck-session-glue.h
index b121358..2984bda 100644
--- a/src/ck-session-glue.h
+++ b/src/ck-session-glue.h
@@ -53,7 +53,7 @@ G_BEGIN_DECLS
#endif /* !G_ENABLE_DEBUG */
-/* NONE:BOOLEAN,POINTER (/tmp/dbus-binding-tool-c-marshallers.CAALXU:1) */
+/* NONE:BOOLEAN,POINTER (/tmp/dbus-binding-tool-c-marshallers.3QM4YU:1) */
extern void dbus_glib_marshal_ck_session_VOID__BOOLEAN_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
@@ -97,7 +97,7 @@ dbus_glib_marshal_ck_session_VOID__BOOLEAN_POINTER (GClosure *closure,
}
#define dbus_glib_marshal_ck_session_NONE__BOOLEAN_POINTER dbus_glib_marshal_ck_session_VOID__BOOLEAN_POINTER
-/* BOOLEAN:POINTER,POINTER (/tmp/dbus-binding-tool-c-marshallers.CAALXU:2) */
+/* BOOLEAN:POINTER,POINTER (/tmp/dbus-binding-tool-c-marshallers.3QM4YU:2) */
extern void dbus_glib_marshal_ck_session_BOOLEAN__POINTER_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
@@ -144,7 +144,7 @@ dbus_glib_marshal_ck_session_BOOLEAN__POINTER_POINTER (GClosure *closure,
g_value_set_boolean (return_value, v_return);
}
-/* NONE:POINTER (/tmp/dbus-binding-tool-c-marshallers.CAALXU:3) */
+/* NONE:POINTER (/tmp/dbus-binding-tool-c-marshallers.3QM4YU:3) */
#define dbus_glib_marshal_ck_session_VOID__POINTER g_cclosure_marshal_VOID__POINTER
#define dbus_glib_marshal_ck_session_NONE__POINTER dbus_glib_marshal_ck_session_VOID__POINTER
diff --git a/src/ck-session-leader.c b/src/ck-session-leader.c
index 322b7fd..3702602 100644
--- a/src/ck-session-leader.c
+++ b/src/ck-session-leader.c
@@ -689,7 +689,6 @@ ck_session_leader_dump (CkSessionLeader *session_leader,
g_key_file_set_string (key_file, group_name, "session", session_leader->priv->session_id);
g_key_file_set_integer (key_file, group_name, "uid", session_leader->priv->uid);
g_key_file_set_integer (key_file, group_name, "pid", session_leader->priv->pid);
- g_key_file_set_string (key_file, group_name, "cookie", session_leader->priv->cookie);
g_key_file_set_string (key_file, group_name, "service_name", session_leader->priv->service_name);
g_free (group_name);
diff --git a/src/ck-session.c b/src/ck-session.c
index 4009ee1..d8db9dd 100644
--- a/src/ck-session.c
+++ b/src/ck-session.c
@@ -399,7 +399,6 @@ ck_session_set_active (CkSession *session,
if (session->priv->active != active) {
session->priv->active = active;
- ck_session_run_programs (session, "session_active_changed");
g_signal_emit (session, signals [ACTIVE_CHANGED], 0, active);
}
@@ -1285,6 +1284,8 @@ ck_session_run_programs (CkSession *session,
extra_env[n++] = g_strdup_printf ("CK_SESSION_IS_LOCAL=%s", session->priv->is_local ? "true" : "false");
extra_env[n++] = NULL;
+ g_assert(n <= G_N_ELEMENTS(extra_env));
+
ck_run_programs (SYSCONFDIR "/ConsoleKit/run-session.d", action, extra_env);
ck_run_programs (PREFIX "/lib/ConsoleKit/run-session.d", action, extra_env);
@@ -1306,10 +1307,6 @@ ck_session_dump (CkSession *session,
group_name,
"seat",
NONULL_STRING (session->priv->seat_id));
- g_key_file_set_string (key_file,
- group_name,
- "cookie",
- NONULL_STRING (session->priv->cookie));
if (session->priv->session_type != NULL) {
g_key_file_set_string (key_file,
group_name,
@@ -1362,4 +1359,3 @@ ck_session_dump (CkSession *session,
g_free (group_name);
}
-
diff --git a/src/ck-session.h b/src/ck-session.h
index c9ebd08..b6b565b 100644
--- a/src/ck-session.h
+++ b/src/ck-session.h
@@ -76,6 +76,9 @@ CkSession * ck_session_new_with_parameters (const char *ss
void ck_session_dump (CkSession *session,
GKeyFile *key_file);
+void ck_session_run_programs (CkSession *session,
+ const char *action);
+
gboolean ck_session_set_active (CkSession *session,
gboolean active,
diff --git a/src/ck-sysdeps-solaris.c b/src/ck-sysdeps-solaris.c
index cd17bf7..bc3b695 100644
--- a/src/ck-sysdeps-solaris.c
+++ b/src/ck-sysdeps-solaris.c
@@ -286,6 +286,7 @@ ck_unix_pid_get_env_hash (pid_t pid)
}
out:
+ pclose (fp);
return hash;
}