8000 minix/minix/tests/test42.c at R3.3.0 · fyy3/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
1506 lines (1068 loc) · 30.6 KB

test42.c

File metadata and controls

1506 lines (1068 loc) · 30.6 KB
/* Tests for MINIX3 ptrace(2) - by D.C. van Moolenbroek */
#include <setjmp.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>
#include <sys/select.h>
#include <sys/ptrace.h>
#include <sys/syslimits.h>
#define ITERATIONS 3
int max_error = 4;
#include "common.h"
#define my_e(n) { \
if (child) exit(n); printf("Attach type %d, ", attach); e(n); }
#define _WIFSTOPPED(s) (WIFSTOPPED(s) && !WIFSIGNALED(s) && !WIFEXITED(s))
#define _WIFSIGNALED(s) (!WIFSTOPPED(s) && WIFSIGNALED(s) && !WIFEXITED(s))
#define _WIFEXITED(s) (!WIFSTOPPED(s) && !WIFSIGNALED(s) && WIFEXITED(s))
#define timed_test(func) (timed_test_func(#func, func));
int main(int argc, char **argv);
void test(int m, int a);
void timed_test_func(const char *s, void (* func)(void));
void timed_test_timeout(int signum);
pid_t traced_fork(void (*c) (void));
pid_t traced_pfork(void (*c) (void));
void WRITE(int value);
int READ(void);
void traced_wait(void);
void detach_running(pid_t pid);
void dummy_handler(int sig);
void exit_handler(int sig);
void count_handler(int sig);
void catch_handler(int sig);
void test_wait_child(void);
void test_wait(void);
void test_exec_child(void);
void test_exec(void);
void test_step_child(void);
void test_step(void);
void test_sig_child(void);
void test_sig(void);
void test_exit_child(void);
void test_exit(void);
void test_term_child(void);
void test_term(void);
void test_catch_child(void);
void test_catch(void);
void test_kill_child(void);
void test_kill(void);
void test_attach_child(void);
void test_attach(void);
void test_detach_child(void);
void test_detach(void);
void test_death_child(void);
void test_death(void);
void test_zdeath_child(void);
void test_zdeath(void);
void test_syscall_child(void);
void test_syscall(void);
void test_tracefork_child(void);
void test_tracefork(void);
void sigexec(int setflag, int opt, int *traps, int *stop);
void test_trapexec(void);
void test_altexec(void);
void test_noexec(void);
void test_defexec(void);
void test_reattach_child(void);
void test_reattach(void);
static char *executable;
static int child = 0, attach;
static pid_t ppid;
static int pfd[4];
static int sigs, caught;
int main(argc, argv)
int argc;
char **argv;
{
int i, m = 0xFFFFFF, n = 0xF;
char cp_cmd[NAME_MAX + 10];
if (strcmp(argv[0], "DO CHECK") == 0) {
exit(42);
}
start(42);
executable = argv[0];
snprintf(cp_cmd, sizeof(cp_cmd), "cp ../%s .", executable);
system(cp_cmd);
if (argc >= 2) m = atoi(argv[1]);
if (argc >= 3) n = atoi(argv[2]);
for (i = 0; i < ITERATIONS; i++) {
if (n & 001) test(m, 0);
if (n & 002) test(m, 1);
if (n & 004) test(m, 2);
if (n & 010) test(m, 3);
}
quit();
return(-1); /* impossible */
}
void test(m, a)
int m;
int a;
{
attach = a;
if (m & 00000001) timed_test(test_wait);
if (m & 00000002) timed_test(test_exec);
#if !defined(__arm__)
/* BJG: single-stepping isn't implemented on ARM */
if (m & 00000004) timed_test(test_step);
#endif
if (m & 00000010) timed_test(test_sig);
if (m & 00000020) timed_test(test_exit);
if (m & 00000040) timed_test(test_term);
if (m & 00000100) timed_test(test_catch);
if (m & 00000200) timed_test(test_kill);
if (m & 00000400) timed_test(test_attach);
if (m & 00001000) timed_test(test_detach);
if (m & 00002000) timed_test(test_death);
if (m & 00004000) timed_test(test_zdeath);
if (m & 00010000) timed_test(test_syscall);
if (m & 00020000) timed_test(test_tracefork);
if (m & 00040000) timed_test(test_trapexec);
if (m & 00100000) timed_test(test_altexec);
if (m & 00200000) timed_test(test_noexec);
if (m & 00400000) timed_test(test_defexec);
if (m & 01000000) test_reattach(); /* not timed, catches SIGALRM */
}
static jmp_buf timed_test_context;
void timed_test_timeout(int signum)
{
longjmp(timed_test_context, -1);
my_e(700);
quit();
exit(-1);
}
void timed_test_func(const char *s, void (* func)(void))
{
if (setjmp(timed_test_context) == 0)
{
/* the function gets 60 seconds to complete */
if (signal(SIGALRM, timed_test_timeout) == SIG_ERR) { my_e(701); return; }
alarm(60);
func();
alarm(0);
}
else
{
/* report timeout as error */
printf("timeout in %s\n", s);
my_e(702);
}
}
pid_t traced_fork(c)
void(*c) (void);
{
pid_t pid;
int r, status;
if (pipe(pfd) != 0) my_e(200);
if (pipe(&pfd[2]) != 0) my_e(201);
switch (attach) {
case 0: /* let child volunteer to be traced */
pid = fork();
if (pid < 0) my_e(202);
if (pid == 0) {
child = 1;
if (ptrace(T_OK, 0, 0, 0) != 0) my_e(203);
WRITE(0);
c();
my_e(204);
}
if (READ() != 0) my_e(205);
break;
case 1: /* attach to child process */
pid = fork();
if (pid < 0) my_e(206);
if (pid == 0) {
child = 1;
if (READ() != 0) my_e(207);
c();
my_e(208);
}
if (ptrace(T_ATTACH, pid, 0, 0) != 0) my_e(209);
if (waitpid(pid, &status, 0) != pid) my_e(210);
if (!_WIFSTOPPED(status)) my_e(211);
if (WSTOPSIG(status) != SIGSTOP) my_e(212);
if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(213);
WRITE(0);
break;
case 2: /* attach to non-child process */
ppid = fork();
if (ppid < 0) my_e(214);
if (ppid == 0) {
pid = fork();
if (pid < 0) exit(215);
if (pid == 0) {
child = 1;
if (READ() != 0) my_e(216);
c();
my_e(217);
}
child = 1;
WRITE(pid);
if (waitpid(pid, &status, 0) != pid) my_e(218);
if (_WIFSTOPPED(status)) my_e(219);
if (_WIFEXITED(status) && (r = WEXITSTATUS(status)) != 42) my_e(r);
exit(0);
}
pid = READ();
if (ptrace(T_ATTACH, pid, 0, 0) != 0) my_e(220);
if (waitpid(pid, &status, 0) != pid) my_e(221);
if (!_WIFSTOPPED(status)) my_e(222);
if (WSTOPSIG(status) != SIGSTOP) my_e(223);
if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(224);
WRITE(0);
break;
case 3: /* attach by forking from child */
ppid = fork();
if (ppid < 0) my_e(225);
if (ppid == 0) {
child = 1;
if (ptrace(T_OK, 0, 0, 0) != 0) my_e(226);
WRITE(0);
if (READ() != 0) my_e(227);
pid = fork();
if (pid < 0) my_e(228);
if (pid == 0) {
c();
my_e(229);
}
WRITE(pid);
if (waitpid(pid, &status, 0) != pid) my_e(230);
if (_WIFSTOPPED(status)) my_e(231);
if (_WIFEXITED(status) && (r = WEXITSTATUS(status)) != 42) my_e(r);
exit(0);
}
if (READ() != 0) my_e(232);
if (kill(ppid, SIGSTOP) != 0) my_e(233);
if (waitpid(ppid, &status, 0) != ppid) my_e(234);
if (!_WIFSTOPPED(status)) my_e(235);
if (WSTOPSIG(status) != SIGSTOP) my_e(236);
if (ptrace(T_SETOPT, ppid, 0, TO_TRACEFORK) != 0) my_e(237);
if (ptrace(T_RESUME, ppid, 0, 0) != 0) my_e(238);
WRITE(0);
pid = READ();
if (waitpid(pid, &status, 0) != pid) my_e(239);
if (!_WIFSTOPPED(status)) my_e(240);
if (WSTOPSIG(status) != SIGSTOP) my_e(241);
if (ptrace(T_SETOPT, pid, 0, 0) != 0) my_e(242);
if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(243);
detach_running(ppid);
break;
}
return pid;
}
pid_t traced_pfork(c)
void(*c) (void);
{
pid_t pid;
if (pipe(pfd) != 0) my_e(300);
if (pipe(&pfd[2]) != 0) my_e(301);
pid = fork();
if (pid < 0) my_e(302);
if (pid == 0) {
child = 1;
c();
my_e(303);
}
return pid;
}
void WRITE(value)
int value;
{
if (write(pfd[child*2+1], &value, sizeof(value)) != sizeof(value)) my_e(400);
}
int READ()
{
int value;
if (read(pfd[2-child*2], &value, sizeof(value)) != sizeof(value)) my_e(401);
return value;
}
void traced_wait()
{
int r, status;
if (attach == 2) {
if (waitpid(ppid, &status, 0) != ppid) my_e(500);
if (!_WIFEXITED(status)) my_e(501);
if ((r = WEXITSTATUS(status)) != 0) my_e(r);
}
else {
/* Quick hack to clean up detached children */
waitpid(-1, NULL, WNOHANG);
}
close(pfd[0]);
close(pfd[1]);
close(pfd[2]);
close(pfd[3]);
}
void detach_running(pid)
pid_t pid;
{
/* Detach from a process that is not already stopped. This is the way to do it.
* We have to stop the child in order to detach from it, but as the child may
* have other signals pending for the tracer, we cannot assume we get our own
* signal back immediately. However, because we know that the kill is instant
* and resuming with pending signals will only stop the process immediately
* again, we can use T_RESUME for all the signals until we get our own signal,
* and then detach. A complicating factor is that anywhere during this
* procedure, the child may die (e.g. by getting a SIGKILL). In our tests, this
* will not happen.
*/
int status;
if (kill(pid, SIGSTOP) != 0) my_e(600);
if (waitpid(pid, &status, 0) != pid) my_e(601);
while (_WIFSTOPPED(status)) {
if (WSTOPSIG(status) == SIGSTOP) {
if (ptrace(T_DETACH, pid, 0, 0) != 0) my_e(602);
return;
}
if (ptrace(T_RESUME, pid, 0, WSTOPSIG(status)) != 0) my_e(603);
if (waitpid(pid, &status, 0) != pid) my_e(604);
}
/* Apparently the process exited. */
if (!_WIFEXITED(status) && !_WIFSIGNALED(status)) my_e(605);
/* In our tests, that should not happen. */
my_e(606);
}
void dummy_handler(sig)
int sig;
{
}
void exit_handler(sig)
int sig;
{
exit(42);
}
void count_handler(sig)
int sig;
{
sigs++;
}
void catch_handler(sig)
int sig;
{
sigset_t set;
int bit;
switch (sig) {
case SIGUSR1: bit = 1; break;
case SIGUSR2: bit = 2; break;
case SIGTERM: bit = 4; break;
default: my_e(100);
}
sigfillset(&set);
sigprocmask(SIG_SETMASK, &set, NULL);
if (caught & bit) my_e(101);
caught |= bit;
}
void test_wait_child()
{
exit(42);
}
void test_wait()
{
pid_t pid;
int status;
subtest = 1;
pid = traced_fork(test_wait_child);
if (waitpid(pid, &status, 0) != pid) my_e(1);
if (!_WIFEXITED(status)) my_e(2);
if (WEXITSTATUS(status) != 42) my_e(3);
traced_wait();
}
void test_exec_child()
{
if (READ() != 0) my_e(100);
execl(executable, "DO CHECK", NULL);
my_e(101);
}
void test_exec()
{
pid_t pid;
int r, status;
/* This test covers the T_OK case. */
if (attach != 0) return;
subtest = 2;
pid = traced_fork(test_exec_child);
WRITE(0);
/* An exec() should result in a trap signal. */
if (waitpid(pid, &status, 0) != pid) my_e(1);
if (!_WIFSTOPPED(status)) my_e(2);
if (WSTOPSIG(status) != SIGTRAP) my_e(3);
if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(4);
if (waitpid(pid, &status, 0) != pid) my_e(5);
if (!_WIFEXITED(status)) my_e(6);
if ((r = WEXITSTATUS(status)) != 42) my_e(r);
traced_wait();
}
void test_step_child()
{
sigset_t set;
signal(SIGUSR1, SIG_IGN);
WRITE(0);
if (READ() != 0) my_e(100);
/* It must not be possible for the child to stop the single-step signal. */
signal(SIGTRAP, SIG_IGN);
sigfillset(&set);
sigprocmask(SIG_SETMASK, &set, NULL);
exit(42);
}
void test_step()
{
pid_t pid;
int r, status, count;
subtest = 3;
pid = traced_fork(test_step_child);
if (READ() != 0) my_e(1);
/* While the child is running, neither waitpid() nor ptrace() should work. */
if (waitpid(pid, &status, WNOHANG) != 0) my_e(2);
if (ptrace(T_RESUME, pid, 0, 0) != -1) my_e(3);
if (errno != EBUSY) my_e(4);
if (kill(pid, SIGUSR1) != 0) my_e(5);
WRITE(0);
/* A kill() signal (other than SIGKILL) should be delivered to the tracer. */
if (waitpid(pid, &status, 0) != pid) my_e(6);
if (!_WIFSTOPPED(status)) my_e(7);
if (WSTOPSIG(status) != SIGUSR1) my_e(8);
/* ptrace(T_STEP) should result in instruction-wise progress. */
for (count = 0; ; count++) {
if (ptrace(T_STEP, pid, 0, 0) != 0) my_e(9);
if (waitpid(pid, &status, 0) != pid) my_e(10);
if (_WIFEXITED(status)) break;
if (!_WIFSTOPPED(status)) my_e(11);
if (WSTOPSIG(status) != SIGTRAP) my_e(12);
}
if ((r = WEXITSTATUS(status)) != 42) my_e(r);
if (count < 10) my_e(13); /* in practice: hundreds */
traced_wait();
}
void test_sig_child()
{
signal(SIGUSR1, exit_handler);
if (READ() != 0) my_e(100);
pause();
my_e(101);
}
void test_sig()
{
pid_t pid;
int r, sig, status;
subtest = 4;
pid = traced_fork(test_sig_child);
WRITE(0);
/* allow the child to enter the pause */
sleep(1);
if (kill(pid, SIGUSR1) != 0) my_e(1);
if (kill(pid, SIGUSR2) != 0) my_e(2);
/* All signals should arrive at the tracer, although in "random" order. */
if (waitpid(pid, &status, 0) != pid) my_e(3);
if (!_WIFSTOPPED(status)) my_e(4);
if (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGUSR2) my_e(5);
/* The tracer should see kills arriving while the tracee is stopped. */
if (kill(pid, WSTOPSIG(status)) != 0) my_e(6);
if (waitpid(pid, &status, WNOHANG) != pid) my_e(7);
if (!_WIFSTOPPED(status)) my_e(8);
if (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGUSR2) my_e(9);
sig = (WSTOPSIG(status) == SIGUSR1) ? SIGUSR2 : SIGUSR1;
if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(10);
if (waitpid(pid, &status, 0) != pid) my_e(11);
if (!_WIFSTOPPED(status)) my_e(12);
if (WSTOPSIG(status) != sig) my_e(13);
if (waitpid(pid, &status, WNOHANG) != 0) my_e(14);
if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(15);
/* Ignored signals passed via ptrace() should be ignored. */
if (kill(pid, SIGUSR1) != 0) my_e(16);
if (waitpid(pid, &status, 0) != pid) my_e(17);
if (!_WIFSTOPPED(status)) my_e(18);
if (WSTOPSIG(status) != SIGUSR1) my_e(19);
if (ptrace(T_RESUME, pid, 0, SIGCHLD) != 0) my_e(20);
/* if the pause has been aborted (shouldn't happen!), let the child exit */
sleep(1);
if (waitpid(pid, &status, WNOHANG) != 0) my_e(21);
/* Caught signals passed via ptrace() should invoke their signal handlers. */
if (kill(pid, SIGUSR1) != 0) my_e(22);
if (waitpid(pid, &status, 0) != pid) my_e(23);
if (!_WIFSTOPPED(status)) my_e(24);
if (WSTOPSIG(status) != SIGUSR1) my_e(25);
if (ptrace(T_RESUME, pid, 0, SIGUSR1) != 0) my_e(26);
if (waitpid(pid, &status, 0) != pid) my_e(27);
if (!_WIFEXITED(status)) my_e(28);
if ((r = WEXITSTATUS(status)) != 42) my_e(29);
traced_wait();
}
void test_exit_child()
{
WRITE(0);
for(;;);
}
void test_exit()
{
pid_t pid;
int r, status;
subtest = 5 10BC8 ;
pid = traced_fork(test_exit_child);
if (READ() != 0) my_e(1);
sleep(1);
if (kill(pid, SIGSTOP) != 0) my_e(2);
if (waitpid(pid, &status, 0) != pid) my_e(3);
if (!_WIFSTOPPED(status)) my_e(4);
if (WSTOPSIG(status) != SIGSTOP) my_e(5);
/* There should be no more signals pending for the tracer now. */
if (waitpid(pid, &status, WNOHANG) != 0) my_e(6);
/* ptrace(T_EXIT) should terminate the process with the given exit value. */
if (ptrace(T_EXIT, pid, 0, 42) != 0) my_e(7);
if (waitpid(pid, &status, 0) != pid) my_e(8);
if (!_WIFEXITED(status)) my_e(9);
if ((r = WEXITSTATUS(status)) != 42) my_e(r);
traced_wait();
}
void test_term_child()
{
signal(SIGUSR1, SIG_DFL);
signal(SIGUSR2, dummy_handler);
WRITE(0);
pause();
my_e(100);
}
void test_term()
{
pid_t pid;
int status;
subtest = 6;
pid = traced_fork(test_term_child);
if (READ() != 0) my_e(1);
/* If the first of two signals terminates the traced child, the second signal
* may or may not be delivered to the tracer - this is merely a policy issue.
* However, nothing unexpected should happen.
*/
if (kill(pid, SIGUSR1) != 0) my_e(2);
if (kill(pid, SIGUSR2) != 0) my_e(3);
if (waitpid(pid, &status, 0) != pid) my_e(4);
if (!_WIFSTOPPED(status)) my_e(5);
if (ptrace(T_RESUME, pid, 0, SIGUSR1) != 0) my_e(6);
if (waitpid(pid, &status, 0) != pid) my_e(7);
if (_WIFSTOPPED(status)) {
if (ptrace(T_RESUME, pid, 0, SIGUSR1) != 0) my_e(8);
if (waitpid(pid, &status, 0) != pid) my_e(9);
}
if (!_WIFSIGNALED(status)) my_e(10);
if (WTERMSIG(status) != SIGUSR1) my_e(11);
traced_wait();
}
void test_catch_child()
{
struct sigaction sa;
sigset_t set, oset;
sa.sa_handler = catch_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_NODEFER;
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigfillset(&set);
sigprocmask(SIG_SETMASK, &set, &oset);
caught = 0;
WRITE(0);
while (caught != 7) sigsuspend(&oset);
exit(42);
}
void test_catch()
{
pid_t pid;
int r, sig, status;
subtest = 7;
pid = traced_fork(test_catch_child);
if (READ() != 0) my_e(1);
if (kill(pid, SIGUSR1) != 0) my_e(2);
if (kill(pid, SIGUSR2) != 0) my_e(3);
if (waitpid(pid, &status, 0) != pid) my_e(4);
if (!_WIFSTOPPED(status)) my_e(5);
if (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGUSR2) my_e(6);
sig = (WSTOPSIG(status) == SIGUSR1) ? SIGUSR2 : SIGUSR1;
if (ptrace(T_RESUME, pid, 0, WSTOPSIG(status)) != 0) my_e(7);
if (kill(pid, SIGTERM) != 0) my_e(8);
if (waitpid(pid, &status, 0) != pid) my_e(9);
if (!_WIFSTOPPED(status)) my_e(10);
if (WSTOPSIG(status) != sig && WSTOPSIG(status) != SIGTERM) my_e(11);
if (WSTOPSIG(status) == sig) sig = SIGTERM;
if (ptrace(T_RESUME, pid, 0, WSTOPSIG(status)) != 0) my_e(12);
if (kill(pid, SIGBUS) != 0) my_e(13);
if (waitpid(pid, &status, 0) != pid) my_e(14);
if (!_WIFSTOPPED(status)) my_e(15);
if (WSTOPSIG(status) != sig && WSTOPSIG(status) != SIGBUS) my_e(16);
if (ptrace(T_RESUME, pid, 0, sig) != 0) my_e(17);
if (WSTOPSIG(status) == sig) sig = SIGBUS;
if (waitpid(pid, &status, 0) != pid) my_e(18);
if (!_WIFSTOPPED(status)) my_e(19);
if (WSTOPSIG(status) != sig) my_e(20);
if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(21);
if (waitpid(pid, &status, 0) != pid) my_e(22);
if (!_WIFEXITED(status)) my_e(23);
if ((r = WEXITSTATUS(status)) != 42) my_e(r);
traced_wait();
}
void test_kill_child()
{
sigset_t set;
signal(SIGKILL, SIG_IGN);
sigfillset(&set);
sigprocmask(SIG_SETMASK, &set, NULL);
WRITE(0);
pause();
my_e(100);
}
void test_kill()
{
pid_t pid;
int status;
subtest = 8;
pid = traced_fork(test_kill_child);
if (READ() != 0) my_e(1);
/* SIGKILL must be unstoppable in every way. */
if (kill(pid, SIGKILL) != 0) my_e(2);
if (waitpid(pid, &status, 0) != pid) my_e(3);
if (!_WIFSIGNALED(status)) my_e(4);
if (WTERMSIG(status) != SIGKILL) my_e(5);
/* After termination, the child must no longer be visible to the tracer. */
if (waitpid(pid, &status, WNOHANG) != -1) my_e(6);
if (errno != ECHILD) my_e(7);
traced_wait();
}
void test_attach_child()
{
if (ptrace(T_OK, 0, 0, 0) != -1) my_e(100);
if (errno != EBUSY) my_e(101);
WRITE(0);
if (READ() != 0) my_e(102);
exit(42);
}
void test_attach()
{
pid_t pid;
subtest = 9;
/* Attaching to kernel processes is not allowed. */
if (ptrace(T_ATTACH, -1, 0, 0) != -1) my_e(1);
if (errno != ESRCH) my_e(2);
/* Attaching to self is not allowed. */
if (ptrace(T_ATTACH, getpid(), 0, 0) != -1) my_e(3);
if (errno != EPERM) my_e(4);
/* Attaching to PM is not allowed. */
#if 0
/* FIXME: disabled until we can reliably determine PM's pid */
if (ptrace(T_ATTACH, 0, 0, 0) != -1) my_e(5);
if (errno != EPERM) my_e(6);
#endif
pid = traced_fork(test_attach_child);
/* Attaching more than once is not allowed. */
if (ptrace(T_ATTACH, pid, 0, 0) != -1) my_e(7);
if (errno != EBUSY) my_e(8);
if (READ() != 0) my_e(9);
/* Detaching a running child should not succeed. */
if (ptrace(T_DETACH, pid, 0, 0) == 0) my_e(10);
if (errno != EBUSY) my_e(11);
detach_running(pid);
WRITE(0);
traced_wait();
}
void test_detach_child()
{
struct sigaction sa;
sigset_t set, sset, oset;
sa.sa_handler = catch_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_NODEFER;
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigfillset(&set);
sigprocmask(SIG_SETMASK, &set, &oset);
sigfillset(&sset);
sigdelset(&sset, SIGUSR1);
caught = 0;
WRITE(0);
if (sigsuspend(&sset) != -1) my_e(102);
if (errno != EINTR) my_e(103);
if (caught != 1) my_e(104);
if (READ() != 0) my_e(105);
while (caught != 7) sigsuspend(&oset);
exit(42);
}
void test_detach() 4FCA
{
pid_t pid;
int r, status;
/* Can't use traced_fork(), so simplify a bit */
if (attach != 0) return;
subtest = 10;
pid = traced_pfork(test_detach_child);
if (READ() != 0) my_e(1);
/* The tracer should not see signals sent to the process before attaching. */
if (kill(pid, SIGUSR2) != 0) my_e(2);
if (ptrace(T_ATTACH, pid, 0, 0) != 0) my_e(3);
if (waitpid(pid, &status, 0) != pid) my_e(4);
if (!_WIFSTOPPED(status)) my_e(5);
if (WSTOPSIG(status) != SIGSTOP) my_e(6);
if (ptrace(T_RESUME, pid, 0, 0) != 0) my_e(7);
if (kill(pid, SIGUSR1) != 0) my_e(8);
if (waitpid(pid, &status, 0) != pid) my_e(9);
if (!_WIFSTOPPED(status)) my_e(10);
if (WSTOPSIG(status) != SIGUSR1) my_e(11);
/* Signals pending at the tracer should be passed on after detaching. */
if (kill(pid, SIGTERM) != 0) my_e(12);
/* A signal may be passed with the detach request. */
0