]> git.baikalelectronics.ru Git - kernel.git/commitdiff
libbpf: preserve errno before calling into user callback
authorAndrii Nakryiko <andriin@fb.com>
Wed, 29 May 2019 17:36:04 +0000 (10:36 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 29 May 2019 23:23:34 +0000 (01:23 +0200)
pr_warning ultimately may call into user-provided callback function,
which can clobber errno value, so we need to save it before that.

Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/lib/bpf/libbpf.c

index c985a7916e35eebf9f812c5beb1ecd2ebdd7168c..40690b7e500eea657aef1214775bb598fa3890a4 100644 (file)
@@ -565,12 +565,12 @@ static int bpf_object__elf_init(struct bpf_object *obj)
        } else {
                obj->efile.fd = open(obj->path, O_RDONLY);
                if (obj->efile.fd < 0) {
-                       char errmsg[STRERR_BUFSIZE];
-                       char *cp = libbpf_strerror_r(errno, errmsg,
-                                                    sizeof(errmsg));
+                       char errmsg[STRERR_BUFSIZE], *cp;
 
+                       err = -errno;
+                       cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg));
                        pr_warning("failed to open %s: %s\n", obj->path, cp);
-                       return -errno;
+                       return err;
                }
 
                obj->efile.elf = elf_begin(obj->efile.fd,