From 489a27f70d41edcc29e60d4dc3e7cbd9452c72a0 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Wed, 20 May 2015 22:13:32 +0300 Subject: [PATCH 1/4] BasicFileServer::handleRead() error handling fix --- libuavcan/include/uavcan/protocol/file_server.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libuavcan/include/uavcan/protocol/file_server.hpp b/libuavcan/include/uavcan/protocol/file_server.hpp index d525b70156..ef6008766c 100644 --- a/libuavcan/include/uavcan/protocol/file_server.hpp +++ b/libuavcan/include/uavcan/protocol/file_server.hpp @@ -136,6 +136,11 @@ class BasicFileServer resp.error.value = backend_.read(req.path.path, req.offset, resp.data.begin(), inout_size); + if (resp.error.value != protocol::file::Error::OK) + { + inout_size = 0; + } + if (inout_size > resp.data.capacity()) { UAVCAN_ASSERT(0); From 45942eef1fb7685491a9051c47f57bdadbb9297e Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Wed, 20 May 2015 22:15:19 +0300 Subject: [PATCH 2/4] Note on error codes --- libuavcan/include/uavcan/protocol/file_server.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libuavcan/include/uavcan/protocol/file_server.hpp b/libuavcan/include/uavcan/protocol/file_server.hpp index ef6008766c..ba458cefad 100644 --- a/libuavcan/include/uavcan/protocol/file_server.hpp +++ b/libuavcan/include/uavcan/protocol/file_server.hpp @@ -20,6 +20,8 @@ namespace uavcan { /** * The file server backend should implement this interface. + * Note that error codes returned by these methods are defined in uavcan.protocol.file.Error; these are + * not the same as libuavcan-internal error codes defined in uavcan.error.hpp. */ class UAVCAN_EXPORT IFileServerBackend { From 823b14c1211b3cef27a1ec3ee3eb256437db2f9c Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Thu, 21 May 2015 01:28:41 +0300 Subject: [PATCH 3/4] POSIX dynamic ID storage backend: calling fsync() on set(), plus a minor style fix --- .../dynamic_node_id_server/file_storage_backend.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_storage_backend.hpp b/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_storage_backend.hpp index fdf173cc13..a2834c6cfb 100644 --- a/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_storage_backend.hpp +++ b/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_storage_backend.hpp @@ -53,9 +53,9 @@ class FileStorageBackend : public uavcan::dynamic_node_id_server::IStorageBacken if (fd >= 0) { char buffer[MaxStringLength + 1]; - memset(buffer, 0, sizeof(buffer)); + (void)memset(buffer, 0, sizeof(buffer)); int len = read(fd, buffer, MaxStringLength); - close(fd); + (void)close(fd); if (len > 0) { for (int i = 0; i < len; i++) @@ -80,8 +80,9 @@ class FileStorageBackend : public uavcan::dynamic_node_id_server::IStorageBacken int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, FilePermissions); if (fd >= 0) { - write(fd, value.c_str(), value.size()); - close(fd); + (void)write(fd, value.c_str(), value.size()); + (void)fsync(fd); + (void)close(fd); } } From e5ce6f74c693b1722c97490c7817693d2a1c9e30 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Thu, 21 May 2015 17:16:20 +0300 Subject: [PATCH 4/4] POSIX file event tracer visibility fix --- .../uavcan_posix/dynamic_node_id_server/file_event_tracer.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_event_tracer.hpp b/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_event_tracer.hpp index 3398a54418..863d7465a1 100644 --- a/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_event_tracer.hpp +++ b/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_event_tracer.hpp @@ -38,6 +38,7 @@ class FileEventTracer : public uavcan::dynamic_node_id_server::IEventTracer PathString path_; +protected: virtual void onEvent(uavcan::dynamic_node_id_server::TraceCode code, uavcan::int64_t argument) { using namespace std;