diff options
author | 2017-03-20 09:08:12 +0000 | |
---|---|---|
committer | 2017-03-20 09:08:12 +0000 | |
commit | c0fd6e1982353d056c26a292186ef0df315adde3 (patch) | |
tree | 6dce1b1866aab81b660aaae554c8f16c53f0d2d5 /src | |
parent | d99b87ba4332fd0c1e51d2708e46c52bad713558 (diff) |
Fix: Avoid segfault if diagnostic bus isn't correctly set.
There is a segfault when binding configuration doesn't matches configuration
generated. Improve general CAN bus device initialization.
Change-Id: I17ea94ee54841d09ac63a7ffad303a88d99e0173
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r-- | src/can/can-bus.cpp | 3 | ||||
-rw-r--r-- | src/diagnostic/diagnostic-manager.cpp | 19 | ||||
-rw-r--r-- | src/low-can-binding.cpp | 12 |
3 files changed, 24 insertions, 10 deletions
diff --git a/src/can/can-bus.cpp b/src/can/can-bus.cpp index a81c142..cfb9d86 100644 --- a/src/can/can-bus.cpp +++ b/src/can/can-bus.cpp @@ -240,7 +240,10 @@ int can_bus_t::init_can_dev() i++; } else + { ERROR(binder_interface, "Can't open device %s", device.c_str()); + return 1; + } } NOTICE(binder_interface, "Initialized %d/%d can bus device(s)", i, t); diff --git a/src/diagnostic/diagnostic-manager.cpp b/src/diagnostic/diagnostic-manager.cpp index 69e2a7c..017601c 100644 --- a/src/diagnostic/diagnostic-manager.cpp +++ b/src/diagnostic/diagnostic-manager.cpp @@ -81,7 +81,10 @@ void diagnostic_manager_t::reset() bool diagnostic_manager_t::shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size) { std::shared_ptr<can_bus_dev_t> can_bus_dev = can_bus_t::get_can_device(configuration_t::instance().get_diagnostic_manager().bus_); - return can_bus_dev->shims_send(arbitration_id, data, size); + if(can_bus_dev != nullptr) + return can_bus_dev->shims_send(arbitration_id, data, size); + ERROR(binder_interface, "shims_send: Can not retrieve diagnostic bus: %s", configuration_t::instance().get_diagnostic_manager().bus_.c_str()); + return false; } /// @brief The type signature for an optional logging function, if the user @@ -446,12 +449,18 @@ int diagnostic_manager_t::send_request(sd_event_source *s, uint64_t usec, void * { adr->get_frequency_clock().tick(); start_diagnostic_request(&dm.shims_, adr->get_handle()); - if(adr->get_handle()->completed && !adr->get_handle()->success) + if(adr->get_handle()->completed) { - DEBUG(binder_interface, "send_request: Fatal error sending diagnostic request"); - sd_event_source_unref(s); - return -1; + if(!adr->get_handle()->success) + { + ERROR(binder_interface, "send_request: Fatal error sending diagnostic request"); + sd_event_source_unref(s); + return -1; + } } + else + WARNING(binder_interface, "send_request: There was a problem sending your request using bus %s.", adr->get_can_bus_dev()->get_device_name().c_str()); + adr->get_timeout_clock().tick(); adr->set_in_flight(true); diff --git a/src/low-can-binding.cpp b/src/low-can-binding.cpp index 3e87072..45213d9 100644 --- a/src/low-can-binding.cpp +++ b/src/low-can-binding.cpp @@ -255,13 +255,15 @@ extern "C" /// Initialize CAN socket if(can_bus_manager.init_can_dev() == 0) + { can_bus_manager.start_threads(); - /// Initialize Diagnostic manager that will handle obd2 requests. - /// We pass by default the first CAN bus device to its Initialization. - /// TODO: be able to choose the CAN bus device that will be use as Diagnostic bus. - if(configuration_t::instance().get_diagnostic_manager().initialize()) - return 0; + /// Initialize Diagnostic manager that will handle obd2 requests. + /// We pass by default the first CAN bus device to its Initialization. + /// TODO: be able to choose the CAN bus device that will be use as Diagnostic bus. + if(configuration_t::instance().get_diagnostic_manager().initialize()) + return 0; + } ERROR(binder_interface, "There was something wrong with CAN device Initialization. Check your config file maybe"); return 1; |