hal/hald Makefile.am, 1.41, 1.42 hald.c, 1.22, 1.23 property.c, 1.9,
1.10 run-hald.sh, 1.1, 1.2 util.c, NONE, 1.1 util.h, NONE, 1.1
David Zeuthen
david at freedesktop.org
Tue Feb 8 08:44:22 PST 2005
Update of /cvs/hal/hal/hald
In directory gabe:/tmp/cvs-serv19159/hald
Modified Files:
Makefile.am hald.c property.c run-hald.sh
Added Files:
util.c util.h
Log Message:
2005-02-08 David Zeuthen <davidz at redhat.com>
* hald/run-hald.sh: Update to include a few more paths
* hald/linux2/addons/Makefile.am: Add build rules for hald-addon-acpi
* hald/linux2/addons/addon-acpi.c: New file
* hald/linux2/pmu.c (pmu_synthesize_hotplug_events): Also look for
computer in the TDL
* hald/linux2/osspec.c (computer_callouts_add_done): New function
(osspec_probe): Run callouts for computer
* hald/linux2/classdev.c (add_classdev_probing_helper_done): Fix up
for the new helper
* hald/linux2/apm.c (apm_synthesize_hotplug_events): Also look for
computer in the TDL
* hald/linux2/acpi.c (acpi_synthesize_hotplug_events): Also look for
computer in the TDL
(acpi_generic_remove): Don't remove the device
(acpi_callouts_add_done): New function
(acpi_callouts_remove_done): New function
(hotplug_event_begin_add_acpi): Run add callouts
(hotplug_event_begin_remove_acpi): Run remove callouts
* hald/property.c (hal_property_to_string): Add code for string lists
* hald/hald.c (addon_terminated): New function
(gdl_store_changed): Run addons
(gdl_property_changed): Don't run property.d callouts
(gdl_capability_added): Don't run capability.d callouts
* hald/util.h: Move from hald/linux2 since this is generic.
Export the HalHelperData structure when doing
hal_util_helper invoke. Add prototypes for hal_util_terminate_
helper, hal_util_dup_strv_from_g_slist,
hal_util_callout_device_add, hal_util_callout_device_remove.
* hald/util.c: Move from hald/linux2 since this is generic.
(hal_util_terminate_helper): New function
(hal_util_helper_invoke): Renamed from helper_invoke. Accept
command line parameters (through g_shell_parse_argv). Accept a
strv of extra environement to set. Introduce that timeout==0 means
no timeout. Return the HalHelperData structure
(hal_util_dup_strv_from_g_slist): New convenience function; create
a new NULL-terminated string vector from a GSList of strings.
(callout_terminated): New function
(callout_do_next): New function
(hal_callout_device): New function
(hal_util_callout_device_add): New function
(hal_util_callout_device_remove): New function
* hald/linux2/util.[ch]: Remove
* hald/callout.[ch]: Remove since this functionality is now in util.[ch]
* hald/Makefile.am: Add util.[ch]
* hald/linux2/Makefile.am: Remove util.[ch]
Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/hald/Makefile.am,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- Makefile.am 31 Jan 2005 20:06:39 -0000 1.41
+++ Makefile.am 8 Feb 2005 16:44:20 -0000 1.42
@@ -39,7 +39,7 @@
hald_SOURCES = \
hald_marshal.h hald_marshal.c \
- callout.h callout.c \
+ util.h util.c \
device.h device.c \
device_info.h device_info.c \
device_store.h device_store.c \
Index: hald.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- hald.c 31 Jan 2005 20:06:39 -0000 1.22
+++ hald.c 8 Feb 2005 16:44:20 -0000 1.23
@@ -46,7 +46,6 @@
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
-#include "callout.h"
#include "logger.h"
#include "hald.h"
#include "device_store.h"
@@ -54,6 +53,7 @@
#include "osspec.h"
#include "hald_dbus.h"
#include "hald_conf.h"
+#include "util.h"
static void delete_pid(void) {
unlink(HALD_PID_FILE);
@@ -69,16 +69,69 @@
static HalDeviceStore *temporary_device_list = NULL;
+static GSList *running_addons = NULL;
+
+static void
+addon_terminated (HalDevice *d, gboolean timed_out, gint return_code,
+ gpointer data1, gpointer data2, HalHelperData *helper_data)
+{
+ running_addons = g_slist_remove (running_addons, helper_data);
+}
+
static void
gdl_store_changed (HalDeviceStore *store, HalDevice *device,
gboolean is_added, gpointer user_data)
{
- if (is_added)
- HAL_INFO (("Added device to GDL; udi=%s",
- hal_device_get_udi(device)));
- else
- HAL_INFO (("Removed device from GDL; udi=%s",
- hal_device_get_udi(device)));
+ if (is_added) {
+ GSList *addons;
+
+ HAL_INFO (("Added device to GDL; udi=%s", hal_device_get_udi(device)));
+
+ if ((addons = hal_device_property_get_strlist (device, "info.addons")) != NULL) {
+ GSList *i;
+
+ for (i = addons; i != NULL; i = g_slist_next (i)) {
+ const gchar *command_line;
+ HalHelperData *helper_data;
+ gchar *extra_env[2] = {"HALD_ACTION=addon", NULL};
+
+ command_line = (const gchar *) i->data;
+ helper_data = hal_util_helper_invoke (command_line, extra_env, device,
+ NULL, NULL,
+ addon_terminated, 0 /* no timeout */);
+
+ if (helper_data != NULL) {
+ HAL_INFO (("Invoked addon %s with pid %d for udi %s",
+ command_line, helper_data->pid, helper_data->d->udi));
+ running_addons = g_slist_prepend (running_addons, helper_data);
+ }
+ }
+ }
+ } else {
+ GSList *i;
+
+ HAL_INFO (("Removed device from GDL; udi=%s", hal_device_get_udi(device)));
+
+ start_from_beginning:
+
+ /* may have several addons running */
+ for (i = running_addons; i != NULL; i = g_slist_next (i)) {
+ HalHelperData *helper_data;
+
+ helper_data = (HalHelperData *) (i->data);
+ if (helper_data->d == device) {
+ HAL_INFO (("Terminating addon with pid %d for udi %s",
+ helper_data->pid, helper_data->d->udi));
+ /* will force a callback - the callback removes us from the list */
+ hal_util_terminate_helper (helper_data);
+ /* TODO: is it safe to remove an elem from a GSList and keep iterating?
+ * Better play it safe for now.
+ */
+ goto start_from_beginning;
+ }
+ }
+
+ }
/*hal_device_print (device);*/
@@ -97,7 +150,7 @@
/* only execute the callouts if the property _changed_ */
if (added == FALSE && removed == FALSE)
- hal_callout_property (device, key);
+ /*hal_callout_property (device, key)*/;
}
static void
@@ -105,7 +158,7 @@
const char *capability, gpointer user_data)
{
manager_send_signal_new_capability (device, capability);
- hal_callout_capability (device, capability, TRUE);
+ /*hal_callout_capability (device, capability, TRUE)*/;
}
HalDeviceStore *
Index: property.c
===================================================================
RCS file: /cvs/hal/hal/hald/property.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- property.c 31 Jan 2005 20:06:39 -0000 1.9
+++ property.c 8 Feb 2005 16:44:20 -0000 1.10
@@ -222,6 +222,32 @@
return g_strdup (prop->bool_value ? "true" : "false");
case HAL_PROPERTY_TYPE_DOUBLE:
return g_strdup_printf ("%f", prop->double_value);
+ case HAL_PROPERTY_TYPE_STRLIST:
+ {
+ GSList *iter;
+ guint i;
+ char buf[256];
+
+ i = 0;
+ for (iter = hal_property_get_strlist (prop);
+ iter != NULL && i < sizeof(buf);
+ iter = g_slist_next (iter)) {
+ guint len;
+ const char *str;
+
+ str = (const char *) iter->data;
+ len = strlen (str);
+ strncpy (buf + i, str, sizeof(buf) - i);
+ i += len;
+
+ if (g_slist_next (iter) != NULL && i < sizeof(buf)) {
+ buf[i] = '\t';
+ i++;
+ }
+ }
+ return g_strdup (buf);
+ }
+
default:
return NULL;
}
Index: run-hald.sh
===================================================================
RCS file: /cvs/hal/hal/hald/run-hald.sh,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- run-hald.sh 18 Jan 2005 20:08:02 -0000 1.1
+++ run-hald.sh 8 Feb 2005 16:44:20 -0000 1.2
@@ -1,4 +1,4 @@
#!/bin/sh
-export PATH=linux2/probing:$PATH
+export PATH=linux2:linux2/probing:linux2/addons:.:$PATH
./hald --daemon=no --verbose=yes
--- NEW FILE: util.c ---
/***************************************************************************
* CVSID: $Id: util.c,v 1.1 2005/02/08 16:44:20 david Exp $
*
* util.c - Various utilities
*
* Copyright (C) 2004 David Zeuthen, <david at fubar.dk>
*
* Licensed under the Academic Free License version 2.0
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
[...1119 lines suppressed...]
;
}
void
hal_util_callout_device_remove (HalDevice *d, HalCalloutsDone callback, gpointer userdata)
{
GSList *programs;
gchar *extra_env[2] = {"HALD_ACTION=remove", NULL};
if ((programs = hal_device_property_get_strlist (d, "info.callouts.remove")) == NULL) {
callback (d, userdata);
goto out;
}
HAL_INFO (("Remove callouts for udi=%s", d->udi));
hal_callout_device (d, callback, userdata, programs, extra_env);
out:
;
}
--- NEW FILE: util.h ---
/***************************************************************************
* CVSID: $Id: util.h,v 1.1 2005/02/08 16:44:20 david Exp $
*
* util.h - Various utilities
*
* Copyright (C) 2004 David Zeuthen, <david at fubar.dk>
*
* Licensed under the Academic Free License version 2.0
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
**************************************************************************/
#ifndef UTIL_H
#define UTIL_H
#include "device.h"
#include "device_store.h"
gboolean hal_util_remove_trailing_slash (gchar *path);
gboolean hal_util_get_fs_mnt_path (const gchar *fs_type, gchar *mnt_path, gsize len);
const gchar *hal_util_get_last_element (const gchar *s);
gchar *hal_util_get_parent_path (const gchar *path);
gboolean hal_util_get_device_file (const gchar *sysfs_path, gchar *dev_file, gsize dev_file_length);
HalDevice *hal_util_find_closest_ancestor (const gchar *sysfs_path);
gchar *hal_util_get_normalized_path (const gchar *path1, const gchar *path2);
gboolean hal_util_get_int_from_file (const gchar *directory, const gchar *file, gint *result, gint base);
gboolean hal_util_set_int_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file, gint base);
gchar *hal_util_get_string_from_file (const gchar *directory, const gchar *file);
gboolean hal_util_set_string_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file);
gboolean hal_util_get_bcd2_from_file (const gchar *directory, const gchar *file, gint *result);
gboolean hal_util_set_bcd2_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file);
void hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...);
gboolean hal_util_set_driver (HalDevice *d, const char *property_name, const char *sysfs_path);
gboolean hal_util_path_ascend (gchar *path);
gchar *hal_util_grep_file (const gchar *directory, const gchar *file, const gchar *linestart);
gint hal_util_grep_int_elem_from_file (const gchar *directory, const gchar *file,
const gchar *linestart, guint elem, guint base);
gchar *hal_util_grep_string_elem_from_file (const gchar *directory, const gchar *file,
const gchar *linestart, guint elem);
gboolean hal_util_set_string_elem_from_file (HalDevice *d, const gchar *key,
const gchar *directory, const gchar *file,
const gchar *linestart, guint elem);
gboolean hal_util_set_int_elem_from_file (HalDevice *d, const gchar *key,
const gchar *directory, const gchar *file,
const gchar *linestart, guint elem, guint base);
gboolean hal_util_set_bool_elem_from_file (HalDevice *d, const gchar *key,
const gchar *directory, const gchar *file,
const gchar *linestart, guint elem, const gchar *expected);
struct HalHelperData_s;
typedef struct HalHelperData_s HalHelperData;
typedef void (*HalHelperTerminatedCB) (HalDevice *d, gboolean timed_out, gint return_code,
gpointer data1, gpointer data2, HalHelperData *helper_data);
struct HalHelperData_s
{
GPid pid;
guint timeout_watch_id;
guint child_watch_id;
HalHelperTerminatedCB cb;
gpointer data1;
gpointer data2;
HalDevice *d;
};
HalHelperData *hal_util_helper_invoke (const gchar *command_line, gchar **extra_env, HalDevice *d,
gpointer data1, gpointer data2, HalHelperTerminatedCB cb, guint timeout);
void hal_util_terminate_helper (HalHelperData *helper_data);
gchar **hal_util_dup_strv_from_g_slist (GSList *strlist);
typedef void (*HalCalloutsDone) (HalDevice *d, gpointer userdata);
void hal_util_callout_device_add (HalDevice *d, HalCalloutsDone callback, gpointer userdata);
void hal_util_callout_device_remove (HalDevice *d, HalCalloutsDone callback, gpointer userdata);
#define HAL_HELPER_TIMEOUT 10000
#define HAL_PATH_MAX 256
extern char hal_sysfs_path [HAL_PATH_MAX];
extern char hal_proc_path [HAL_PATH_MAX];
#endif /* UTIL_H */
More information about the hal-commit
mailing list