From 50a26514a581ecfdccb22a31f2b24a4b42ff934c Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Thu, 12 May 2016 14:23:50 +0000
Subject: [PATCH] Export print_seccomp_fprog for further use in parser of
 ptrace syscall

* defs.h (print_seccomp_fprog): New prototype.
* seccomp.c (print_seccomp_fprog): Remove "static" keyword.
Move printing of struct seccomp_fprog fields ...
(print_seccomp_filter): ... here.
---
 defs.h    |  3 ++-
 seccomp.c | 11 +++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/defs.h b/defs.h
index a5aff96a..a3b1ddaa 100644
--- a/defs.h
+++ b/defs.h
@@ -652,7 +652,8 @@ extern void tprint_iov(struct tcb *, unsigned long, unsigned long, int decode_io
 extern void tprint_iov_upto(struct tcb *, unsigned long, unsigned long, int decode_iov, unsigned long);
 extern void tprint_open_modes(unsigned int);
 extern const char *sprint_open_modes(unsigned int);
-extern void print_seccomp_filter(struct tcb *tcp, unsigned long);
+extern void print_seccomp_filter(struct tcb *, unsigned long);
+extern void print_seccomp_fprog(struct tcb *, unsigned long, unsigned short);
 
 struct strace_statfs;
 extern void print_struct_statfs(struct tcb *tcp, long);
diff --git a/seccomp.c b/seccomp.c
index 5d972f97..4d8d7e4b 100644
--- a/seccomp.c
+++ b/seccomp.c
@@ -171,11 +171,9 @@ print_bpf_filter(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
 	return true;
 }
 
-static void
+void
 print_seccomp_fprog(struct tcb *tcp, unsigned long addr, unsigned short len)
 {
-	tprintf("{len=%u, filter=", len);
-
 	if (abbrev(tcp)) {
 		printaddr(addr);
 	} else {
@@ -185,8 +183,6 @@ print_seccomp_fprog(struct tcb *tcp, unsigned long addr, unsigned short len)
 		print_array(tcp, addr, len, &filter, sizeof(filter),
 			    umoven_or_printaddr, print_bpf_filter, &insns);
 	}
-
-	tprints("}");
 }
 
 #include "seccomp_fprog.h"
@@ -196,8 +192,11 @@ print_seccomp_filter(struct tcb *tcp, unsigned long addr)
 {
 	struct seccomp_fprog fprog;
 
-	if (fetch_seccomp_fprog(tcp, addr, &fprog))
+	if (fetch_seccomp_fprog(tcp, addr, &fprog)) {
+		tprintf("{len=%hu, filter=", fprog.len);
 		print_seccomp_fprog(tcp, fprog.filter, fprog.len);
+		tprints("}");
+	}
 }
 
 static void
-- 
2.40.0