Module Name:    src
Committed By:   kamil
Date:           Sun May 13 23:01:25 UTC 2018

Modified Files:
        src/tests/lib/libc/sys: t_ptrace_wait.h t_ptrace_x86_wait.h

Log Message:
Refactor code in ATF ptrace(2) tests

Move the can_we_set_dbregs() auxiliary function from t_ptrace_x86_wait.h
to a common file t_ptrace_wait.h. This allows using this function for
checking whether the DBREGS set operations in ptrace(2) are accessible for
a user.

Sponsored by <The NetBSD Foundation>


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_ptrace_wait.h
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_ptrace_x86_wait.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.3 src/tests/lib/libc/sys/t_ptrace_wait.h:1.4
--- src/tests/lib/libc/sys/t_ptrace_wait.h:1.3	Sat Apr 28 17:56:55 2018
+++ src/tests/lib/libc/sys/t_ptrace_wait.h	Sun May 13 23:01:25 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.h,v 1.3 2018/04/28 17:56:55 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.h,v 1.4 2018/05/13 23:01:25 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -409,6 +409,35 @@ check_happy(unsigned n)
 	}
 }
 
+#if defined(HAVE_DBREGS)
+static bool
+can_we_set_dbregs(void)
+{
+	static long euid = -1;
+	static int user_set_dbregs  = -1;
+	size_t user_set_dbregs_len = sizeof(user_set_dbregs);
+
+	if (euid == -1)
+		euid = geteuid();
+
+	if (euid == 0)
+		return true;
+
+	if (user_set_dbregs == -1) {
+		if (sysctlbyname("security.models.extensions.user_set_dbregs",
+			&user_set_dbregs, &user_set_dbregs_len, NULL, 0)
+			== -1) {
+			return false;
+		}
+	}
+
+	if (user_set_dbregs > 0)
+		return true;
+	else
+		return false;
+}
+#endif
+
 #if defined(TWAIT_HAVE_PID)
 #define ATF_TP_ADD_TC_HAVE_PID(a,b)	ATF_TP_ADD_TC(a,b)
 #else

Index: src/tests/lib/libc/sys/t_ptrace_x86_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.5 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.6
--- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.5	Sun Apr  8 17:20:18 2018
+++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h	Sun May 13 23:01:25 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_x86_wait.h,v 1.5 2018/04/08 17:20:18 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_x86_wait.h,v 1.6 2018/05/13 23:01:25 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -57,33 +57,6 @@ union u {
 	} bits;
 };
 
-static bool
-can_we_set_dbregs(void)
-{
-	static long euid = -1;
-	static int user_set_dbregs  = -1;
-	size_t user_set_dbregs_len = sizeof(user_set_dbregs);
-
-	if (euid == -1)
-		euid = geteuid();
-
-	if (euid == 0)
-		return true;
-
-	if (user_set_dbregs == -1) {
-		if (sysctlbyname("security.models.extensions.user_set_dbregs",
-			&user_set_dbregs, &user_set_dbregs_len, NULL, 0)
-			== -1) {
-			return false;
-		}
-	}
-
-	if (user_set_dbregs > 0)
-		return true;
-	else
-		return false;
-}
-
 ATF_TC(dbregs_print);
 ATF_TC_HEAD(dbregs_print, tc)
 {

Reply via email to