diff mbox series

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

Message ID 20210118160139.1971039-3-gprocida@google.com (mailing list archive)
State Superseded
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. 18, 2021, 4:01 p.m. UTC
* Report the correct filename when objcopy fails.
* Unlink the temporary file on error.

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

Comments

Andrii Nakryiko Jan. 21, 2021, 7:09 a.m. UTC | #1
On Mon, Jan 18, 2021 at 8:01 AM Giuliano Procida <gprocida@google.com> wrote:
>
> * Report the correct filename when objcopy fails.
> * Unlink the temporary file on error.
>
> Signed-off-by: Giuliano Procida <gprocida@google.com>
> ---

Acked-by: Andrii Nakryiko <andrii@kernel.org>

>  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.284.gd98b1dd5eaa7-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);
 	}