hal: Branch 'master' - 3 commits
David Zeuthen
david at kemper.freedesktop.org
Mon Mar 3 21:17:22 PST 2008
hald-runner/runner.c | 3
hald/device_pm.c | 2
hald/hald_dbus.c | 282 ++++++++++++++++++++++++++++++++-------------------
hald/util.c | 16 +-
tools/hal-acl-tool.c | 8 +
5 files changed, 194 insertions(+), 117 deletions(-)
New commits:
commit f047f03869b2f5d20de1eafdae02d4ebc6eddc06
Author: David Zeuthen <davidz at redhat.com>
Date: Tue Mar 4 00:10:22 2008 -0500
properly serialize the calls to 'hal-acl-tool --reconfigure'
This fixes a long standing bug where ACL's were sometimes wrong when
VT switching and when resuming from STR or STD. The problem was that
we would get a bunch of events from ConsoleKit at once, say
1. Session1 -> Inactive
2. Session2 -> Active
3. Session2 -> Inactive
4. Session1 -> Active
So for events 1-4 we would spawn 'hal-acl-tool --reconfigure' with a
carefully prepared environment reflecting the ConsoleKit state. All
four copies would start at once and race to get the lock. Which means
that it was undefined what other they execute in.
It's very easy to reproduce this; just try running
# chvt 1; chvt 7; sleep 1; getfacl /dev/snd/pcmC0D0p
(or some other device node)
a few times and observe that sometimes you wouldn't get an ACL.
This patch serializes the events and fixes this bug.
diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c
index ab87cef..8ad812e 100644
--- a/hald/hald_dbus.c
+++ b/hald/hald_dbus.c
@@ -5280,9 +5280,9 @@ local_server_message_handler (DBusConnection *connection,
GSList *i;
GSList *j;
- HAL_INFO (("************************"));
- HAL_INFO (("Client to local_server was disconnected for %x", connection));
- HAL_INFO (("************************"));
+ //HAL_INFO (("************************"));
+ //HAL_INFO (("Client to local_server was disconnected for %x", connection));
+ //HAL_INFO (("************************"));
for (i = helper_interface_handlers; i != NULL; i = j) {
HelperInterfaceHandler *hih = i->data;
@@ -5324,9 +5324,9 @@ local_server_message_handler (DBusConnection *connection,
static void
local_server_unregister_handler (DBusConnection *connection, void *user_data)
{
- HAL_INFO (("***************************"));
- HAL_INFO (("********* unregistered %x", connection));
- HAL_INFO (("***************************"));
+ //HAL_INFO (("***************************"));
+ //HAL_INFO (("********* unregistered %x", connection));
+ //HAL_INFO (("***************************"));
}
static void
@@ -5338,9 +5338,9 @@ local_server_handle_connection (DBusServer *server,
&local_server_message_handler,
NULL, NULL, NULL, NULL};
- HAL_INFO (("***************************"));
- HAL_INFO (("********* got a connection %x", new_connection));
- HAL_INFO (("***************************"));
+ //HAL_INFO (("***************************"));
+ //HAL_INFO (("********* got a connection %x", new_connection));
+ //HAL_INFO (("***************************"));
/*dbus_connection_add_filter (new_connection, server_filter_function, NULL, NULL);*/
@@ -5405,96 +5405,6 @@ hald_dbus_local_server_shutdown (void)
#ifdef HAVE_CONKIT
static void
-hald_dbus_session_added (CKTracker *tracker, CKSession *session, void *user_data)
-{
- HalDevice *d;
- char **programs;
- char *extra_env[5] = {"HALD_ACTION=session_add",
- NULL /* "HALD_SESSION_ADD_SESSION_ID=" */,
- NULL /* "HALD_SESSION_ADD_SESSION_UID=" */,
- NULL /* "HALD_SESSION_ADD_SESSION_IS_ACTIVE=" */,
- NULL};
-
- HAL_INFO (("In hald_dbus_session_added for session '%s' on seat '%s'",
- ck_session_get_id (session),
- ck_session_get_seat (session) != NULL ? ck_seat_get_id (ck_session_get_seat (session)) : "(NONE)"));
-
- 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) {
- goto out;
- }
-
- programs = hal_device_property_dup_strlist_as_strv (d, "info.callouts.session_add");
- if (programs == NULL) {
- goto out;
- }
-
- extra_env[1] = g_strdup_printf ("HALD_SESSION_ADD_SESSION_ID=%s", ck_session_get_id (session));
- extra_env[2] = g_strdup_printf ("HALD_SESSION_ADD_SESSION_UID=%d", ck_session_get_user (session));
- extra_env[3] = g_strdup_printf ("HALD_SESSION_ADD_SESSION_IS_ACTIVE=%s",
- ck_session_is_active (session) ? "true" : "false");
- hal_callout_device (d,
- NULL /* callback */,
- NULL /* userdata1 */,
- NULL /* userdata2 */,
- programs,
- extra_env);
- g_free (extra_env[1]);
- g_free (extra_env[2]);
- g_free (extra_env[3]);
-out:
- ;
-}
-
-static void
-hald_dbus_session_removed (CKTracker *tracker, CKSession *session, void *user_data)
-{
- HalDevice *d;
- char **programs;
- char *extra_env[5] = {"HALD_ACTION=session_remove",
- NULL /* "HALD_SESSION_REMOVE_SESSION_ID=" */,
- NULL /* "HALD_SESSION_REMOVE_SESSION_UID=" */,
- NULL /* "HALD_SESSION_REMOVE_SESSION_IS_ACTIVE=" */,
- NULL};
-
- HAL_INFO (("In hald_dbus_session_removed for session '%s' on seat '%s'",
- ck_session_get_id (session),
- ck_session_get_seat (session) != NULL ? ck_seat_get_id (ck_session_get_seat (session)) : "(NONE)"));
-
- 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) {
- goto out;
- }
-
- programs = hal_device_property_dup_strlist_as_strv (d, "info.callouts.session_remove");
- if (programs == NULL) {
- goto out;
- }
-
- extra_env[1] = g_strdup_printf ("HALD_SESSION_REMOVE_SESSION_ID=%s", ck_session_get_id (session));
- extra_env[2] = g_strdup_printf ("HALD_SESSION_REMOVE_SESSION_UID=%d", ck_session_get_user (session));
- extra_env[3] = g_strdup_printf ("HALD_SESSION_REMOVE_SESSION_IS_ACTIVE=%s",
- ck_session_is_active (session) ? "true" : "false");
- hal_callout_device (d,
- NULL /* callback */,
- NULL /* userdata1 */,
- NULL /* userdata2 */,
- programs,
- extra_env);
- g_free (extra_env[1]);
- g_free (extra_env[2]);
- g_free (extra_env[3]);
-out:
- ;
-}
-
-static void
hald_dbus_seat_added (CKTracker *tracker, CKSeat *seat, void *user_data)
{
/* TODO: we could run callouts here... but they wouldn't do anything useful right now */
@@ -5593,6 +5503,87 @@ reconfigure_all_policy (void)
reconfigure_acl ();
}
+
+typedef struct {
+ HalDevice *d;
+ char **programs;
+ char **extra_env;
+} SessionChangesEntry;
+
+static GList *session_changes_queue = NULL;
+gboolean session_changes_is_running = FALSE;
+
+static void session_changes_process_queue (void);
+
+static void
+session_changes_done_cb (HalDevice *d, gpointer userdata1, gpointer userdata2)
+{
+ SessionChangesEntry *entry = userdata1;
+
+ HAL_INFO (("session_changes_done_cb"));
+
+ g_assert (entry->d == d);
+
+ /* hal_callout_device takes ownership of entry->programs so we don't free it here */
+ g_object_unref (entry->d);
+ g_strfreev (entry->extra_env);
+ g_free (entry);
+
+ session_changes_is_running = FALSE;
+
+ session_changes_process_queue ();
+}
+
+static void
+session_changes_process_queue (void)
+{
+ SessionChangesEntry *entry;
+
+ HAL_INFO (("session_changes_process_queue"));
+
+ /* nothing to run */
+ if (session_changes_queue == NULL)
+ return;
+
+ /* something is already running; wait for it to terminate */
+ if (session_changes_is_running)
+ return;
+
+ HAL_INFO ((" running element in queue"));
+
+ /* pop the first element */
+ entry = session_changes_queue->data;
+ session_changes_queue = g_list_remove (session_changes_queue, entry);
+
+ hal_callout_device (entry->d,
+ session_changes_done_cb, /* callback */
+ entry, /* userdata1 */
+ NULL, /* userdata2 */
+ entry->programs,
+ entry->extra_env);
+
+ session_changes_is_running = TRUE;
+}
+
+static void
+session_changes_push (HalDevice *d, char **programs, char **extra_env)
+{
+ SessionChangesEntry *entry;
+
+ HAL_INFO (("session_changes_push"));
+
+ entry = g_new0 (SessionChangesEntry, 1);
+ entry->d = g_object_ref (d);
+ entry->programs = g_strdupv (programs);
+ entry->extra_env = g_strdupv (extra_env);
+
+ /* push to end of queue */
+ session_changes_queue = g_list_append (session_changes_queue, entry);
+
+ /* only process the queue if there we are the only element */
+ session_changes_process_queue ();
+}
+
static void
hald_dbus_session_active_changed (CKTracker *tracker, CKSession *session, void *user_data)
{
@@ -5631,12 +5622,93 @@ hald_dbus_session_active_changed (CKTracker *tracker, CKSession *session, void *
extra_env[2] = g_strdup_printf ("HALD_SESSION_ACTIVE_CHANGED_SESSION_UID=%d", ck_session_get_user (session));
extra_env[3] = g_strdup_printf ("HALD_SESSION_ACTIVE_CHANGED_SESSION_IS_ACTIVE=%s",
ck_session_is_active (session) ? "true" : "false");
- hal_callout_device (d,
- NULL /* callback */,
- NULL /* userdata1 */,
- NULL /* userdata2 */,
- programs,
- extra_env);
+
+ session_changes_push (d, programs, extra_env);
+
+ g_free (extra_env[1]);
+ g_free (extra_env[2]);
+ g_free (extra_env[3]);
+out:
+ ;
+}
+
+static void
+hald_dbus_session_added (CKTracker *tracker, CKSession *session, void *user_data)
+{
+ HalDevice *d;
+ char **programs;
+ char *extra_env[5] = {"HALD_ACTION=session_add",
+ NULL /* "HALD_SESSION_ADD_SESSION_ID=" */,
+ NULL /* "HALD_SESSION_ADD_SESSION_UID=" */,
+ NULL /* "HALD_SESSION_ADD_SESSION_IS_ACTIVE=" */,
+ NULL};
+
+ HAL_INFO (("In hald_dbus_session_added for session '%s' on seat '%s'",
+ ck_session_get_id (session),
+ ck_session_get_seat (session) != NULL ? ck_seat_get_id (ck_session_get_seat (session)) : "(NONE)"));
+
+ 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) {
+ goto out;
+ }
+
+ programs = hal_device_property_dup_strlist_as_strv (d, "info.callouts.session_add");
+ if (programs == NULL) {
+ goto out;
+ }
+
+ extra_env[1] = g_strdup_printf ("HALD_SESSION_ADD_SESSION_ID=%s", ck_session_get_id (session));
+ extra_env[2] = g_strdup_printf ("HALD_SESSION_ADD_SESSION_UID=%d", ck_session_get_user (session));
+ extra_env[3] = g_strdup_printf ("HALD_SESSION_ADD_SESSION_IS_ACTIVE=%s",
+ ck_session_is_active (session) ? "true" : "false");
+
+ session_changes_push (d, programs, extra_env);
+
+ g_free (extra_env[1]);
+ g_free (extra_env[2]);
+ g_free (extra_env[3]);
+out:
+ ;
+}
+
+static void
+hald_dbus_session_removed (CKTracker *tracker, CKSession *session, void *user_data)
+{
+ HalDevice *d;
+ char **programs;
+ char *extra_env[5] = {"HALD_ACTION=session_remove",
+ NULL /* "HALD_SESSION_REMOVE_SESSION_ID=" */,
+ NULL /* "HALD_SESSION_REMOVE_SESSION_UID=" */,
+ NULL /* "HALD_SESSION_REMOVE_SESSION_IS_ACTIVE=" */,
+ NULL};
+
+ HAL_INFO (("In hald_dbus_session_removed for session '%s' on seat '%s'",
+ ck_session_get_id (session),
+ ck_session_get_seat (session) != NULL ? ck_seat_get_id (ck_session_get_seat (session)) : "(NONE)"));
+
+ 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) {
+ goto out;
+ }
+
+ programs = hal_device_property_dup_strlist_as_strv (d, "info.callouts.session_remove");
+ if (programs == NULL) {
+ goto out;
+ }
+
+ extra_env[1] = g_strdup_printf ("HALD_SESSION_REMOVE_SESSION_ID=%s", ck_session_get_id (session));
+ extra_env[2] = g_strdup_printf ("HALD_SESSION_REMOVE_SESSION_UID=%d", ck_session_get_user (session));
+ extra_env[3] = g_strdup_printf ("HALD_SESSION_REMOVE_SESSION_IS_ACTIVE=%s",
+ ck_session_is_active (session) ? "true" : "false");
+
+ session_changes_push (d, programs, extra_env);
+
g_free (extra_env[1]);
g_free (extra_env[2]);
g_free (extra_env[3]);
diff --git a/tools/hal-acl-tool.c b/tools/hal-acl-tool.c
index b4f8ea8..16bede9 100644
--- a/tools/hal-acl-tool.c
+++ b/tools/hal-acl-tool.c
@@ -1175,7 +1175,9 @@ tryagain:
goto tryagain;
return FALSE;
}
-
+
+ printf ("\n");
+ printf ("****************************************************\n");
printf ("%d: got lock on " PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list\n", getpid ());
return TRUE;
}
@@ -1183,6 +1185,9 @@ tryagain:
static void
acl_unlock (void)
{
+ printf ("\n");
+ printf ("****************************************************\n");
+ printf ("%d: releasing lock on " PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list\n", getpid ());
#if sun
lockf (lock_acl_fd, F_ULOCK, 0);
#else
@@ -1190,7 +1195,6 @@ acl_unlock (void)
#endif
close (lock_acl_fd);
lock_acl_fd = -1;
- printf ("%d: released lock on " PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list\n", getpid ());
}
int
commit 63976f27b91fba37fc36d6cf81d9336185f51546
Author: David Zeuthen <davidz at redhat.com>
Date: Mon Mar 3 23:49:22 2008 -0500
comment out debugging spew for now
diff --git a/hald/device_pm.c b/hald/device_pm.c
index 8a0262a..63e36d9 100644
--- a/hald/device_pm.c
+++ b/hald/device_pm.c
@@ -102,7 +102,7 @@ device_pm_abstract_props (HalDevice *d)
/* If the current voltage is unknown, smaller than 50% of design voltage (fd.o #8593)
* or greater than design, then use design voltage. */
if (voltage < (design_voltage/2) || voltage > design_voltage) {
- HAL_DEBUG (("Current voltage is unknown, smaller than 50%% or greater than design"));
+ //HAL_DEBUG (("Current voltage is unknown, smaller than 50%% or greater than design"));
voltage = design_voltage;
}
diff --git a/hald/util.c b/hald/util.c
index c6c6b80..8f2dbec 100644
--- a/hald/util.c
+++ b/hald/util.c
@@ -188,12 +188,12 @@ hal_util_get_int_from_file (const gchar *directory, const gchar *file, gint *res
f = fopen (path, "rb");
if (f == NULL) {
- HAL_ERROR (("Cannot open '%s'", path));
+ //HAL_ERROR (("Cannot open '%s'", path));
goto out;
}
if (fgets (buf, sizeof (buf), f) == NULL) {
- HAL_ERROR (("Cannot read from '%s'", path));
+ //HAL_ERROR (("Cannot read from '%s'", path));
goto out;
}
@@ -242,12 +242,12 @@ hal_util_get_uint64_from_file (const gchar *directory, const gchar *file, guint6
f = fopen (path, "rb");
if (f == NULL) {
- HAL_ERROR (("Cannot open '%s'", path));
+ //HAL_ERROR (("Cannot open '%s'", path));
goto out;
}
if (fgets (buf, sizeof (buf), f) == NULL) {
- HAL_ERROR (("Cannot read from '%s'", path));
+ //HAL_ERROR (("Cannot read from '%s'", path));
goto out;
}
@@ -301,12 +301,12 @@ hal_util_get_bcd2_from_file (const gchar *directory, const gchar *file, gint *re
f = fopen (path, "rb");
if (f == NULL) {
- HAL_ERROR (("Cannot open '%s'", path));
+ //HAL_ERROR (("Cannot open '%s'", path));
goto out;
}
if (fgets (buf, sizeof (buf), f) == NULL) {
- HAL_ERROR (("Cannot read from '%s'", path));
+ //HAL_ERROR (("Cannot read from '%s'", path));
goto out;
}
@@ -386,13 +386,13 @@ hal_util_get_string_from_file (const gchar *directory, const gchar *file)
f = fopen (path, "rb");
if (f == NULL) {
- HAL_ERROR (("Cannot open '%s'", path));
+ //HAL_ERROR (("Cannot open '%s'", path));
goto out;
}
buf[0] = '\0';
if (fgets (buf, sizeof (buf), f) == NULL) {
- HAL_ERROR (("Cannot read from '%s'", path));
+ //HAL_ERROR (("Cannot read from '%s'", path));
goto out;
}
commit 20dc74b537d4cf3447a86d12224db5e158ce0bef
Author: David Zeuthen <davidz at redhat.com>
Date: Mon Mar 3 23:48:10 2008 -0500
print more debug information
diff --git a/hald-runner/runner.c b/hald-runner/runner.c
index 4847655..1184ce2 100644
--- a/hald-runner/runner.c
+++ b/hald-runner/runner.c
@@ -151,7 +151,8 @@ run_exited(GPid pid, gint status, gpointer data)
run_data *rd = (run_data *)data;
char **error = NULL;
- printf("%s exited\n", rd->r->argv[0]);
+ printf("pid %d: rc=%d signaled=%d: %s\n",
+ pid, WEXITSTATUS(status), WIFSIGNALED(status), rd->r->argv[0]);
rd->watch = 0;
if (rd->sent_kill == TRUE) {
/* We send it a kill, so ignore */
More information about the hal-commit
mailing list