#include <stdio.h>
#include <unistd.h>
-#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
-#include <sys/stat.h>
#include <pulse/xmalloc.h>
-#include <pulse/timeval.h>
-#include <pulsecore/core-error.h>
#include <pulsecore/module.h>
#include <pulsecore/log.h>
#include <pulsecore/hashmap.h>
#include <pulsecore/idxset.h>
-#include <pulsecore/core-util.h>
-#include <pulsecore/namereg.h>
-#include <pulsecore/core-scache.h>
#include <pulsecore/modargs.h>
#include <pulsecore/dbus-shared.h>
PA_MODULE_AUTHOR("Lennart Poettering");
PA_MODULE_DESCRIPTION("Create a client for each ConsoleKit session of this user");
PA_MODULE_VERSION(PACKAGE_VERSION);
-PA_MODULE_LOAD_ONCE(TRUE);
+PA_MODULE_LOAD_ONCE(true);
static const char* const valid_modargs[] = {
NULL
pa_core *core;
pa_dbus_connection *connection;
pa_hashmap *sessions;
+ bool filter_added;
};
static void add_session(struct userdata *u, const char *id) {
struct session *session;
pa_client_new_data data;
- dbus_error_init (&error);
+ dbus_error_init(&error);
if (pa_hashmap_get(u->sessions, id)) {
pa_log_warn("Duplicate session %s, ignoring.", id);
}
add_session(u, path);
- return DBUS_HANDLER_RESULT_HANDLED;
} else if (dbus_message_is_signal(message, "org.freedesktop.ConsoleKit.Seat", "SessionRemoved")) {
}
remove_session(u, path);
- return DBUS_HANDLER_RESULT_HANDLED;
}
finish:
dbus_error_init(&error);
+ /* If systemd's logind service is running, we shouldn't watch ConsoleKit
+ * but login */
+ if (access("/run/systemd/seats/", F_OK) >= 0)
+ return 0;
+
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
pa_log("Failed to parse module arguments");
goto fail;
goto fail;
}
- m->userdata = u = pa_xnew(struct userdata, 1);
+ m->userdata = u = pa_xnew0(struct userdata, 1);
u->core = m->core;
u->module = m;
u->connection = connection;
- u->sessions = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+ u->sessions = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) free_session);
if (!dbus_connection_add_filter(pa_dbus_connection_get(connection), filter_cb, u, NULL)) {
pa_log_error("Failed to add filter function");
goto fail;
}
+ u->filter_added = true;
+
if (pa_dbus_add_matches(
pa_dbus_connection_get(connection), &error,
"type='signal',sender='org.freedesktop.ConsoleKit',interface='org.freedesktop.ConsoleKit.Seat',member='SessionAdded'",
return -1;
}
-
void pa__done(pa_module *m) {
struct userdata *u;
- struct session *session;
pa_assert(m);
if (!(u = m->userdata))
return;
- if (u->sessions) {
- while ((session = pa_hashmap_steal_first(u->sessions)))
- free_session(session);
-
- pa_hashmap_free(u->sessions, NULL, NULL);
- }
+ if (u->sessions)
+ pa_hashmap_free(u->sessions);
if (u->connection) {
pa_dbus_remove_matches(
"type='signal',sender='org.freedesktop.ConsoleKit',interface='org.freedesktop.ConsoleKit.Seat',member='SessionAdded'",
"type='signal',sender='org.freedesktop.ConsoleKit',interface='org.freedesktop.ConsoleKit.Seat',member='SessionRemoved'", NULL);
- dbus_connection_remove_filter(pa_dbus_connection_get(u->connection), filter_cb, u);
+ if (u->filter_added)
+ dbus_connection_remove_filter(pa_dbus_connection_get(u->connection), filter_cb, u);
+
pa_dbus_connection_unref(u->connection);
}