From ebee0c4c24e3b2a327c6b7275093690d2bff66bb Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 6 Oct 2018 10:17:06 -0700 Subject: Fix error handling for libdivecomputer import The error handling was incorrect for the case where we successfully opened the libdivecomputer iostream in divecomputer_device_open(), but the dc_device_open() call failed. When the dc_device_open() failed, we would (correctly) not do the dc_device_close() but we would _also_ not do the dc_iostream_close() to close the underlying file descriptor, which is wrong. Normally this isn't all that noticeable, partly because the common case is that dc_device_open() succeeds if you actually do have a dive computer connected, but also because most of the time it just leaked a file descriptor or something like that. However, particularly for the POSIX serial device case, libdivecomputer does a ioctl(device->fd, TIOCEXCL, NULL) call to make serial opens exclusive. This is what we want - but if we then fail at closing the serial file descriptor, we won't be able to retry the import at all because now the next open will fail with EBUSY. So the error handling was incorrect, and while it doesn't usually matter all that much, it can be quite noticeable particularly when you have transient errors. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- core/libdivecomputer.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index e6c74f115..5b386c032 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -1413,13 +1413,14 @@ const char *do_libdivecomputer_import(device_data_t *data) #else err = translate("gettextFromC", "Error opening the device %s %s (%s).\nIn most cases, in order to debug this issue, a libdivecomputer logfile will be useful.\nYou can create this logfile by selecting the corresponding checkbox in the download dialog."); #endif - } - - if (rc == DC_STATUS_SUCCESS) { - err = do_device_import(data); - /* TODO: Show the logfile to the user on error. */ - dc_device_close(data->device); - data->device = NULL; + if (rc == DC_STATUS_SUCCESS) { + err = do_device_import(data); + /* TODO: Show the logfile to the user on error. */ + dc_device_close(data->device); + data->device = NULL; + if (!downloadTable.nr) + dev_info(data, translate("gettextFromC", "No new dives downloaded from dive computer")); + } dc_iostream_close(data->iostream); data->iostream = NULL; } -- cgit v1.2.3-70-g09d2