diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-10-06 10:17:06 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-06 19:38:14 -0700 |
commit | ebee0c4c24e3b2a327c6b7275093690d2bff66bb (patch) | |
tree | af8bdbdbe1be7f0966f1dce5af89bb301c6ddbce /core | |
parent | 432a324756040b1ef164edfe51b06133f66d1aa3 (diff) | |
download | subsurface-ebee0c4c24e3b2a327c6b7275093690d2bff66bb.tar.gz |
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 <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/libdivecomputer.c | 15 |
1 files 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; } |