mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-20 15:43:16 +00:00
Add code to test queued SIGCHLD.
This commit is contained in:
parent
ebceaf6dc7
commit
14b7815fcb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=152186
@ -1,5 +1,5 @@
|
||||
# $FreeBSD$
|
||||
|
||||
SUBDIR=sigqtest1
|
||||
SUBDIR=sigqtest1 sigqtest2
|
||||
|
||||
.include <bsd.subdir.mk>
|
||||
|
8
tools/regression/sigqueue/sigqtest2/Makefile
Normal file
8
tools/regression/sigqueue/sigqtest2/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG=sigqtest2
|
||||
LDADD+=
|
||||
NO_MAN=
|
||||
DEBUG_FLAGS=-g
|
||||
|
||||
.include <bsd.prog.mk>
|
91
tools/regression/sigqueue/sigqtest2/sigqtest2.c
Normal file
91
tools/regression/sigqueue/sigqtest2/sigqtest2.c
Normal file
@ -0,0 +1,91 @@
|
||||
/* $FreeBSD$ */
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int stop_received;
|
||||
int exit_received;
|
||||
int cont_received;
|
||||
|
||||
void job_handler(int sig, siginfo_t *si, void *ctx)
|
||||
{
|
||||
int status;
|
||||
int ret;
|
||||
|
||||
if (si->si_code == CLD_STOPPED) {
|
||||
stop_received = 1;
|
||||
kill(si->si_pid, SIGCONT);
|
||||
} else if (si->si_code == CLD_EXITED) {
|
||||
ret = waitpid(si->si_pid, &status, 0);
|
||||
if (ret == -1)
|
||||
errx(1, "waitpid");
|
||||
if (!WIFEXITED(status))
|
||||
errx(1, "!WIFEXITED(status)");
|
||||
exit_received = 1;
|
||||
} else if (si->si_code == CLD_CONTINUED) {
|
||||
cont_received = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void job_control_test()
|
||||
{
|
||||
struct sigaction sa;
|
||||
pid_t pid;
|
||||
int count = 10;
|
||||
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sa.sa_sigaction = job_handler;
|
||||
sigaction(SIGCHLD, &sa, NULL);
|
||||
stop_received = 0;
|
||||
cont_received = 0;
|
||||
exit_received = 0;
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
kill(getpid(), SIGSTOP);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (!(cont_received && stop_received && exit_received)) {
|
||||
sleep(1);
|
||||
if (--count == 0)
|
||||
break;
|
||||
}
|
||||
if (!(cont_received && stop_received && exit_received))
|
||||
errx(1, "job signals lost");
|
||||
|
||||
printf("job control test OK.\n");
|
||||
}
|
||||
|
||||
void rtsig_handler(int sig, siginfo_t *si, void *ctx)
|
||||
{
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
struct sigaction sa;
|
||||
sigset_t set;
|
||||
union sigval val;
|
||||
|
||||
/* test job control with empty signal queue */
|
||||
job_control_test();
|
||||
|
||||
/* now full fill signal queue in kernel */
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sa.sa_sigaction = rtsig_handler;
|
||||
sigaction(SIGRTMIN, &sa, NULL);
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGRTMIN);
|
||||
sigprocmask(SIG_BLOCK, &set, NULL);
|
||||
val.sival_int = 1;
|
||||
while (sigqueue(getpid(), SIGRTMIN, val))
|
||||
;
|
||||
|
||||
/* signal queue is fully filled, test the job control again. */
|
||||
job_control_test();
|
||||
return (0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user