mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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>
This commit is contained in:
parent
432a324756
commit
ebee0c4c24
1 changed files with 8 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue