diff mbox series

handlers: raw_handler.c: fix return value when an error occurred

Message ID 20240116111705.13088-1-m.salvini@koansoftware.com
State Accepted
Headers show
Series handlers: raw_handler.c: fix return value when an error occurred | expand

Commit Message

Mauro Salvini Jan. 16, 2024, 11:17 a.m. UTC
Before this commit, if an error occurs during the raw file handling (e.g.
no space on device) and there is a mounted device, the error code
got overwritten by the swupdate_umount() return value: if swupdate_umount()
returned success (0), the update process did not fail as expected.

Signed-off-by: Mauro Salvini <m.salvini@koansoftware.com>
---
 handlers/raw_handler.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Stefano Babic Jan. 26, 2024, 9:25 a.m. UTC | #1
Hi Mauro,

On 16.01.24 12:17, Mauro Salvini wrote:
> Before this commit, if an error occurs during the raw file handling (e.g.
> no space on device) and there is a mounted device, the error code
> got overwritten by the swupdate_umount() return value: if swupdate_umount()
> returned success (0), the update process did not fail as expected.
> 
> Signed-off-by: Mauro Salvini <m.salvini@koansoftware.com>
> ---
>   handlers/raw_handler.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/handlers/raw_handler.c b/handlers/raw_handler.c
> index 979c55f..4e9b3a4 100644
> --- a/handlers/raw_handler.c
> +++ b/handlers/raw_handler.c
> @@ -153,6 +153,7 @@ static int install_raw_file(struct img_type *img,
>   	char tmp_path[255];
>   	int fdout = -1;
>   	int ret = -1;
> +	int cleanup_ret;
>   	int use_mount = (strlen(img->device) && strlen(img->filesystem)) ? 1 : 0;
>   	char* DATADST_DIR = alloca(strlen(get_tmpdir())+strlen(DATADST_DIR_SUFFIX)+1);
>   	sprintf(DATADST_DIR, "%s%s", get_tmpdir(), DATADST_DIR_SUFFIX);
> @@ -244,12 +245,12 @@ cleanup:
>   		close(fdout);
>   
>   	if (use_mount) {
> -		ret = swupdate_umount(DATADST_DIR);
> -		if (ret)
> +		cleanup_ret = swupdate_umount(DATADST_DIR);
> +		if (cleanup_ret)
>   			WARN("Can't unmount path %s: %s", DATADST_DIR, strerror(errno));
>   	}
>   
> -	return ret;
> +	return (ret ? ret : cleanup_ret);
>   }
>   
>   __attribute__((constructor))

Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/handlers/raw_handler.c b/handlers/raw_handler.c
index 979c55f..4e9b3a4 100644
--- a/handlers/raw_handler.c
+++ b/handlers/raw_handler.c
@@ -153,6 +153,7 @@  static int install_raw_file(struct img_type *img,
 	char tmp_path[255];
 	int fdout = -1;
 	int ret = -1;
+	int cleanup_ret;
 	int use_mount = (strlen(img->device) && strlen(img->filesystem)) ? 1 : 0;
 	char* DATADST_DIR = alloca(strlen(get_tmpdir())+strlen(DATADST_DIR_SUFFIX)+1);
 	sprintf(DATADST_DIR, "%s%s", get_tmpdir(), DATADST_DIR_SUFFIX);
@@ -244,12 +245,12 @@  cleanup:
 		close(fdout);
 
 	if (use_mount) {
-		ret = swupdate_umount(DATADST_DIR);
-		if (ret)
+		cleanup_ret = swupdate_umount(DATADST_DIR);
+		if (cleanup_ret)
 			WARN("Can't unmount path %s: %s", DATADST_DIR, strerror(errno));
 	}
 
-	return ret;
+	return (ret ? ret : cleanup_ret);
 }
 
 __attribute__((constructor))