diff options
-rw-r--r-- | ChangeLog | 23 | ||||
-rw-r--r-- | hald-runner/runner.c | 22 | ||||
-rw-r--r-- | hald/device.c | 33 | ||||
-rw-r--r-- | hald/device.h | 2 | ||||
-rw-r--r-- | hald/device_info.c | 84 | ||||
-rw-r--r-- | hald/hald_dbus.c | 27 | ||||
-rw-r--r-- | hald/hald_runner.c | 11 | ||||
-rw-r--r-- | hald/property.c | 16 | ||||
-rw-r--r-- | hald/property.h | 1 |
9 files changed, 183 insertions, 36 deletions
@@ -1,3 +1,26 @@ +2006-01-21 David Zeuthen <davidz@redhat.com> + + * hald-runner/runner.c: Search $PATH before searching allowed dirs; + this is needed to make e.g. run-hald.sh work - note that passing + "/bin/sh /path/to/evil/program" will _not_ work as we don't do + shell-ish stuff. Also, don't force working dir to be "/" for + same reasons. + + * hald/property.h: Export hal_property_strlist_clear + + * hald/property.c (hal_property_strlist_clear): New function + + * hald/hald_runner.c (hald_runner_start_runner): Pass $PATH to runner + + * hald/hald_dbus.c (hald_exec_method_cb): Fix up indenting + + * hald/device_info.c (handle_clear): New function + (start): Check for new fdi tag "clear" + + * hald/device.h: Export hal_device_property_strlist_clear + + * hald/device.c (hal_device_property_strlist_clear): New function + 2006-01-20 David Zeuthen <davidz@redhat.com> * doc/spec/hal-spec.xml.in: Add docs for volume.disc.capacity diff --git a/hald-runner/runner.c b/hald-runner/runner.c index 46c5d0bd..d8e646af 100644 --- a/hald-runner/runner.c +++ b/hald-runner/runner.c @@ -197,14 +197,21 @@ gboolean find_program(char **argv) { if (argv[0] == NULL) return FALSE; + program = g_path_get_basename(argv[0]); - for (i = 0; dirs[i] != NULL; i++) { - path = g_build_filename(dirs[i], program, NULL); - if (stat(path, &buf) == 0) { - break; + + /* first search $PATH to make e.g. run-hald.sh work */ + path = g_find_program_in_path (program); + /* otherwise check allowed paths */ + if (path == NULL) { + for (i = 0; dirs[i] != NULL; i++) { + path = g_build_filename(dirs[i], program, NULL); + if (stat(path, &buf) == 0) { + break; + } + g_free(path); + path = NULL; } - g_free(path); - path = NULL; } g_free(program); if (path == NULL) @@ -214,6 +221,7 @@ gboolean find_program(char **argv) { g_free(argv[0]); argv[0] = path; } + fprintf (stderr, "foobar '%s'!\n", argv[0]); return TRUE; } @@ -240,7 +248,7 @@ run_request_run(run_request *r, DBusConnection *con, DBusMessage *msg) { } if (!find_program(r->argv) || - !g_spawn_async_with_pipes("/", r->argv, r->environment, + !g_spawn_async_with_pipes(NULL, r->argv, r->environment, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, stdin_p, NULL, stderr_p, &error)) { diff --git a/hald/device.c b/hald/device.c index e1e56c6d..eca5a7a0 100644 --- a/hald/device.c +++ b/hald/device.c @@ -1200,6 +1200,39 @@ hal_device_property_strlist_remove_elem (HalDevice *device, } gboolean +hal_device_property_strlist_clear (HalDevice *device, + const char *key) +{ + HalProperty *prop; + + /* check if property already exists */ + prop = hal_device_property_find (device, key); + + if (prop == NULL) { + prop = hal_property_new_strlist (key); + + device->properties = g_slist_prepend (device->properties, prop); + + g_signal_emit (device, signals[PROPERTY_CHANGED], 0, + key, FALSE, TRUE); + + return TRUE; + } + + if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_STRLIST) + return FALSE; + + if (hal_property_strlist_clear (prop)) { + g_signal_emit (device, signals[PROPERTY_CHANGED], 0, + key, FALSE, FALSE); + return TRUE; + } + + return FALSE; +} + + +gboolean hal_device_property_strlist_add (HalDevice *device, const char *key, const char *value) diff --git a/hald/device.h b/hald/device.h index 1997ce34..590ee037 100644 --- a/hald/device.h +++ b/hald/device.h @@ -165,6 +165,8 @@ gboolean hal_device_property_strlist_prepend (HalDevice *device, gboolean hal_device_property_strlist_remove_elem (HalDevice *device, const char *key, guint index); +gboolean hal_device_property_strlist_clear (HalDevice *device, + const char *key); gboolean hal_device_property_strlist_add (HalDevice *device, const char *key, const char *value); diff --git a/hald/device_info.c b/hald/device_info.c index d793c352..ea13d162 100644 --- a/hald/device_info.c +++ b/hald/device_info.c @@ -79,24 +79,28 @@ enum { /** Processing an append element */ CURELEM_APPEND = 4, - /** Processing an prepend element */ + /** Processing a prepend element */ CURELEM_PREPEND = 5, - /** Processing an prepend element */ - CURELEM_REMOVE = 6 + /** Processing a remove element */ + CURELEM_REMOVE = 6, + + /** Processing a clear element */ + CURELEM_CLEAR = 7 }; /** What and how to merge */ enum { - MERGE_TYPE_UNKNOWN, - MERGE_TYPE_STRING, - MERGE_TYPE_BOOLEAN, - MERGE_TYPE_INT32, - MERGE_TYPE_UINT64, - MERGE_TYPE_DOUBLE, - MERGE_TYPE_COPY_PROPERTY, - MERGE_TYPE_STRLIST, - MERGE_TYPE_REMOVE + MERGE_TYPE_UNKNOWN = 0, + MERGE_TYPE_STRING = 1, + MERGE_TYPE_BOOLEAN = 2, + MERGE_TYPE_INT32 = 3, + MERGE_TYPE_UINT64 = 4, + MERGE_TYPE_DOUBLE = 5, + MERGE_TYPE_COPY_PROPERTY = 6, + MERGE_TYPE_STRLIST = 7, + MERGE_TYPE_REMOVE = 8, + MERGE_TYPE_CLEAR = 9 }; /** Parsing Context @@ -744,7 +748,7 @@ handle_append_prepend (ParsingContext * pc, const char **attr) return; } -/** Called when the append or prepend element begins. +/** Called when the remove element begins. * * @param pc Parsing context * @param attr Attribute key/value pairs @@ -786,6 +790,39 @@ handle_remove (ParsingContext * pc, const char **attr) return; } +/** Called when the clear element begins. + * + * @param pc Parsing context + * @param attr Attribute key/value pairs + */ +static void +handle_clear (ParsingContext * pc, const char **attr) +{ + int num_attrib; + + pc->merge_type = MERGE_TYPE_UNKNOWN; + + for (num_attrib = 0; attr[num_attrib] != NULL; num_attrib++) { + ; + } + + if (num_attrib != 4) + return; + + if (strcmp (attr[0], "key") != 0) + return; + + + if (strcmp (attr[3], "strlist") != 0) + return; + + strncpy (pc->merge_key, attr[1], MAX_KEY_SIZE); + + pc->merge_type = MERGE_TYPE_CLEAR; + + return; +} + /** Abort parsing of document * * @param pc Parsing context @@ -914,6 +951,23 @@ start (ParsingContext * pc, const char *el, const char **attr) } else { /*HAL_INFO(("No merge!")); */ } + } else if (strcmp (el, "clear") == 0) { + if (pc->curelem != CURELEM_DEVICE + && pc->curelem != CURELEM_MATCH) { + HAL_ERROR (("%s:%d:%d: Element <remove> can only be " + "inside <device> and <match>", + pc->file, + XML_GetCurrentLineNumber (pc->parser), + XML_GetCurrentColumnNumber (pc->parser))); + parsing_abort (pc); + } + + pc->curelem = CURELEM_CLEAR; + if (pc->match_ok) { + handle_clear (pc, attr); + } else { + /*HAL_INFO(("No merge!")); */ + } } else if (strcmp (el, "device") == 0) { if (pc->curelem != CURELEM_DEVICE_INFO) { HAL_ERROR (("%s:%d:%d: Element <device> can only be " @@ -1147,6 +1201,10 @@ end (ParsingContext * pc, const char *el) hal_device_property_remove (pc->device, pc->merge_key); } } + } else if (pc->curelem == CURELEM_CLEAR && pc->match_ok) { + if (pc->merge_type == MERGE_TYPE_CLEAR) { + hal_device_property_strlist_clear (pc->device, pc->merge_key); + } } diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c index 6a0d3b22..992b3668 100644 --- a/hald/hald_dbus.c +++ b/hald/hald_dbus.c @@ -2486,27 +2486,28 @@ hald_exec_method_cb (HalDevice *d, guint32 exit_type, DBusMessage *reply = NULL; DBusMessage *message; DBusMessageIter iter; - message = (DBusMessage *) data1; - gchar *exp_name = NULL; - gchar *exp_detail = NULL; + gchar *exp_name = NULL; + gchar *exp_detail = NULL; + message = (DBusMessage *) data1; + if (exit_type == HALD_RUN_SUCCESS && error != NULL) { - exp_name = error[0]; - if (error[0] != NULL) { - exp_detail = error[1]; - } - HAL_INFO (("failed with '%s' '%s'", exp_name, exp_detail)); - } - - if (exit_type != HALD_RUN_SUCCESS) { + exp_name = error[0]; + if (error[0] != NULL) { + exp_detail = error[1]; + } + HAL_INFO (("failed with '%s' '%s'", exp_name, exp_detail)); + } + + if (exit_type != HALD_RUN_SUCCESS) { reply = dbus_message_new_error (message, "org.freedesktop.Hal.Device.UnknownError", "An unknown error occured"); if (dbus_connection != NULL) { if (!dbus_connection_send (dbus_connection, reply, NULL)) DIE (("No memory")); } dbus_message_unref (reply); - } else if (exp_name != NULL && exp_detail != NULL) { - reply = dbus_message_new_error (message, exp_name, exp_detail); + } else if (exp_name != NULL && exp_detail != NULL) { + reply = dbus_message_new_error (message, exp_name, exp_detail); if (reply == NULL) { /* error name may be invalid - assume caller fucked up and use a generic HAL error name */ reply = dbus_message_new_error (message, "org.freedesktop.Hal.Device.UnknownError", "An unknown error occured"); diff --git a/hald/hald_runner.c b/hald/hald_runner.c index 10c8ef75..8069c45d 100644 --- a/hald/hald_runner.c +++ b/hald/hald_runner.c @@ -70,13 +70,14 @@ runner_died(GPid pid, gint status, gpointer data) { } gboolean -hald_runner_start_runner(gchar *runner_location) { +hald_runner_start_runner(gchar *runner_location) +{ DBusServer *server = NULL; DBusError err; GError *error = NULL; GPid pid; char *argv[] = { NULL, NULL}; - char *env[] = { NULL, NULL}; + char *env[] = { NULL, NULL, NULL}; dbus_error_init(&err); server = dbus_server_listen(DBUS_SERVER_ADDRESS, &err); @@ -97,6 +98,7 @@ hald_runner_start_runner(gchar *runner_location) { argv[0] = runner_location; env[0] = g_strdup_printf("HALD_RUNNER_DBUS_ADDRESS=%s", dbus_server_get_address(server)); + env[1] = g_strdup_printf("PATH=%s", getenv("PATH")); if (!g_spawn_async(NULL, argv, env, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, &error)) { @@ -106,6 +108,7 @@ hald_runner_start_runner(gchar *runner_location) { } g_free(argv[0]); g_free(env[0]); + g_free(env[1]); g_child_watch_add(pid, runner_died, NULL); while (runner_connection == NULL) { @@ -294,8 +297,10 @@ call_notify(DBusPendingCall *pending, void *user_data) { while (dbus_message_iter_next(&iter) && dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) { const char *value; + const char *copy; dbus_message_iter_get_basic(&iter, &value); - g_array_append_vals(error, &value, 1); + copy = g_strdup (value); + g_array_append_vals(error, ©, 1); } hb->cb(hb->d, exitt, return_code, diff --git a/hald/property.c b/hald/property.c index ac0ef999..1c0e2e4d 100644 --- a/hald/property.c +++ b/hald/property.c @@ -471,3 +471,19 @@ hal_property_strlist_remove (HalProperty *prop, const char *value) return FALSE; } + +gboolean +hal_property_strlist_clear (HalProperty *prop) +{ + GSList *elem; + + g_return_val_if_fail (prop != NULL, FALSE); + g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_STRLIST, FALSE); + + for (elem = prop->strlist_value; elem != NULL; elem = g_slist_next (elem)) { + g_free (elem->data); + } + g_slist_free (prop->strlist_value); + + return FALSE; +} diff --git a/hald/property.h b/hald/property.h index 48d6845d..b5afa25d 100644 --- a/hald/property.h +++ b/hald/property.h @@ -91,6 +91,7 @@ gboolean hal_property_strlist_add (HalProperty *prop, const char *value); gboolean hal_property_strlist_remove (HalProperty *prop, const char *value); +gboolean hal_property_strlist_clear (HalProperty *prop); void hal_property_set_attribute (HalProperty *prop, |