📄 3-17.c
字号:
/* * Test case for assertion #3 of the sigaction system call that shows * calling sigaction with a null act argument does not change the * signal handler. * * Steps: * 1. Initialize global variable to indicate handler has not been called * 2. Set the signal handler for SIGUSR1 to handler * 3. Call sigaction with a null act * 4. raise SIGUSR1 * 5. Verify handler was called.*/#include <signal.h>#include "compat.h"#define NTASKS 1static pthread_t thread[NTASKS];int handler_called = 0;void handler(int signo){ handler_called = 1;}void * th_code (void *arg){ struct sigaction act; struct sigaction oact; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGUSR1, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return NULL; } if (sigaction(SIGUSR1, 0, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return NULL; } if (raise(SIGUSR1) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return NULL; } if (handler_called) { printf("Test PASSED\n"); return 0; } printf("Test FAILED\n"); return NULL; }int init_module(void){ int i; for(i=0;i<NTASKS;i++) pthread_create(&thread[i], NULL,th_code,(void *) i); return 0; }void cleanup_module(void){ int i; for(i=0;i<NTASKS;i++) pthread_delete_np(thread[i]);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -