hal: Branch 'master'
David Zeuthen
david at kemper.freedesktop.org
Sat Feb 17 18:22:11 PST 2007
hald/ck-tracker.c | 77 +++++++++++++++++++++++++++++++++++++++++++--------
hald/ck-tracker.h | 4 ++
hald/hald_dbus.c | 49 +++++++++++++++++++++++++++++++-
hald/hald_runner.c | 12 +++++--
tools/Makefile.am | 5 +++
tools/hal-acl-tool.c | 20 ++++++-------
6 files changed, 139 insertions(+), 28 deletions(-)
New commits:
diff-tree 04ff0ba613b2dc3d9c3ffabac2399d992a8d7363 (from b23a5a78919e4d3ea52e152c82ce8734edddbe2a)
Author: David Zeuthen <davidz at redhat.com>
Date: Sat Feb 17 21:22:07 2007 -0500
use $(localstatedir) instead of /var and make hald DTRT when CK goes away
Doing the "right thing" when ConsoleKit goes away / reappears
basically sums up to calling "hal-acl-tool --reconfigure" such that
ACL's granted to users based upon seat/sessions are removed.
See
http://lists.freedesktop.org/archives/hal/2007-February/007180.html
and surrounding messages for discussion.
Also fix up some code to be conditional on whether we have ConsoleKit or not.
diff --git a/hald/ck-tracker.c b/hald/ck-tracker.c
index 7276ad6..02d7bf2 100644
--- a/hald/ck-tracker.c
+++ b/hald/ck-tracker.c
@@ -63,6 +63,8 @@ struct CKTracker_s {
CKSessionAddedCB session_added_cb;
CKSessionRemovedCB session_removed_cb;
CKSessionActiveChangedCB session_active_changed_cb;
+ CKServiceDisappearedCB service_disappeared_cb;
+ CKServiceAppearedCB service_appeared_cb;
GSList *seats;
GSList *sessions;
};
@@ -371,24 +373,33 @@ ck_tracker_ref (CKTracker *tracker)
tracker->refcount++;
}
+static void
+ck_tracker_remove_all_seats_and_sessions (CKTracker *tracker)
+{
+ GSList *i;
+
+ for (i = tracker->sessions; i != NULL; i = g_slist_next (i)) {
+ CKSession *session = (CKSession *) i->data;
+ ck_session_unref (session);
+ }
+ g_slist_free (tracker->sessions);
+ tracker->sessions = NULL;
+
+ for (i = tracker->seats; i != NULL; i = g_slist_next (i)) {
+ CKSeat *seat = (CKSeat *) i->data;
+ ck_seat_unref (seat);
+ }
+ g_slist_free (tracker->seats);
+ tracker->seats = NULL;
+}
+
void
ck_tracker_unref (CKTracker *tracker)
{
tracker->refcount--;
if (tracker->refcount == 0) {
- GSList *i;
-
- for (i = tracker->sessions; i != NULL; i = g_slist_next (i)) {
- CKSession *session = (CKSession *) i->data;
- ck_session_unref (session);
- }
-
- for (i = tracker->seats; i != NULL; i = g_slist_next (i)) {
- CKSeat *seat = (CKSeat *) i->data;
- ck_seat_unref (seat);
- }
-
+ ck_tracker_remove_all_seats_and_sessions (tracker);
tracker->dbus_connection = NULL;
}
}
@@ -423,6 +434,17 @@ ck_tracker_set_session_active_changed_cb
tracker->session_active_changed_cb = cb;
}
+void
+ck_tracker_set_service_disappeared_cb (CKTracker *tracker, CKServiceDisappearedCB cb)
+{
+ tracker->service_disappeared_cb = cb;
+}
+
+void
+ck_tracker_set_service_appeared_cb (CKTracker *tracker, CKServiceAppearedCB cb)
+{
+ tracker->service_appeared_cb = cb;
+}
void
ck_tracker_process_system_bus_message (CKTracker *tracker, DBusMessage *message)
@@ -546,8 +568,39 @@ ck_tracker_process_system_bus_message (C
if (i == NULL) {
HAL_ERROR (("No such session '%s'", session_objpath));
}
+ } else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
+ char *name;
+ char *old_service_name;
+ char *new_service_name;
+
+ if (!dbus_message_get_args (message, NULL,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_STRING, &old_service_name,
+ DBUS_TYPE_STRING, &new_service_name,
+ DBUS_TYPE_INVALID)) {
+ HAL_ERROR (("Invalid NameOwnerChanged signal from bus!"));
+ goto out;
+ }
+
+ if (strlen (new_service_name) == 0 && strcmp (name, "org.freedesktop.ConsoleKit") == 0) {
+ HAL_INFO (("uh, oh, ConsoleKit went away!"));
+ ck_tracker_remove_all_seats_and_sessions (tracker);
+ if (tracker->service_disappeared_cb != NULL) {
+ tracker->service_disappeared_cb (tracker, tracker->user_data);
+ }
+ }
+
+ if (strlen (old_service_name) == 0 && strcmp (name, "org.freedesktop.ConsoleKit") == 0) {
+ HAL_INFO (("ConsoleKit reappeared!"));
+ ck_tracker_init (tracker);
+ if (tracker->service_appeared_cb != NULL) {
+ tracker->service_appeared_cb (tracker, tracker->user_data);
+ }
+ }
+
}
+
out:
;
}
diff --git a/hald/ck-tracker.h b/hald/ck-tracker.h
index 6c3147b..6f8b5dd 100644
--- a/hald/ck-tracker.h
+++ b/hald/ck-tracker.h
@@ -41,6 +41,8 @@ typedef struct CKSession_s CKSession;
typedef void (*CKSessionAddedCB) (CKTracker *tracker, CKSession *session, void *user_data);
typedef void (*CKSessionRemovedCB) (CKTracker *tracker, CKSession *session, void *user_data);
typedef void (*CKSessionActiveChangedCB) (CKTracker *tracker, CKSession *session, void *user_data);
+typedef void (*CKServiceDisappearedCB) (CKTracker *tracker, void *user_data);
+typedef void (*CKServiceAppearedCB) (CKTracker *tracker, void *user_data);
CKTracker *ck_tracker_new (void);
void ck_tracker_set_system_bus_connection (CKTracker *tracker, DBusConnection *system_bus_connection);
@@ -48,6 +50,8 @@ void ck_tracker_set_user_data
void ck_tracker_set_session_added_cb (CKTracker *tracker, CKSessionAddedCB cb);
void ck_tracker_set_session_removed_cb (CKTracker *tracker, CKSessionRemovedCB cb);
void ck_tracker_set_session_active_changed_cb (CKTracker *tracker, CKSessionActiveChangedCB cb);
+void ck_tracker_set_service_disappeared_cb (CKTracker *tracker, CKServiceDisappearedCB cb);
+void ck_tracker_set_service_appeared_cb (CKTracker *tracker, CKServiceAppearedCB cb);
/* TODO: also handle seat_added, seat_removed */
gboolean ck_tracker_init (CKTracker *tracker);
diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c
index 9cc75b9..ae70232 100644
--- a/hald/hald_dbus.c
+++ b/hald/hald_dbus.c
@@ -4404,6 +4404,8 @@ hald_dbus_local_server_shutdown (void)
}
}
+#ifdef HAVE_CONKIT
+
static void
hald_dbus_session_added (CKTracker *tracker, CKSession *session, void *user_data)
{
@@ -4542,6 +4544,48 @@ out:
;
}
+static void
+hald_dbus_ck_availability_changed (gboolean ck_available)
+{
+ HalDevice *d;
+ char *extra_env[1] = {NULL};
+
+ d = hal_device_store_find (hald_get_gdl (), "/org/freedesktop/Hal/devices/computer");
+ if (d == NULL) {
+ d = hal_device_store_find (hald_get_tdl (), "/org/freedesktop/Hal/devices/computer");
+ }
+ if (d == NULL) {
+ HAL_ERROR (("No computer object?!?"));
+ goto out;
+ }
+
+ hald_runner_run (d,
+ "hal-acl-tool --reconfigure",
+ extra_env,
+ HAL_HELPER_TIMEOUT,
+ NULL, /* run_terminated_cb */
+ NULL /* userdata1 */,
+ NULL /* userdata2 */ );
+out:
+ ;
+}
+
+static void
+hald_dbus_ck_disappeared (CKTracker *tracker, void *user_data)
+{
+ HAL_INFO (("In hald_dbus_ck_disappeared"));
+ hald_dbus_ck_availability_changed (FALSE);
+}
+
+static void
+hald_dbus_ck_appeared (CKTracker *tracker, void *user_data)
+{
+ HAL_INFO (("In hald_dbus_ck_appeared"));
+ hald_dbus_ck_availability_changed (TRUE);
+}
+
+#endif /* HAVE_CONKIT */
+
gboolean
hald_dbus_init_preprobe (void)
{
@@ -4597,9 +4641,10 @@ hald_dbus_init_preprobe (void)
ck_tracker_set_session_added_cb (ck_tracker, hald_dbus_session_added);
ck_tracker_set_session_removed_cb (ck_tracker, hald_dbus_session_removed);
ck_tracker_set_session_active_changed_cb (ck_tracker, hald_dbus_session_active_changed);
+ ck_tracker_set_service_disappeared_cb (ck_tracker, hald_dbus_ck_disappeared);
+ ck_tracker_set_service_appeared_cb (ck_tracker, hald_dbus_ck_appeared);
if (!ck_tracker_init (ck_tracker)) {
- ck_tracker_unref (ck_tracker);
- DIE (("Could not initialize seats and sessions from ConsoleKit"));
+ HAL_WARNING (("Could not initialize seats and sessions from ConsoleKit"));
}
#endif /* HAVE_CONKIT */
diff --git a/hald/hald_runner.c b/hald/hald_runner.c
index 7eb7b14..008c2cf 100644
--- a/hald/hald_runner.c
+++ b/hald/hald_runner.c
@@ -644,8 +644,10 @@ call_notify (DBusPendingCall * pending,
g_array_append_vals (error, &value, 1);
}
- hb->cb (hb->d, exitt, return_code,
- (gchar **) error->data, hb->data1, hb->data2);
+ if (hb->cb != NULL) {
+ hb->cb (hb->d, exitt, return_code,
+ (gchar **) error->data, hb->data1, hb->data2);
+ }
if (hb->d != NULL)
g_object_unref (hb->d);
@@ -662,8 +664,10 @@ call_notify (DBusPendingCall * pending,
malformed:
/* Send a Fail callback on malformed messages */
HAL_ERROR (("Malformed or unexpected reply message"));
- hb->cb (hb->d, HALD_RUN_FAILED, return_code, NULL, hb->data1,
- hb->data2);
+ if (hb->cb != NULL) {
+ hb->cb (hb->d, HALD_RUN_FAILED, return_code, NULL, hb->data1,
+ hb->data2);
+ }
if (hb->d != NULL)
g_object_unref (hb->d);
diff --git a/tools/Makefile.am b/tools/Makefile.am
index b5332e3..e594bde 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -125,5 +125,10 @@ check:
fi; \
done;
+install-data-local:
+ -$(mkdir_p) $(DESTDIR)$(localstatedir)/lib/hal
+ -chown $(HAL_USER):$(HAL_GROUP) $(DESTDIR)$(localstatedir)/lib/hal
+ -chmod 0700 $(DESTDIR)$(localstatedir)/lib/hal
+
clean-local :
rm -f *~
diff --git a/tools/hal-acl-tool.c b/tools/hal-acl-tool.c
index d49d097..2d8b6ea 100644
--- a/tools/hal-acl-tool.c
+++ b/tools/hal-acl-tool.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <sys/file.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
@@ -218,7 +219,7 @@ acl_apply_changes (GSList *new_acl_list,
}
/* success; now atomically set the new list */
- g_file_set_contents ("/var/lib/hal/acl-list",
+ g_file_set_contents (PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list",
new_acl_file_contents,
strlen (new_acl_file_contents),
NULL);
@@ -247,9 +248,9 @@ get_current_acl_list (GSList **l)
f = NULL;
ret = FALSE;
- f = fopen ("/var/lib/hal/acl-list", "r");
+ f = fopen (PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list", "r");
if (f == NULL) {
- printf ("%d: cannot open /var/lib/hal/acl-list\n", getpid ());
+ printf ("%d: cannot open " PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list\n", getpid ());
goto out;
}
@@ -982,15 +983,14 @@ acl_lock (void)
if (lock_acl_fd >= 0)
return TRUE;
- printf ("%d: attempting to get lock on /var/lib/hal/acl-list\n", getpid ());
-
- lock_acl_fd = open ("/var/lib/hal/acl-list", O_CREAT | O_RDWR);
- /* TODO: set correct mode, owner etc. */
+ printf ("%d: attempting to get lock on " PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list\n", getpid ());
+ lock_acl_fd = open (PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list", O_CREAT | O_RDWR);
if (lock_acl_fd < 0) {
- printf ("%d: error opening/creating /var/lib/hal/acl-list\n", getpid ());
+ printf ("%d: error opening/creating " PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list\n", getpid ());
return FALSE;
}
+
tryagain:
#if sun
@@ -1004,7 +1004,7 @@ tryagain:
return FALSE;
}
- printf ("%d: got lock on /var/lib/hal/acl-list\n", getpid ());
+ printf ("%d: got lock on " PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list\n", getpid ());
return TRUE;
}
@@ -1018,7 +1018,7 @@ acl_unlock (void)
#endif
close (lock_acl_fd);
lock_acl_fd = -1;
- printf ("%d: released lock on /var/lib/hal/acl-list\n", getpid ());
+ printf ("%d: released lock on " PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list\n", getpid ());
}
More information about the hal-commit
mailing list