]> granicus.if.org Git - strace/commitdiff
bpf: move common code to a separate function
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 28 Jan 2017 22:11:20 +0000 (22:11 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 29 Jan 2017 23:54:54 +0000 (23:54 +0000)
* bpf.c (bpf_prog_attach_detach): New function.
(bpf_prog_attach, bpf_prog_detach): Use it.

bpf.c

diff --git a/bpf.c b/bpf.c
index d36745ed89601045f2dcdad65cfe864a64cfd1a1..99410183bd48bc0bd23b93dc1ff28e832ccd549e 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -207,8 +207,8 @@ bpf_obj_manage(struct tcb *const tcp, const kernel_ulong_t addr,
 }
 
 static int
-bpf_prog_attach(struct tcb *const tcp, const kernel_ulong_t addr,
-               unsigned int size)
+bpf_prog_attach_detach(struct tcb *const tcp, const kernel_ulong_t addr,
+                      unsigned int size, bool print_attach_bpf_fd)
 {
        struct {
                uint32_t target_fd, attach_bpf_fd, attach_type;
@@ -225,8 +225,10 @@ bpf_prog_attach(struct tcb *const tcp, const kernel_ulong_t addr,
 
        tprintf("{target_fd=");
        printfd(tcp, attr.target_fd);
-       tprintf(", attach_bpf_fd=");
-       printfd(tcp, attr.attach_bpf_fd);
+       if (print_attach_bpf_fd) {
+               tprintf(", attach_bpf_fd=");
+               printfd(tcp, attr.attach_bpf_fd);
+       }
        tprintf(", attach_type=");
        printxval(bpf_attach_type, attr.attach_type, "BPF_???");
        tprintf("}");
@@ -235,29 +237,17 @@ bpf_prog_attach(struct tcb *const tcp, const kernel_ulong_t addr,
 }
 
 static int
-bpf_prog_detach(struct tcb *const tcp, const kernel_ulong_t addr,
+bpf_prog_attach(struct tcb *const tcp, const kernel_ulong_t addr,
                unsigned int size)
 {
-       struct {
-               uint32_t target_fd, attach_bpf_fd, attach_type;
-       } attr = {};
-
-       if (!size) {
-               printaddr(addr);
-               return RVAL_DECODED;
-       }
-       if (size > sizeof(attr))
-               size = sizeof(attr);
-       if (umoven_or_printaddr(tcp, addr, size, &attr))
-               return RVAL_DECODED;
-
-       tprintf("{target_fd=");
-       printfd(tcp, attr.target_fd);
-       tprintf(", attach_type=");
-       printxval(bpf_attach_type, attr.attach_type, "BPF_???");
-       tprintf("}");
+       return bpf_prog_attach_detach(tcp, addr, size, true);
+}
 
-       return RVAL_DECODED;
+static int
+bpf_prog_detach(struct tcb *const tcp, const kernel_ulong_t addr,
+               unsigned int size)
+{
+       return bpf_prog_attach_detach(tcp, addr, size, false);
 }
 
 SYS_FUNC(bpf)