Diff below enables a ptrace(2) regress coming from NetBSD.

With usr.bin/make built since -D2020-01-14, that includes -current, it
complains during the last test:

        make: Child (52049) not in table?
        FAILED

That results in a failing test, however the syscall correctly reports
EBUSY.

Should I commit this first to help you look at the issue?

Index: Makefile
===================================================================
RCS file: /cvs/src/regress/lib/libc/sys/Makefile,v
retrieving revision 1.2
diff -u -p -r1.2 Makefile
--- Makefile    13 Jan 2020 17:06:56 -0000      1.2
+++ Makefile    14 Jan 2020 16:01:50 -0000
@@ -30,8 +30,8 @@ PROGS +=      t_access t_bind t_chroot t_cloc
 PROGS +=       t_getgroups t_getitimer t_getlogin t_getpid t_getrusage
 PROGS +=       t_getsid t_getsockname t_gettimeofday t_kill t_link t_listen
 PROGS +=       t_mkdir t_mknod t_msgctl t_msgget t_msgsnd t_msync t_pipe
-PROGS +=       t_poll t_revoke t_select t_sendrecv t_setuid t_socketpair
-PROGS +=       t_sigaction t_truncate t_umask t_write
+PROGS +=       t_poll t_ptrace t_revoke t_select t_sendrecv t_setuid
+PROGS +=       t_socketpair t_sigaction t_truncate t_umask t_write
 
 # failing tests
 .if 0
@@ -40,7 +40,6 @@ PROGS +=      t_mlock
 PROGS +=       t_mmap
 PROGS +=       t_msgrcv
 PROGS +=       t_pipe2
-PROGS +=       t_ptrace
 PROGS +=       t_stat
 PROGS +=       t_syscall
 PROGS +=       t_unlink
@@ -57,8 +56,9 @@ setup-t_truncate:
        ${SUDO} touch truncate_test.root_owned
        ${SUDO} chown root:wheel truncate_test.root_owned
 
-run-t_chroot: cleanup-t_chroot
-cleanup-t_chroot:
+run-t_chroot: cleanup-dir
+run-t_ptrace: cleanup-dir
+cleanup-dir:
        ${SUDO} rm -rf dir
 
 CLEANFILES =   access dummy mmap truncate_test.root_owned
@@ -100,3 +100,5 @@ run-${PROG}-$n:
 .endif
 
 .include <bsd.regress.mk>
+
+clean: cleanup-dir
Index: README
===================================================================
RCS file: /cvs/src/regress/lib/libc/sys/README,v
retrieving revision 1.2
diff -u -p -r1.2 README
--- README      22 Nov 2019 15:59:53 -0000      1.2
+++ README      28 Nov 2019 17:13:08 -0000
@@ -18,6 +18,7 @@ t_getrusage   - no expected fail, PR kern/
 t_mknod        - remove tests for unsupported file types
 t_msgget       - remove msgget_limit test
 t_poll                 - remove pollts_* tests
+t_ptrace       - change EPERM -> EINVAL for PT_ATTACH of a parent 
 t_revoke       - remove basic tests, revoke only on ttys supported
 t_select       - remove sigset_t struct as it is int on OpenBSD
 
@@ -26,7 +27,6 @@ t_mlock               - wrong errno, succeeds where n
 t_mmap         - ENOTBLK on test NetBSD is skipping, remove mmap_va0 test
 t_msgrcv       - msgrcv(id, &r, 3 - 1, 0x41, 004000) != -1
 t_pipe2        - closefrom(4) == -1, remove F_GETNOSIGPIPE and nosigpipe test
-t_ptrace       - ptrace(0, 0, ((void *)0), 0) != -1
 t_stat                 - invalid GID with doas
 t_syscall      - SIGSEGV
 t_unlink       - wrong errno according to POSIX
Index: macros.h
===================================================================
RCS file: /cvs/src/regress/lib/libc/sys/macros.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 macros.h
--- macros.h    19 Nov 2019 19:57:03 -0000      1.1.1.1
+++ macros.h    29 Jan 2020 12:45:56 -0000
@@ -9,6 +9,7 @@
 
 #include <stdbool.h>
 #include <string.h>
+#include <stdio.h>
 
 #define __RCSID(str)
 #define __COPYRIGHT(str)
@@ -26,17 +27,26 @@ int sysctlbyname(char *, void *, size_t 
 int
 sysctlbyname(char* s, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
 {
-       int ktc;
-       if (strcmp(s, "kern.timecounter.hardware") == 0)
-               ktc = KERN_TIMECOUNTER_HARDWARE;
-       else if (strcmp(s, "kern.timecounter.choice") == 0)
-               ktc = KERN_TIMECOUNTER_CHOICE;
+        int mib[3], miblen;
 
-        int mib[3];
        mib[0] = CTL_KERN;
-       mib[1] = KERN_TIMECOUNTER;
-       mib[2] = ktc;
-        return sysctl(mib, 3, oldp, oldlenp, newp, newlen);
+       if (strcmp(s, "kern.timecounter.hardware") == 0) {
+               mib[1] = KERN_TIMECOUNTER;
+               mib[2] = KERN_TIMECOUNTER_HARDWARE;
+               miblen = 3;
+       } else if (strcmp(s, "kern.timecounter.choice") == 0) {
+               mib[1] = KERN_TIMECOUNTER;
+               mib[2] = KERN_TIMECOUNTER_CHOICE;
+               miblen = 3;
+       } else if (strcmp(s, "kern.securelevel") == 0) {
+               mib[1] = KERN_SECURELVL;
+               miblen = 2;
+       } else {
+               fprintf(stderr, "%s(): mib '%s' not supported\n", __func__, s);
+               return -42;
+       }
+
+        return sysctl(mib, miblen, oldp, oldlenp, newp, newlen);
 }
 
 /* t_mlock.c */
Index: t_ptrace.c
===================================================================
RCS file: /cvs/src/regress/lib/libc/sys/t_ptrace.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 t_ptrace.c
--- t_ptrace.c  19 Nov 2019 19:57:04 -0000      1.1.1.1
+++ t_ptrace.c  29 Jan 2020 12:54:05 -0000
@@ -171,7 +171,7 @@ ATF_TC_BODY(attach_chroot, tc)
                rv = write(fds_toparent[1], &msg, sizeof(msg));
                FORKEE_ASSERTX(rv == sizeof(msg));
 
-               ATF_REQUIRE_ERRNO(EPERM,
+               ATF_REQUIRE_ERRNO(EINVAL,
                        ptrace(PT_ATTACH, getppid(), NULL, 0) == -1);
 
                rv = read(fds_fromparent[0], &msg, sizeof(msg));
@@ -207,11 +207,11 @@ ATF_TC_HEAD(traceme_twice, tc)
 ATF_TC_BODY(traceme_twice, tc)
 {
 
-       printf("Mark the parent process (PID %d) a debugger of PID %d",
+       printf("Mark the parent process (PID %d) a debugger of PID %d\n",
               getppid(), getpid());
        ATF_REQUIRE(ptrace(PT_TRACE_ME, 0, NULL, 0) == 0);
 
-       printf("Mark the parent process (PID %d) a debugger of PID %d again",
+       printf("Mark the parent process (PID %d) a debugger of PID %d again\n",
               getppid(), getpid());
        ATF_REQUIRE_ERRNO(EBUSY, ptrace(PT_TRACE_ME, 0, NULL, 0) == -1);
 }

Reply via email to