mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-08-01 14:30:53 +00:00
test: Add sigaction test
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
parent
8a647a582e
commit
8557e39bef
2 changed files with 54 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ SRCS += test-shmem-async.c
|
|||
SRCS += test-shmem-three-async.c
|
||||
SRCS += test-pipe-async.c
|
||||
SRCS += test-vdso.c
|
||||
SRCS += test-sigaction.c
|
||||
|
||||
SRCS-TH += test-pthreads.c
|
||||
OBJS-TH += $(patsubst %.c,%.o,$(SRCS-TH))
|
||||
|
|
|
|||
53
test/test-sigaction.c
Normal file
53
test/test-sigaction.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
|
||||
static void forked_handler(int sig)
|
||||
{
|
||||
printf("%d: %s\n", getpid(), __func__);
|
||||
}
|
||||
|
||||
static void primary_handler(int sig)
|
||||
{
|
||||
printf("%d: %s\n", getpid(), __func__);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct sigaction act;
|
||||
int pid;
|
||||
|
||||
printf("%s pid %d\n", argv[0], getpid());
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
exit(-1);
|
||||
} else if (pid == 0) {
|
||||
act.sa_handler = forked_handler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaction(SIGTSTP, &act, 0);
|
||||
|
||||
while (1) {
|
||||
kill(getppid(), SIGTSTP);
|
||||
kill(getpid(), SIGTSTP);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
} else {
|
||||
act.sa_handler = primary_handler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaction(SIGTSTP, &act, 0);
|
||||
|
||||
while (1) {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue