diff options
author | Alexander Mohr <alexander.m.mohr@daimler.com> | 2021-07-29 12:55:23 +0200 |
---|---|---|
committer | Saya Sugiura <39760799+ssugiura@users.noreply.github.com> | 2021-08-06 14:08:23 +0900 |
commit | 5379928defc81fc3826d84a634893c27394da59f (patch) | |
tree | d060aeeab7dc6b1005fe339dc67e6836ac951ebd | |
parent | 655f8caa782742ec1565dd8683422dce8fa3f29a (diff) | |
download | DLT-daemon-5379928defc81fc3826d84a634893c27394da59f.tar.gz |
file-transfer: Abort file transfer if get serial number failed
If a file is deleted while a file transfer is ongoing,
the file transfer tries to seek through the whole file.
This is due to the fact the the file handle is held open.
getFileSerialNumber is already validating the file
by using stat.
If this call returns a negative value, we know
that a stat to the file is not possible anymore,
therefore further reading can be aborted.
-rw-r--r-- | include/dlt/dlt_filetransfer.h | 2 | ||||
-rw-r--r-- | src/lib/dlt_filetransfer.c | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/include/dlt/dlt_filetransfer.h b/include/dlt/dlt_filetransfer.h index 728dfbb..5404d1a 100644 --- a/include/dlt/dlt_filetransfer.h +++ b/include/dlt/dlt_filetransfer.h @@ -52,6 +52,8 @@ #define DLT_FILETRANSFER_ERROR_INFO_ABOUT -700 /* ! Error code for dlt_user_log_file_packagesCount */ #define DLT_FILETRANSFER_ERROR_PACKAGE_COUNT -800 +/* ! Error code for failed get serial number */ +#define DLT_FILETRANSFER_FILE_SERIAL_NUMBER -900 /* !Transfer the complete file as several dlt logs. */ diff --git a/src/lib/dlt_filetransfer.c b/src/lib/dlt_filetransfer.c index 7508790..081893b 100644 --- a/src/lib/dlt_filetransfer.c +++ b/src/lib/dlt_filetransfer.c @@ -462,6 +462,7 @@ int dlt_user_log_file_header_alias(DltContext *fileContext, const char *filename DLT_STRING( "dlt_user_log_file_header_alias, Error getting serial number of file:"), DLT_STRING(filename)); + return DLT_FILETRANSFER_FILE_SERIAL_NUMBER; } uint32_t fsize = getFilesize(filename, &ok); @@ -633,6 +634,8 @@ int dlt_user_log_file_data(DltContext *fileContext, DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("failed to get FileSerialNumber for: "), DLT_STRING(filename)); + fclose (file); + return DLT_FILETRANSFER_FILE_SERIAL_NUMBER; } DLT_LOG(*fileContext, DLT_LOG_INFO, @@ -661,6 +664,8 @@ int dlt_user_log_file_data(DltContext *fileContext, DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("failed to get FileSerialNumber for: "), DLT_STRING(filename)); + fclose(file); + return DLT_FILETRANSFER_FILE_SERIAL_NUMBER; } DLT_LOG(*fileContext, DLT_LOG_INFO, @@ -705,6 +710,7 @@ int dlt_user_log_file_end(DltContext *fileContext, const char *filename, int del DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("failed to get FileSerialNumber for: "), DLT_STRING(filename)); + return DLT_FILETRANSFER_FILE_SERIAL_NUMBER; } DLT_LOG(*fileContext, DLT_LOG_INFO, |