summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Cardona <remi@gentoo.org>2009-07-27 12:07:51 +0200
committerRémi Cardona <remi@gentoo.org>2009-07-28 11:58:45 +0200
commitb1c3dc6ae226db178420e3b5f297b94afc87c94c (patch)
tree430625f5efc9c708513e0d323f84f74c5efe15c4
parent8898203b0d0e9fa03453b2bcd9b88843cccc3230 (diff)
config: add HAL error checks
This patch simplifies error handling in the HAL code and fixes a segfault if libhal_find_device_by_capability() failed. Fixes http://bugs.gentoo.org/278760 Based on a patch by Martin von Gagern <Martin.vGagern@gmx.net> Signed-off-by: Rémi Cardona <remi@gentoo.org> Acked-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--config/hal.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/config/hal.c b/config/hal.c
index 731d9b8fc..59bff6613 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -474,13 +474,13 @@ connect_and_register(DBusConnection *connection, struct config_hal_info *info)
474 char **devices; 474 char **devices;
475 int num_devices, i; 475 int num_devices, i;
476 476
477 if (info->hal_ctx)
478 return TRUE; /* already registered, pretend we did something */
479
477 info->system_bus = connection; 480 info->system_bus = connection;
478 481
479 dbus_error_init(&error); 482 dbus_error_init(&error);
480 483
481 if (info->hal_ctx)
482 return TRUE; /* already registered, pretend we did something */
483
484 info->hal_ctx = libhal_ctx_new(); 484 info->hal_ctx = libhal_ctx_new();
485 if (!info->hal_ctx) { 485 if (!info->hal_ctx) {
486 LogMessage(X_ERROR, "config/hal: couldn't create HAL context\n"); 486 LogMessage(X_ERROR, "config/hal: couldn't create HAL context\n");
@@ -501,7 +501,7 @@ connect_and_register(DBusConnection *connection, struct config_hal_info *info)
501 LogMessage(X_ERROR, "config/hal: couldn't watch all properties: %s (%s)\n", 501 LogMessage(X_ERROR, "config/hal: couldn't watch all properties: %s (%s)\n",
502 error.name ? error.name : "unknown error", 502 error.name ? error.name : "unknown error",
503 error.message ? error.message : "null"); 503 error.message ? error.message : "null");
504 goto out_ctx2; 504 goto out_ctx;
505 } 505 }
506 libhal_ctx_set_device_added(info->hal_ctx, device_added); 506 libhal_ctx_set_device_added(info->hal_ctx, device_added);
507 libhal_ctx_set_device_removed(info->hal_ctx, device_removed); 507 libhal_ctx_set_device_removed(info->hal_ctx, device_removed);
@@ -509,6 +509,12 @@ connect_and_register(DBusConnection *connection, struct config_hal_info *info)
509 devices = libhal_find_device_by_capability(info->hal_ctx, "input", 509 devices = libhal_find_device_by_capability(info->hal_ctx, "input",
510 &num_devices, &error); 510 &num_devices, &error);
511 /* FIXME: Get default devices if error is set. */ 511 /* FIXME: Get default devices if error is set. */
512 if (dbus_error_is_set(&error)) {
513 LogMessage(X_ERROR, "config/hal: couldn't find input device: %s (%s)\n",
514 error.name ? error.name : "unknown error",
515 error.message ? error.message : "null");
516 goto out_ctx;
517 }
512 for (i = 0; i < num_devices; i++) 518 for (i = 0; i < num_devices; i++)
513 device_added(info->hal_ctx, devices[i]); 519 device_added(info->hal_ctx, devices[i]);
514 libhal_free_string_array(devices); 520 libhal_free_string_array(devices);
@@ -517,13 +523,19 @@ connect_and_register(DBusConnection *connection, struct config_hal_info *info)
517 523
518 return TRUE; 524 return TRUE;
519 525
520out_ctx2:
521 if (!libhal_ctx_shutdown(info->hal_ctx, &error))
522 LogMessage(X_WARNING, "config/hal: couldn't shut down context: %s (%s)\n",
523 error.name ? error.name : "unknown error",
524 error.message ? error.message : "null");
525out_ctx: 526out_ctx:
526 libhal_ctx_free(info->hal_ctx); 527 dbus_error_free(&error);
528
529 if (info->hal_ctx) {
530 if (!libhal_ctx_shutdown(info->hal_ctx, &error)) {
531 LogMessage(X_WARNING, "config/hal: couldn't shut down context: %s (%s)\n",
532 error.name ? error.name : "unknown error",
533 error.message ? error.message : "null");
534 dbus_error_free(&error);
535 }
536 libhal_ctx_free(info->hal_ctx);
537 }
538
527out_err: 539out_err:
528 dbus_error_free(&error); 540 dbus_error_free(&error);
529 541