diff mbox series

[dwarves,v2,2/3] btf_encoder: Improve error-handling around objcopy

Message ID 20210121113520.3603097-3-gprocida@google.com (mailing list archive)
State Not Applicable
Delegated to: BPF
Headers show
Series Small fixes and improvements | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Giuliano Procida Jan. 21, 2021, 11:35 a.m. UTC
* Report the correct filename when objcopy fails.
* Unlink the temporary file on error.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 libbtf.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Arnaldo Carvalho de Melo Jan. 21, 2021, 1:24 p.m. UTC | #1
Em Thu, Jan 21, 2021 at 11:35:19AM +0000, Giuliano Procida escreveu:
> * Report the correct filename when objcopy fails.
> * Unlink the temporary file on error.

Thanks, applied.

- Arnaldo

 
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Giuliano Procida <gprocida@google.com>
> ---
>  libbtf.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/libbtf.c b/libbtf.c
> index 3709087..7552d8e 100644
> --- a/libbtf.c
> +++ b/libbtf.c
> @@ -786,18 +786,19 @@ static int btf_elf__write(const char *filename, struct btf *btf)
>  		if (write(fd, raw_btf_data, raw_btf_size) != raw_btf_size) {
>  			fprintf(stderr, "%s: write of %d bytes to '%s' failed: %d!\n",
>  				__func__, raw_btf_size, tmp_fn, errno);
> -			goto out;
> +			goto unlink;
>  		}
>  
>  		snprintf(cmd, sizeof(cmd), "%s --add-section .BTF=%s %s",
>  			 llvm_objcopy, tmp_fn, filename);
>  		if (system(cmd)) {
>  			fprintf(stderr, "%s: failed to add .BTF section to '%s': %d!\n",
> -				__func__, tmp_fn, errno);
> -			goto out;
> +				__func__, filename, errno);
> +			goto unlink;
>  		}
>  
>  		err = 0;
> +	unlink:
>  		unlink(tmp_fn);
>  	}
>  
> -- 
> 2.30.0.296.g2bfb1c46d8-goog
>
diff mbox series

Patch

diff --git a/libbtf.c b/libbtf.c
index 3709087..7552d8e 100644
--- a/libbtf.c
+++ b/libbtf.c
@@ -786,18 +786,19 @@  static int btf_elf__write(const char *filename, struct btf *btf)
 		if (write(fd, raw_btf_data, raw_btf_size) != raw_btf_size) {
 			fprintf(stderr, "%s: write of %d bytes to '%s' failed: %d!\n",
 				__func__, raw_btf_size, tmp_fn, errno);
-			goto out;
+			goto unlink;
 		}
 
 		snprintf(cmd, sizeof(cmd), "%s --add-section .BTF=%s %s",
 			 llvm_objcopy, tmp_fn, filename);
 		if (system(cmd)) {
 			fprintf(stderr, "%s: failed to add .BTF section to '%s': %d!\n",
-				__func__, tmp_fn, errno);
-			goto out;
+				__func__, filename, errno);
+			goto unlink;
 		}
 
 		err = 0;
+	unlink:
 		unlink(tmp_fn);
 	}