add stdint.h to test_helpers
add tests for signals
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
/*
|
||||
* Test signal catching when being signalled from parent.
|
||||
* Skip SIGKILL and SIGSTOP as these are not catchable.
|
||||
*/
|
||||
|
||||
int sig_handled = 0;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
sig_handled = 1;
|
||||
}
|
||||
|
||||
void child_proc(int signum)
|
||||
{
|
||||
|
||||
int sig;
|
||||
(void) sig;
|
||||
sigset_t sig_set;
|
||||
int status;
|
||||
|
||||
sig_handled = 0;
|
||||
|
||||
status = sigemptyset(&sig_set);
|
||||
ERROR_IF(sigemptyset, status, == -1);
|
||||
|
||||
status = sigaddset(&sig_set, signum);
|
||||
ERROR_IF(sigaddset, status, == -1);
|
||||
|
||||
struct sigaction act;
|
||||
act.sa_handler = sig_handler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaction(signum, &act, NULL);
|
||||
|
||||
status = sleep(10);
|
||||
ERROR_IF(sleep, status, == 0);
|
||||
|
||||
if (sig_handled == 0)
|
||||
{
|
||||
printf("signal handler was not called");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
void parent(int signum, pid_t pid)
|
||||
{
|
||||
int status;
|
||||
|
||||
sleep(1);
|
||||
status = kill(pid, signum);
|
||||
ERROR_IF(kill, status, != 0);
|
||||
|
||||
pid = wait(&status);
|
||||
ERROR_IF(wait, pid, == (pid_t)-1);
|
||||
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS)
|
||||
{
|
||||
printf("Child did not exit normally.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void kill_child(int signum)
|
||||
{
|
||||
int pid;
|
||||
|
||||
if ((pid = fork()) == 0)
|
||||
{
|
||||
child_proc(signum);
|
||||
}
|
||||
else
|
||||
{
|
||||
parent(signum, pid);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
for (int i = 1; i < N_SIGNALS; i++)
|
||||
{
|
||||
if (i == SIGKILL || i == SIGSTOP)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
kill_child(i);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
/*
|
||||
* ESRCH
|
||||
*/
|
||||
if (-1 == kill(999999, 0)) {
|
||||
if (ESRCH == errno) {
|
||||
printf("ESRCH error received\n");
|
||||
} else {
|
||||
printf("kill() failed on ESRCH errno not set correctly\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
printf("kill() did not fail on ESRCH\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
printf("test passed\n");
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
setuid(1); /* this is added incase user is root. If user is normal user, then it has no effect on the tests*/
|
||||
|
||||
if (kill(1, 0) == -1) {
|
||||
if (EPERM == errno) {
|
||||
printf("EPERM error received\n");
|
||||
} else {
|
||||
printf("kill() failed on EPERM errno not set correctly\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
printf("kill() did not fail on EPERM\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("test passed\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#include <signal.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
/*
|
||||
* Test signal catching when signalling self.
|
||||
* Ensure all signals can be caught (other than SIGKILL and SIGSTOP).
|
||||
*/
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int kill_self(int sig)
|
||||
{
|
||||
struct sigaction act;
|
||||
int status;
|
||||
|
||||
handler_called = 0;
|
||||
|
||||
act.sa_handler = sig_handler;
|
||||
act.sa_flags = 0;
|
||||
|
||||
status = sigemptyset(&act.sa_mask);
|
||||
ERROR_IF(sigemptyset, status, == -1);
|
||||
|
||||
status = sigaction(sig, &act, NULL);
|
||||
ERROR_IF(sigaction, status, == -1);
|
||||
|
||||
status = kill(getpid(), sig);
|
||||
ERROR_IF(kill, status, != 0);
|
||||
|
||||
if (handler_called == 0)
|
||||
{
|
||||
printf("Handler was not called\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
for (unsigned int i = 1; i < sizeof(signals_list)/sizeof(signals_list[0]); i++)
|
||||
{
|
||||
int sig = signals_list[i].signal;
|
||||
if (sig == SIGKILL || sig == SIGSTOP)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
kill_self(sig);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <signal.h>
|
||||
#include "../test_helpers.h"
|
||||
|
||||
/*
|
||||
* Send signal 0 to self. This just reports whether a signal can be sent.
|
||||
*/
|
||||
|
||||
int main()
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
status = kill(getpid(), 0);
|
||||
ERROR_IF(kill, status, != 0);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
void sig_handler (int signo) {
|
||||
(void) signo;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int killpg_test2(int signum)
|
||||
{
|
||||
int child_pid, child_pgid;
|
||||
printf("we are on signal %d\n ", signum);
|
||||
|
||||
if ((child_pid = fork()) == 0) {
|
||||
/* child here */
|
||||
struct sigaction act;
|
||||
act.sa_handler=sig_handler;
|
||||
act.sa_flags=0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaction(signum, &act, 0);
|
||||
|
||||
/* change child's process group id */
|
||||
setpgrp();
|
||||
|
||||
sigpause(SIGABRT);
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
/* parent here */
|
||||
int i;
|
||||
sigignore(signum);
|
||||
|
||||
sleep(1);
|
||||
if ((child_pgid = getpgid(child_pid)) == -1) {
|
||||
printf("Could not get pgid of child\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
if (killpg(child_pgid, signum) != 0) {
|
||||
printf("Could not raise signal being tested\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (wait(&i) == -1) {
|
||||
perror("Error waiting for child to exit\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (WEXITSTATUS(i)) {
|
||||
printf("Child exited normally\n");
|
||||
printf("Test PASSED\n");
|
||||
return 0;
|
||||
} else {
|
||||
printf("Child did not exit normally.\n");
|
||||
printf("Test FAILED\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Should have exited from parent\n");
|
||||
printf("Test FAILED\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int x;
|
||||
for (unsigned int i = 1; i < sizeof(signals_list)/sizeof(signals_list[0]); i++)
|
||||
{
|
||||
int sig = signals_list[i].signal;
|
||||
if (sig == SIGKILL || sig == SIGSTOP || sig == SIGCHLD)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
x = killpg_test2(sig);
|
||||
}
|
||||
if (x == EXIT_FAILURE){
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
if (killpg(999999, 0) != -1) {
|
||||
printf("killpg did not return -1 even though it was passed an invalid process group id.");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (errno != ESRCH) {
|
||||
printf("killpg did not set errno to ESRCH even though it was passed an invalid signal number.");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
int pgrp;
|
||||
|
||||
if ((pgrp = getpgrp()) == -1) {
|
||||
printf("Could not get process group number\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (killpg(pgrp, -1) != -1) {
|
||||
printf("killpg did not return -1 even though it was passed an invalid signal number.");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (errno != EINVAL) {
|
||||
printf("killpg did not set errno to EINVAL even though it was passed an invalid signal number.");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
printf("Caught signal %d being tested!\n", signo);
|
||||
printf("Test PASSED\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int killpg_test1(int signum)
|
||||
{
|
||||
int pgrp;
|
||||
struct sigaction act;
|
||||
|
||||
act.sa_handler=sig_handler;
|
||||
act.sa_flags=0;
|
||||
if (sigemptyset(&act.sa_mask) == -1) {
|
||||
perror("Error calling sigemptyset\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sigaction(signum, &act, 0) == -1) {
|
||||
perror("Error calling sigaction\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ((pgrp = getpgrp()) == -1) {
|
||||
printf("Could not get process group number\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (killpg(pgrp, signum) != 0) {
|
||||
printf("Could not raise signal being tested\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (unsigned int i = 0; i < sizeof(signals_list)/sizeof(signals_list[0]); i++)
|
||||
{
|
||||
int sig = signals_list[i].signal;
|
||||
if (sig == SIGKILL || sig == SIGSTOP)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
killpg_test1(sig);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int pgrp;
|
||||
|
||||
if ((pgrp = getpgrp()) == -1) {
|
||||
printf("Could not get process group number\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (killpg(pgrp, 0) != 0) {
|
||||
printf("killpg did not return success.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
void * thread_function(void *arg)
|
||||
{
|
||||
/* Does nothing */
|
||||
(void) arg;
|
||||
pthread_exit((void*)0);
|
||||
|
||||
/* To please some compilers */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t child_thread;
|
||||
pthread_t invalid_tid;
|
||||
|
||||
int rc;
|
||||
|
||||
rc = pthread_create(&child_thread, NULL,
|
||||
thread_function, NULL);
|
||||
if (rc != 0)
|
||||
{
|
||||
printf("Error at pthread_create()\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
rc = pthread_join(child_thread, NULL);
|
||||
if (rc != 0)
|
||||
{
|
||||
printf("Error at pthread_join()\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Now the child_thread exited, it is an invalid tid */
|
||||
memcpy(&invalid_tid, &child_thread,
|
||||
sizeof(pthread_t));
|
||||
// int i = pthread_kill(invalid_tid, 0);
|
||||
sleep(3);
|
||||
// printf("%d\n", i);
|
||||
// printf("esrch is %d\n", ESRCH);
|
||||
|
||||
if (pthread_kill(invalid_tid, 0) == ESRCH) {
|
||||
printf("pthread_kill() returns ESRCH.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Test Fail\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t main_thread;
|
||||
|
||||
main_thread = pthread_self();
|
||||
|
||||
if (EINVAL != pthread_kill(main_thread, -1)) {
|
||||
printf("pthread_kill() did not fail on EINVAL\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("test pass\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
# define INTHREAD 0
|
||||
# define INMAIN 1
|
||||
# define SIGTOTEST SIGABRT
|
||||
|
||||
int sem1; /* Manual semaphore */
|
||||
int handler_called = 0;
|
||||
int count = 1;
|
||||
|
||||
struct signal {
|
||||
int signum;
|
||||
};
|
||||
|
||||
void handler() {
|
||||
printf("signal was called\n");
|
||||
handler_called = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
void *a_thread_func( void *arg)
|
||||
{
|
||||
|
||||
struct sigaction act;
|
||||
act.sa_flags = 0;
|
||||
act.sa_handler = handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaction(((struct signal *)arg)->signum, &act, 0);
|
||||
|
||||
sem1=INMAIN;
|
||||
|
||||
while(sem1==INMAIN)
|
||||
sleep(1);
|
||||
|
||||
// sleep(50);
|
||||
|
||||
handler_called=-1;
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int pthread_kill_test1(int signum)
|
||||
{
|
||||
pthread_t new_th;
|
||||
|
||||
sem1=INTHREAD;
|
||||
|
||||
struct signal arg;
|
||||
arg.signum = signum;
|
||||
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, &arg) != 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while(sem1==INTHREAD)
|
||||
sleep(1);
|
||||
|
||||
if(pthread_kill(new_th, signum) != 0)
|
||||
{
|
||||
printf("Test FAILED: Couldn't send signal to thread\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sleep(2);
|
||||
sem1=INTHREAD;
|
||||
|
||||
while(handler_called==0)
|
||||
sleep(1);
|
||||
|
||||
if(handler_called == -1) {
|
||||
printf("Test FAILED: Kill request timed out\n");
|
||||
exit(EXIT_FAILURE);
|
||||
} else if (handler_called == 0) {
|
||||
printf("Test FAILED: Thread did not recieve or handle\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test PASSED for signal %d\n", signum);
|
||||
handler_called = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (unsigned int i = 0; i < sizeof(signals_list)/sizeof(signals_list[0]); i++)
|
||||
{
|
||||
int sig = signals_list[i].signal;
|
||||
if (sig == SIGKILL || sig == SIGSTOP)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
pthread_kill_test1(sig);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t main_thread;
|
||||
|
||||
main_thread=pthread_self();
|
||||
|
||||
if (pthread_kill(main_thread, 0) != 0) {
|
||||
printf("Could not call pthread_kill with sig = 0\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// The raise() function shall send the signal sig to the executing [CX] [Option Start] thread or process. [Option End] If a signal handler is called, the raise() function shall not return until after the signal handler does.
|
||||
|
||||
// [CX] [Option Start] The effect of the raise() function shall be equivalent to calling: pthread_kill(pthread_self(), sig);
|
||||
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
void sig_hand(int i)
|
||||
|
||||
{
|
||||
if (i < 1 || i > 32){
|
||||
printf("an invalid signal was given: %d", i);
|
||||
}
|
||||
static int count = 1;
|
||||
|
||||
count++;
|
||||
printf("%d \n", count);
|
||||
if (count == 32) {
|
||||
printf("reached 32nd signal\n");
|
||||
return;
|
||||
}
|
||||
else{
|
||||
printf("count is %d\n", count);
|
||||
}
|
||||
}
|
||||
|
||||
void raise_test(int sig){
|
||||
signal(sig, sig_hand);
|
||||
raise(sig);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for (int i = 0; i < N_SIGNALS; i++)
|
||||
{
|
||||
int sig = signals_list[i].signal;
|
||||
if (sig == SIGKILL || sig == SIGSTOP)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
raise_test(sig);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
|
||||
// The sigaddset() function adds the individual signal specified by the signo to the signal set pointed to by set.
|
||||
|
||||
// Applications shall call either sigemptyset() or sigfillset() at least once for each object of type sigset_t prior to any other use of that object. If such an object is not initialized in this way, but is nonetheless supplied as an argument to any of pthread_sigmask(), sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or sigwaitinfo(), the results are undefined.
|
||||
|
||||
#define _OPEN_SYS
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
|
||||
|
||||
void addset_test(sigset_t *sigset, int signal){
|
||||
if (sigismember(sigset, signal) !=0){
|
||||
printf("the signal is already in the set, %d\n", signal);
|
||||
}
|
||||
sigaddset(sigset, signal);
|
||||
if (sigismember(sigset, signal) ==1){
|
||||
printf("the signal was added successfully\n");
|
||||
}
|
||||
if (sigismember(sigset, signal) !=1){
|
||||
printf("the signal add failed\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
sigset_t sigset;
|
||||
|
||||
sigemptyset(&sigset);
|
||||
|
||||
for (int i = 1; i < N_SIGNALS; i++){
|
||||
addset_test(&sigset, i);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
|
||||
// The sigdelset() function deletes the individual signal specified by signo from the signal set pointed to by set.
|
||||
|
||||
// Applications should call either sigemptyset() or sigfillset() at least once for each object of type sigset_t prior to any other use of that object. If such an object is not initialized in this way, but is nonetheless supplied as an argument to any of pthread_sigmask(), sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or sigwaitinfo(), the results are undefined.
|
||||
|
||||
|
||||
#define _OPEN_SYS
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
|
||||
|
||||
void delset_test(sigset_t *sigset, int signal){
|
||||
if (sigismember(sigset, signal) !=1){
|
||||
printf("the signal is already out of the set, %d\n", signal);
|
||||
}
|
||||
sigdelset(sigset, signal);
|
||||
if (sigismember(sigset, signal) ==0){
|
||||
printf("the signal was deleted successfully\n");
|
||||
}
|
||||
if (sigismember(sigset, signal) !=0){
|
||||
printf("the signal remove failed\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
sigset_t sigset;
|
||||
|
||||
sigfillset(&sigset);
|
||||
|
||||
for (int i = 1; i < N_SIGNALS; i++){
|
||||
delset_test(&sigset, i);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#define _OPEN_SYS
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
sigset_t sigset;
|
||||
|
||||
sigfillset(&sigset);
|
||||
if (sigismember(&sigset, -1)!=-1){
|
||||
printf("sigismember didn't return -1");
|
||||
exit(EXIT_FAILURE);
|
||||
} else if (EINVAL != errno) {
|
||||
printf("errno was not set to EINVAL\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf ("errno set to EINVAL and sigismember returned -1\n");
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// The sigismember() function shall test whether the signal specified by signo is a member of the set pointed to by set.
|
||||
|
||||
// Applications should call either sigemptyset() or sigfillset() at least once for each object of type sigset_t prior to any other use of that object. If such an object is not initialized in this way, but is nonetheless supplied as an argument to any of pthread_sigmask(), sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or sigwaitinfo(), the results are undefined.
|
||||
|
||||
|
||||
|
||||
#define _OPEN_SYS
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
void check(sigset_t set, int signum) {
|
||||
printf("%d is ", signum);
|
||||
if (!sigismember(&set, signum))
|
||||
printf("not ");
|
||||
puts("in the set");
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
sigset_t sigset;
|
||||
|
||||
sigfillset(&sigset);
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
check(sigset, i);
|
||||
}
|
||||
|
||||
sigemptyset(&sigset);
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
check(sigset, i);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "../test_helpers.h"
|
||||
#include <signal.h>
|
||||
|
||||
/*
|
||||
* This is a test to ensure all required items for signal.h are defined.
|
||||
* The definitions follow the order described in
|
||||
* <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>
|
||||
*/
|
||||
|
||||
void handler(int sig_num)
|
||||
{
|
||||
(void)sig_num;
|
||||
}
|
||||
|
||||
void action(int sig_num, siginfo_t *info, void *context)
|
||||
{
|
||||
(void)sig_num;
|
||||
(void)info;
|
||||
(void)context;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int (*sh)(int) __attribute__((unused)) = sighold;
|
||||
int (*sigig)(int) __attribute__((unused)) = sigignore;
|
||||
int (*sigintr)(int, int) __attribute__((unused)) = siginterrupt;
|
||||
int (*paws)(int) __attribute__((unused)) = sigpause;
|
||||
int (*srls)(int) __attribute__((unused)) = sigrelse;
|
||||
void (*(*sset)(int, void (*)(int)))(int) __attribute__((unused)) = sigset;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
#include "../test_helpers.h"
|
||||
#include <signal.h>
|
||||
|
||||
/*
|
||||
* This is a test to ensure all required items for signal.h are defined.
|
||||
* The definitions follow the order described in
|
||||
* <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>
|
||||
*/
|
||||
|
||||
void handler(int sig_num)
|
||||
{
|
||||
(void)sig_num;
|
||||
}
|
||||
|
||||
void action(int sig_num, siginfo_t *info, void *context)
|
||||
{
|
||||
(void)sig_num;
|
||||
(void)info;
|
||||
(void)context;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
void (*sig_dfl)(int) __attribute__((unused)) = SIG_DFL;
|
||||
void (*sig_err)(int) __attribute__((unused)) = SIG_ERR;
|
||||
void (*sig_ign)(int) __attribute__((unused)) = SIG_IGN;
|
||||
|
||||
pthread_t pthread_num __attribute__((unused)) = 0;
|
||||
size_t size __attribute__((unused)) = 0;
|
||||
uid_t uid __attribute__((unused)) = 0;
|
||||
|
||||
sig_atomic_t atomic __attribute__((unused)) = 0;
|
||||
sigset_t sig_set __attribute__((unused)) ;
|
||||
pid_t pid __attribute__((unused)) = 0;
|
||||
|
||||
pthread_attr_t *attr __attribute__((unused)) = NULL;
|
||||
|
||||
// struct sigevent sev;
|
||||
union sigval sv;
|
||||
|
||||
sv.sival_int = (int)0;
|
||||
sv.sival_ptr = (void *)0;
|
||||
|
||||
// sev.sigev_notify = (int)0;
|
||||
// sev.sigev_notify = SIGEV_NONE;
|
||||
// sev.sigev_notify = SIGEV_SIGNAL;
|
||||
// sev.sigev_notify = SIGEV_THREAD;
|
||||
|
||||
// sev.sigev_signo = (int)0;
|
||||
// sev.sigev_value = sv;
|
||||
// sev.sigev_value.sival_int = (int)0;
|
||||
// sev.sigev_value.sival_ptr = (void *)0;
|
||||
// sev.sigev_notify_function = (void (*)(union sigval))0;
|
||||
// sev.sigev_notify_attributes = (pthread_attr_t *)0;
|
||||
|
||||
int rt_sig_num __attribute__((unused)) = SIGRTMIN;
|
||||
rt_sig_num = SIGRTMAX;
|
||||
|
||||
// rt_sig_num = SIG2STR_MAX;
|
||||
|
||||
// sev.sigev_signo = SIGABRT;
|
||||
// sev.sigev_signo = SIGALRM;
|
||||
// sev.sigev_signo = SIGBUS;
|
||||
// sev.sigev_signo = SIGCHLD;
|
||||
// sev.sigev_signo = SIGCONT;
|
||||
// sev.sigev_signo = SIGFPE;
|
||||
// sev.sigev_signo = SIGHUP;
|
||||
// sev.sigev_signo = SIGILL;
|
||||
// sev.sigev_signo = SIGINT;
|
||||
// sev.sigev_signo = SIGKILL;
|
||||
// sev.sigev_signo = SIGPIPE;
|
||||
// sev.sigev_signo = SIGQUIT;
|
||||
// sev.sigev_signo = SIGSEGV;
|
||||
// sev.sigev_signo = SIGSTOP;
|
||||
// sev.sigev_signo = SIGTERM;
|
||||
// sev.sigev_signo = SIGTSTP;
|
||||
// sev.sigev_signo = SIGTTIN;
|
||||
// sev.sigev_signo = SIGTTOU;
|
||||
// sev.sigev_signo = SIGUSR1;
|
||||
// sev.sigev_signo = SIGUSR2;
|
||||
// sev.sigev_signo = SIGWINCH;
|
||||
// sev.sigev_signo = SIGPOLL;
|
||||
// sev.sigev_signo = SIGPROF;
|
||||
// sev.sigev_signo = SIGSYS;
|
||||
// sev.sigev_signo = SIGTRAP;
|
||||
// sev.sigev_signo = SIGURG;
|
||||
// sev.sigev_signo = SIGVTALRM;
|
||||
// sev.sigev_signo = SIGXCPU;
|
||||
// sev.sigev_signo = SIGXFSZ;
|
||||
|
||||
struct sigaction sa;
|
||||
|
||||
sa.sa_handler = SIG_IGN;
|
||||
sa.sa_handler = SIG_DFL;
|
||||
sa.sa_handler = handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = (int)0;
|
||||
sa.sa_sigaction = action;
|
||||
|
||||
#ifndef SA_NOCLDSTOP
|
||||
#error "Required constant not defined SA_NOCLDSTOP"
|
||||
#endif
|
||||
#ifndef SIG_BLOCK
|
||||
#error "Required constant not defined SIG_BLOCK"
|
||||
#endif
|
||||
#ifndef SIG_UNBLOCK
|
||||
#error "Required constant not defined SIG_UNBLOCK"
|
||||
#endif
|
||||
#ifndef SIG_SETMASK
|
||||
#error "Required constant not defined SIG_SETMASK"
|
||||
#endif
|
||||
#ifndef SA_ONSTACK
|
||||
#error "Required constant not defined SA_ONSTACK"
|
||||
#endif
|
||||
#ifndef SA_RESETHAND
|
||||
#error "Required constant not defined SA_RESETHAND"
|
||||
#endif
|
||||
#ifndef SA_RESTART
|
||||
#error "Required constant not defined SA_RESTART"
|
||||
#endif
|
||||
#ifndef SA_SIGINFO
|
||||
#error "Required constant not defined SA_SIGINFO"
|
||||
#endif
|
||||
#ifndef SA_NOCLDWAIT
|
||||
#error "Required constant not defined SA_NOCLDWAIT"
|
||||
#endif
|
||||
#ifndef SA_NODEFER
|
||||
#error "Required constant not defined SA_NODEFER"
|
||||
#endif
|
||||
#ifndef SS_ONSTACK
|
||||
#error "Required constant not defined SS_ONSTACK"
|
||||
#endif
|
||||
#ifndef SS_DISABLE
|
||||
#error "Required constant not defined SS_DISABLE"
|
||||
#endif
|
||||
#ifndef MINSIGSTKSZ
|
||||
#error "Required constant not defined MINSIGSTKSZ"
|
||||
#endif
|
||||
#ifndef SIGSTKSZ
|
||||
#error "Required constant not defined SIGSTKSZ"
|
||||
#endif
|
||||
|
||||
// struct ucontext_t uc;
|
||||
mcontext_t mc __attribute__((unused));
|
||||
|
||||
// add parts to ucontext_t
|
||||
// uc.uc_link = NULL;
|
||||
// uc.uc_sigmask = 0;
|
||||
// uc.uc_stack = NULL;
|
||||
// uc.uc_mcontext = NULL;
|
||||
|
||||
|
||||
stack_t st __attribute__((unused));
|
||||
st.ss_sp = NULL;
|
||||
st.ss_size = (size_t)0;
|
||||
st.ss_flags = (int)0;
|
||||
|
||||
siginfo_t si __attribute__((unused));
|
||||
si.si_signo = SIGHUP;
|
||||
si.si_code = (int)0;
|
||||
si.si_errno = (int)0;
|
||||
si.si_pid = (pid_t)0;
|
||||
si.si_uid = (uid_t)0;
|
||||
si.si_addr = NULL;
|
||||
si.si_status = (int)0;
|
||||
si.si_value = sv;
|
||||
|
||||
// si.si_code = ILL_ILLOPC;
|
||||
// si.si_code = ILL_ILLOPN;
|
||||
// si.si_code = ILL_ILLADR;
|
||||
// si.si_code = ILL_ILLTRP;
|
||||
// si.si_code = ILL_PRVOPC;
|
||||
// si.si_code = ILL_PRVREG;
|
||||
// si.si_code = ILL_COPROC;
|
||||
// si.si_code = ILL_BADSTK;
|
||||
// si.si_code = FPE_INTDIV;
|
||||
// si.si_code = FPE_INTOVF;
|
||||
// si.si_code = FPE_FLTDIV;
|
||||
// si.si_code = FPE_FLTOVF;
|
||||
// si.si_code = FPE_FLTUND;
|
||||
// si.si_code = FPE_FLTRES;
|
||||
// si.si_code = FPE_FLTINV;
|
||||
// si.si_code = FPE_FLTSUB;
|
||||
// si.si_code = SEGV_MAPERR;
|
||||
// si.si_code = SEGV_ACCERR;
|
||||
// si.si_code = BUS_ADRALN;
|
||||
// si.si_code = BUS_ADRERR;
|
||||
// si.si_code = BUS_OBJERR;
|
||||
// si.si_code = TRAP_BRKPT;
|
||||
// si.si_code = TRAP_TRACE;
|
||||
// si.si_code = CLD_EXITED;
|
||||
// si.si_code = CLD_KILLED;
|
||||
// si.si_code = CLD_DUMPED;
|
||||
// si.si_code = CLD_TRAPPED;
|
||||
// si.si_code = CLD_STOPPED;
|
||||
// si.si_code = CLD_CONTINUED;
|
||||
// si.si_code = SI_USER;
|
||||
// si.si_code = SI_QUEUE;
|
||||
// si.si_code = SI_TIMER;
|
||||
// si.si_code = SI_ASYNCIO;
|
||||
// si.si_code = SI_MESGQ;
|
||||
|
||||
// void (*(*bs)(int, void (*)(int)))(int) = bsd_signal;
|
||||
int (*k)(pid_t, int) __attribute__((unused))= kill;
|
||||
int (*kpg)(pid_t, int) __attribute__((unused))= killpg;
|
||||
void (*psig)(const siginfo_t *, const char *) __attribute__((unused))= psiginfo;
|
||||
void (*ps)(int, const char *) __attribute__((unused))= psignal;
|
||||
int (*ptk)(pthread_t, int) __attribute__((unused))= pthread_kill;
|
||||
int (*ptsm)(int, const sigset_t *, sigset_t *) __attribute__((unused))= pthread_sigmask;
|
||||
int (*r)(int) __attribute__((unused))= raise;
|
||||
// int (*s2s)(int, char*) = sig2str;
|
||||
int (*sact)(int, const struct sigaction *restrict,
|
||||
struct sigaction *restrict) __attribute__((unused)) = sigaction;
|
||||
int (*sas)(sigset_t *, int) __attribute__((unused))= sigaddset;
|
||||
int (*sastk)(const stack_t *restrict, stack_t *restrict) __attribute__((unused))= sigaltstack;
|
||||
int (*sds)(sigset_t *, int) __attribute__((unused))= sigdelset;
|
||||
int (*ses)(sigset_t *) __attribute__((unused))= sigemptyset;
|
||||
int (*sfs)(sigset_t *) __attribute__((unused))= sigfillset;
|
||||
int (*ismem)(const sigset_t *, int) __attribute__((unused))= sigismember;
|
||||
void ( *(*sgnl)(int, void (*)(int)))(int) __attribute__((unused))= signal;
|
||||
int (*pend)(sigset_t *) __attribute__((unused))= sigpending;
|
||||
int (*spmsk)(int, const sigset_t *restrict, sigset_t *restrict) __attribute__((unused))= sigprocmask;
|
||||
int (*sigq)(pid_t, int, const union sigval) __attribute__((unused))= sigqueue;
|
||||
int (*susp)(const sigset_t *) __attribute__((unused))= sigsuspend;
|
||||
int (*stmwt)(const sigset_t *restrict, siginfo_t *restrict,
|
||||
const struct timespec *restrict) __attribute__((unused))= sigtimedwait;
|
||||
int (*swt)(const sigset_t *restrict, int *restrict) __attribute__((unused))= sigwait;
|
||||
int (*swtinfo)(const sigset_t *restrict, siginfo_t *restrict) __attribute__((unused))= sigwaitinfo;
|
||||
// int (*str2s)(const char *restrict, int *restrict) = str2sig;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void SIGUSR1_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
printf("do nothing useful\n");
|
||||
}
|
||||
|
||||
void SIGUSR2_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
printf("do nothing useful\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (signal(SIGUSR1, SIGUSR1_handler) == SIG_ERR) {
|
||||
perror("Unexpected error while using signal()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (signal(SIGUSR2, SIGUSR2_handler) == SIG_ERR) {
|
||||
perror("Unexpected error while using signal()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (signal(SIGUSR1,SIG_IGN) != SIGUSR1_handler) {
|
||||
printf("signal did not return the last handler that was associated with SIGUSR1\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("test passed\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
printf("SIGCHLD called. Inside handler\n");
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (signal(SIGCHLD, sig_handler) == SIG_ERR) {
|
||||
perror("Unexpected error while using signal()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (signal(SIGCHLD,SIG_DFL) != sig_handler) {
|
||||
perror("Unexpected error while using signal()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
raise(SIGCHLD);
|
||||
|
||||
if (handler_called == 1) {
|
||||
printf("Test FAILED: handler was called even though default was expected\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("test passed \n");
|
||||
handler_called = 0;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
printf("%d called. Inside handler\n", signo);
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int signal_test3(int signum)
|
||||
{
|
||||
if (signal(signum, sig_handler) == SIG_ERR) {
|
||||
perror("Unexpected error while using signal()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
raise(signum);
|
||||
|
||||
if (handler_called != 1) {
|
||||
printf("Test FAILED: handler wasn't called even though it should have been\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("test %d passed\n", signum);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
signal_test3(i);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
printf("%d called. Inside handler\n", signo);
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int signal_test2(int signum)
|
||||
{
|
||||
if (signal(signum, sig_handler) == SIG_ERR) {
|
||||
perror("Unexpected error while using signal()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (signal(signum,SIG_IGN) != sig_handler) {
|
||||
perror("Unexpected error while using signal()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
raise(signum);
|
||||
|
||||
if (handler_called == 1) {
|
||||
printf("Test FAILED: handler was called even though ingore was expected\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("test %d passed\n", signum);
|
||||
handler_called = 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
signal_test2(i);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
printf("handler does nothing useful.\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
errno = -1;
|
||||
|
||||
if (signal(-1, sig_handler) != SIG_ERR) {
|
||||
printf("Test FAILED: signal() didn't return SIG_ERR even though invalid signal number was passed to it\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (errno <= 0) {
|
||||
printf("Test FAILED: errno wasn't set to a positive number even though invalid signal number was passed to the signal() function\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("test passed\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
printf("handler does nothing useful.\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
errno = -1;
|
||||
|
||||
if (signal(SIGKILL, sig_handler) != SIG_ERR) {
|
||||
printf("Test FAILED: signal() didn't return SIG_ERR even though a non-catchable signal was passed to it\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (errno <= 0) {
|
||||
printf("Test FAILED: errno wasn't set to a positive number even though a non-catchable signal was passed to the signal() function\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("test passed\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
#ifndef _SIGNALS_LIST
|
||||
#define _SIGNALS_LIST 1
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef SIGSTKFLT
|
||||
#endif
|
||||
|
||||
const int N_SIGNALS = (28
|
||||
#ifdef SIGSTKFLT
|
||||
+ 1
|
||||
#endif
|
||||
#ifdef SIGWINCH
|
||||
+ 1
|
||||
#endif
|
||||
#ifdef SIGIO
|
||||
+ 1
|
||||
#endif
|
||||
#ifdef SIGPWR
|
||||
+ 1
|
||||
#endif
|
||||
#ifdef SIGUNUSED
|
||||
+ 1
|
||||
#endif
|
||||
);
|
||||
|
||||
struct signalAction
|
||||
{
|
||||
int signal;
|
||||
char action;
|
||||
};
|
||||
|
||||
const struct signalAction signals_list[] = {
|
||||
{SIGABRT, 'A'},
|
||||
{SIGALRM, 'T'},
|
||||
{SIGBUS, 'A'},
|
||||
{SIGCHLD, 'I'},
|
||||
{SIGCONT, 'C'},
|
||||
{SIGFPE, 'A'},
|
||||
{SIGHUP, 'T'},
|
||||
{SIGILL, 'A'},
|
||||
{SIGINT, 'T'},
|
||||
{SIGKILL, 'T'},
|
||||
{SIGPIPE, 'T'},
|
||||
{SIGQUIT, 'A'},
|
||||
{SIGSEGV, 'A'},
|
||||
{SIGSTOP, 'S'},
|
||||
{SIGTERM, 'T'},
|
||||
{SIGTSTP, 'S'},
|
||||
{SIGTTIN, 'S'},
|
||||
{SIGTTOU, 'S'},
|
||||
{SIGUSR1, 'T'},
|
||||
{SIGUSR2, 'T'},
|
||||
// {SIGPOLL, 'T'},
|
||||
{SIGPROF, 'T'},
|
||||
{SIGSYS, 'A'},
|
||||
{SIGTRAP, 'A'},
|
||||
{SIGURG, 'I'},
|
||||
{SIGVTALRM, 'T'},
|
||||
{SIGXCPU, 'A'},
|
||||
{SIGXFSZ, 'A'},
|
||||
#ifdef SIGSTKFLT
|
||||
{SIGSTKFLT, 'T'},
|
||||
#endif
|
||||
#ifdef SIGWINCH
|
||||
{SIGWINCH, 'I'},
|
||||
#endif
|
||||
#ifdef SIGIO
|
||||
{SIGIO, 'T'},
|
||||
#endif
|
||||
#ifdef SIGPWR
|
||||
{SIGPWR, 'T'},
|
||||
#endif
|
||||
#ifdef SIGUNUSED
|
||||
{SIGUNUSED, 'A'},
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* _SIGNALS_LIST */
|
||||
@@ -0,0 +1,102 @@
|
||||
#define _XOPEN_SOURCE 700
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
#define INMAIN 0
|
||||
#define INTHREAD 1
|
||||
|
||||
int handler_called = 0;
|
||||
int returned = 0;
|
||||
int return_value = 2;
|
||||
int result = 2;
|
||||
int sem = INMAIN;
|
||||
|
||||
void handler() {
|
||||
// printf("signal was called\n");
|
||||
handler_called = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
void *d_thread_func(void *sig)
|
||||
{
|
||||
|
||||
int signum = *(int *)sig;
|
||||
printf("%d !!!\n", signum);
|
||||
int return_value = 0;
|
||||
struct sigaction act;
|
||||
act.sa_flags = 0;
|
||||
act.sa_handler = handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaction(signum, &act, 0);
|
||||
return_value = sigpause(signum);
|
||||
if (return_value == -1) {
|
||||
if (errno == EINTR) {
|
||||
printf ("Test PASSED: sigpause returned -1 and set errno to EINTR\n");
|
||||
result = 0;
|
||||
} else {
|
||||
printf ("Test FAILED: sigpause did not set errno to EINTR\n");
|
||||
result = 1;
|
||||
}
|
||||
} else {
|
||||
if (errno == EINTR) {
|
||||
printf ("Test FAILED: sigpause did not return -1\n");
|
||||
}
|
||||
printf ("Test FAILED: sigpause did not set errno to EINTR\n");
|
||||
printf ("Test FAILED: sigpause did not return -1\n");
|
||||
result = 1;
|
||||
|
||||
}
|
||||
sem = INMAIN;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int sigpause_error(int signum){
|
||||
pthread_t new_th;
|
||||
|
||||
if ((pthread_create(&new_th, NULL, d_thread_func, (void *)&signum)) != 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
if(pthread_kill(new_th, signum) != 0)
|
||||
{
|
||||
printf("Test UNRESOLVED: Couldn't send signal to thread\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sem = INTHREAD;
|
||||
while (sem == INTHREAD)
|
||||
sleep(1);
|
||||
|
||||
if(result == 2) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if(result == 1) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
sigpause_error(i);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#define _XOPEN_SOURCE 700
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define INMAIN 0
|
||||
#define INTHREAD 1
|
||||
|
||||
int handler_called = 0;
|
||||
int returned = 0;
|
||||
int return_value = 2;
|
||||
int result = 2;
|
||||
int sem = INMAIN;
|
||||
|
||||
void handler() {
|
||||
// printf("signal was called\n");
|
||||
handler_called = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
int sigpause_invalid(){
|
||||
int return_value = 0;
|
||||
|
||||
return_value = sigpause(-1);
|
||||
if (return_value == -1) {
|
||||
if (errno == EINVAL) {
|
||||
printf ("Test PASSED: sigpause returned -1 and set errno to EINVAL\n");
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
printf ("Test FAILED: sigpause did not set errno to EINVAL\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
printf ("Test FAILED: sigpause did not return -1\n");
|
||||
if (errno == EINVAL) {
|
||||
printf ("Test FAILED: sigpause did not set errno to EINVAL\n");
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
int main(){
|
||||
sigpause_invalid();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#define _XOPEN_SOURCE 700
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void handler() {
|
||||
// printf("signal was called\n");
|
||||
handler_called = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
void *a_thread_func(void *sig)
|
||||
{
|
||||
int signum = *(int *)sig;
|
||||
printf("%d !!!\n", signum);
|
||||
struct sigaction act;
|
||||
act.sa_flags = 0;
|
||||
act.sa_handler = handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaction(signum, &act, 0);
|
||||
sighold(signum);
|
||||
sigpause(signum);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int sigpause_basic(int signum)
|
||||
{
|
||||
pthread_t new_th;
|
||||
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, (void *)&signum) != 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
if(pthread_kill(new_th, signum) != 0)
|
||||
{
|
||||
printf("Test UNRESOLVED: Couldn't send signal to thread\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
if(handler_called != 1) {
|
||||
printf("Test FAILED: signal wasn't removed from signal mask\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
handler_called = 0;
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
sigpause_basic(i);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
#define _XOPEN_SOURCE 700
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
#define INMAIN 0
|
||||
#define INTHREAD 1
|
||||
|
||||
int handler_called = 0;
|
||||
int returned = 0;
|
||||
int return_value = 2;
|
||||
int result = 2;
|
||||
int sem = INMAIN;
|
||||
|
||||
void handler() {
|
||||
// printf("signal was called\n");
|
||||
handler_called = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
void *c_thread_func(void *sig)
|
||||
{
|
||||
int signum = *(int *)sig;
|
||||
printf("%d !!!\n", signum);
|
||||
struct sigaction act;
|
||||
sigset_t pendingset;
|
||||
|
||||
act.sa_flags = 0;
|
||||
act.sa_handler = handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaction(signum, &act, 0);
|
||||
sighold(signum);
|
||||
printf("after sigpause\n");
|
||||
|
||||
if ((sigpause(signum) != -1) || (errno != EINTR)) {
|
||||
printf ("Test UNRESOLVED: sigpause didn't return -1 and/or didn't set errno correctly.");
|
||||
return_value = 2;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
raise (signum);
|
||||
sigpending(&pendingset);
|
||||
if (sigismember(&pendingset, signum) == 1) {
|
||||
printf("Test PASSED: signal mask was restored when sigpause returned.");
|
||||
return_value = 0;
|
||||
}
|
||||
|
||||
sem = INMAIN;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
int sigpause_revert(int signum){
|
||||
pthread_t new_th;
|
||||
|
||||
if(pthread_create(&new_th, NULL, c_thread_func, (void *)&signum) != 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
if(pthread_kill(new_th, signum) != 0)
|
||||
{
|
||||
printf("Test UNRESOLVED: Couldn't send signal to thread\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sem = INTHREAD;
|
||||
while (sem == INTHREAD)
|
||||
sleep(1);
|
||||
|
||||
if(handler_called != 1) {
|
||||
printf("Test UNRESOLVED: signal wasn't removed from signal mask\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (return_value != 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
sigpause_revert(i);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
#define _XOPEN_SOURCE 700
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
#define INMAIN 0
|
||||
#define INTHREAD 1
|
||||
|
||||
int handler_called = 0;
|
||||
int returned = 0;
|
||||
int return_value = 2;
|
||||
int result = 2;
|
||||
int sem = INMAIN;
|
||||
|
||||
void handler() {
|
||||
// printf("signal was called\n");
|
||||
handler_called = 1;
|
||||
return;
|
||||
}
|
||||
void *b_thread_func(void *sig)
|
||||
{
|
||||
int signum = *(int *)sig;
|
||||
printf("%d !!!\n", signum);
|
||||
struct sigaction act;
|
||||
act.sa_flags = 0;
|
||||
act.sa_handler = handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaction(signum, &act, 0);
|
||||
sigpause(signum);
|
||||
returned = 1;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int sigpause_suspend(int signum)
|
||||
{
|
||||
pthread_t new_th;
|
||||
int j;
|
||||
|
||||
if(pthread_create(&new_th, NULL, b_thread_func, (void *)&signum) != 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (j=0; j<10; j++) {
|
||||
sleep(1);
|
||||
if (returned == 1) {
|
||||
printf ("Test FAILED: sigpause returned before it received a signal\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if(pthread_kill(new_th, signum) != 0)
|
||||
{
|
||||
printf("Test UNRESOLVED: Couldn't send signal to thread\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
if(returned != 1) {
|
||||
printf("Test FAILED: signal was sent, but sigpause never returned.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
returned = 0;
|
||||
|
||||
printf("test passed\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
sigpause_suspend(i);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define NUMSIGNALS 24
|
||||
|
||||
int is_changed(sigset_t set) {
|
||||
|
||||
int i;
|
||||
int siglist[] = {SIGALRM, SIGBUS, SIGCHLD,
|
||||
SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
|
||||
SIGPIPE, SIGQUIT, SIGSEGV,
|
||||
SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU,
|
||||
SIGUSR1, SIGUSR2, SIGPROF, SIGSYS,
|
||||
SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ };
|
||||
|
||||
for (i=0; i<NUMSIGNALS; i++) {
|
||||
if (sigismember(&set, siglist[i]) != 0)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_rand() {
|
||||
|
||||
int r;
|
||||
r=rand();
|
||||
while ((r == SIG_BLOCK) || (r == SIG_SETMASK) || (r == SIG_UNBLOCK)) {
|
||||
r = get_rand();
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
int r=get_rand();
|
||||
sigset_t actl, oactl;
|
||||
|
||||
sigemptyset(&actl);
|
||||
sigemptyset(&oactl);
|
||||
sigaddset(&actl, SIGABRT);
|
||||
|
||||
sigprocmask(SIG_SETMASK, &actl, NULL);
|
||||
|
||||
sigaddset(&actl, SIGALRM);
|
||||
if (sigprocmask(r, &actl, NULL) != -1) {
|
||||
perror("sigprocmask() did not fail even though invalid how parameter was passed to it.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sigprocmask(SIG_SETMASK, NULL, &oactl);
|
||||
|
||||
if (sigismember(&oactl, SIGABRT) != 1) {
|
||||
printf("FAIL: signal mask was changed. \n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (is_changed(oactl)) {
|
||||
printf("FAIL: signal mask was changed. \n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("PASS: signal mask was not changed.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// I don't understand this test
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
sigset_t set;
|
||||
sigaddset (&set, SIGABRT);
|
||||
|
||||
if (sigprocmask(SIG_SETMASK, &set, NULL) != 0) {
|
||||
perror("sigprocmask failed -- returned -- test aborted");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("sigignore passed\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int signo;
|
||||
(void) signo;
|
||||
int r=rand();
|
||||
sigset_t set;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s [1|2|3|4]\n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
Various error conditions
|
||||
*/
|
||||
switch (argv[1][0]) {
|
||||
case '1':
|
||||
signo=-1;
|
||||
break;
|
||||
case '2':
|
||||
signo=-10000;
|
||||
break;
|
||||
case '3':
|
||||
signo=INT32_MIN+1;
|
||||
break;
|
||||
case '4':
|
||||
signo=INT32_MIN;
|
||||
break;
|
||||
default:
|
||||
printf("Usage: %s [1|2|3|4]\n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sigaddset(&set, SIGABRT);
|
||||
|
||||
if (sigprocmask(r, &set, NULL) == -1) {
|
||||
if (EINVAL == errno) {
|
||||
printf ("errno set to EINVAL\n");
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
printf ("errno not set to EINVAL\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
printf("sighold did not return -1\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int sigprocmask_block(int signum)
|
||||
{
|
||||
int defaultsig = SIGALRM;
|
||||
if (signum == SIGALRM) {
|
||||
defaultsig = SIGHUP;
|
||||
}
|
||||
struct sigaction act;
|
||||
sigset_t set1, set2, pending_set;
|
||||
sigemptyset(&set1);
|
||||
sigemptyset(&set2);
|
||||
sigaddset(&set1, defaultsig);
|
||||
sigaddset(&set2, signum);
|
||||
|
||||
act.sa_handler = sig_handler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
if (sigaction(signum, &act, 0) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
if (sigaction(defaultsig, &act, 0) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigprocmask(SIG_SETMASK, &set1, NULL) == -1) {
|
||||
perror("Unexpected error while attempting to use sigprocmask.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigprocmask(SIG_UNBLOCK, &set2, NULL) == -1) {
|
||||
perror("Unexpected error while attempting to use sigprocmask.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (raise(signum) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!handler_called) {
|
||||
printf("FAIL: Handler was not called while it should have been\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
handler_called = 0;
|
||||
|
||||
if (raise(defaultsig) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (handler_called) {
|
||||
printf("FAIL: signal was not blocked\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigpending(&pending_set) == -1) {
|
||||
perror("Unexpected error while attempting to use sigpending\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigismember(&pending_set, defaultsig) != 1) {
|
||||
perror("FAIL: sigismember did not return 1\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigismember(&pending_set, signum) != 0) {
|
||||
perror("FAIL: sigismember did not return 0\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test PASSED: signal was added to the process's signal mask\n");
|
||||
act.sa_handler = SIG_IGN;
|
||||
sigaction(signum, &act, 0);
|
||||
sigaction(defaultsig, &act, 0);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
sigprocmask_block(i);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define NUMSIGNALS 26
|
||||
|
||||
int main()
|
||||
{
|
||||
sigset_t oactl, tempset;
|
||||
int i, j, test_failed=0;
|
||||
|
||||
int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD,
|
||||
SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
|
||||
SIGPIPE, SIGQUIT, SIGSEGV,
|
||||
SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU,
|
||||
SIGUSR1, SIGUSR2, SIGPROF, SIGSYS,
|
||||
SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ };
|
||||
|
||||
for (i=0; i<NUMSIGNALS; i++) {
|
||||
sigemptyset(&oactl);
|
||||
sigemptyset(&tempset);
|
||||
sigaddset(&tempset, siglist[i]);
|
||||
sigprocmask(SIG_BLOCK, &tempset, &oactl);
|
||||
if (i > 0) {
|
||||
for (j=0; j<i; j++) {
|
||||
if (sigismember(&oactl, siglist[j]) != 1) {
|
||||
test_failed = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (test_failed != 0) {
|
||||
printf("Old set is missing a signal\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test PASSED: oactl did contain all signals that were added to the signal mask.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define NUMSIGNALS 25
|
||||
|
||||
int is_changed(sigset_t set, int sig) {
|
||||
|
||||
int i;
|
||||
int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD,
|
||||
SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
|
||||
SIGPIPE, SIGQUIT, SIGSEGV,
|
||||
SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU,
|
||||
SIGUSR1, SIGUSR2, SIGPROF, SIGSYS,
|
||||
SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ };
|
||||
|
||||
if (sigismember(&set, sig) != 1) {
|
||||
return 1;
|
||||
}
|
||||
for (i=0; i<NUMSIGNALS; i++) {
|
||||
if ((siglist[i] != sig)) {
|
||||
if (sigismember(&set, siglist[i]) != 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
sigset_t actl, oactl;
|
||||
|
||||
sigemptyset(&actl);
|
||||
sigemptyset(&oactl);
|
||||
|
||||
sigaddset(&actl, SIGABRT);
|
||||
|
||||
sigprocmask(SIG_SETMASK, &actl, NULL);
|
||||
sigprocmask(SIG_BLOCK, NULL, &oactl);
|
||||
|
||||
if (is_changed(oactl, SIGABRT)) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("PASS: signal mask was not changed.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define NUMSIGNALS 25
|
||||
|
||||
int is_changed(sigset_t set, int sig) {
|
||||
|
||||
int i;
|
||||
int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD,
|
||||
SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
|
||||
SIGPIPE, SIGQUIT, SIGSEGV,
|
||||
SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU,
|
||||
SIGUSR1, SIGUSR2, SIGPROF, SIGSYS,
|
||||
SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ };
|
||||
|
||||
if (sigismember(&set, sig) != 1) {
|
||||
return 1;
|
||||
}
|
||||
for (i=0; i<NUMSIGNALS; i++) {
|
||||
if ((siglist[i] != sig)) {
|
||||
if (sigismember(&set, siglist[i]) != 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
sigset_t actl, oactl;
|
||||
|
||||
sigemptyset(&actl);
|
||||
sigemptyset(&oactl);
|
||||
|
||||
sigaddset(&actl, SIGABRT);
|
||||
|
||||
sigprocmask(SIG_SETMASK, &actl, NULL);
|
||||
sigprocmask(SIG_SETMASK, NULL, &oactl);
|
||||
|
||||
if (is_changed(oactl, SIGABRT)) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("PASS: signal mask was not changed.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define NUMSIGNALS 25
|
||||
|
||||
int is_changed(sigset_t set, int sig) {
|
||||
|
||||
int i;
|
||||
int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD,
|
||||
SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
|
||||
SIGPIPE, SIGQUIT, SIGSEGV,
|
||||
SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU,
|
||||
SIGUSR1, SIGUSR2, SIGPROF, SIGSYS,
|
||||
SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ };
|
||||
|
||||
if (sigismember(&set, sig) != 1) {
|
||||
return 1;
|
||||
}
|
||||
for (i=0; i<NUMSIGNALS; i++) {
|
||||
if ((siglist[i] != sig)) {
|
||||
if (sigismember(&set, siglist[i]) != 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
sigset_t actl, oactl;
|
||||
|
||||
sigemptyset(&actl);
|
||||
sigemptyset(&oactl);
|
||||
|
||||
sigaddset(&actl, SIGABRT);
|
||||
|
||||
sigprocmask(SIG_SETMASK, &actl, NULL);
|
||||
sigprocmask(SIG_UNBLOCK, NULL, &oactl);
|
||||
|
||||
if (is_changed(oactl, SIGABRT)) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("PASS: signal mask was not changed.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int handler_called = 0;
|
||||
int sigprocmask_return_val = 1; /* some value that's not a 1 or 0 */
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
handler_called = 1;
|
||||
if (sigprocmask_return_val != 1) {
|
||||
printf("FAIL: sigprocmask() returned before signal was delivered.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
struct sigaction act;
|
||||
sigset_t blocked_set1;
|
||||
sigemptyset(&blocked_set1);
|
||||
sigaddset(&blocked_set1, SIGABRT);
|
||||
|
||||
act.sa_handler = sig_handler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
if (sigaction(SIGABRT, &act, 0) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigprocmask(SIG_SETMASK, &blocked_set1, NULL) == -1) {
|
||||
perror("Unexpected error while attempting to use sigprocmask.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ((raise(SIGABRT) == -1)) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sigprocmask_return_val = sigprocmask(SIG_UNBLOCK, &blocked_set1, NULL);
|
||||
|
||||
if (sigprocmask_return_val != 0) {
|
||||
perror("Unexpected error while attempting to use sigprocmask.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (handler_called != 1) {
|
||||
perror("Handler wasn't called, implying signal was not delivered.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test PASSED: signal was delivered before the call to sigprocmask returned.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
|
||||
sigset_t set1, set2;
|
||||
int sigprocmask_return_val = 1;
|
||||
|
||||
sigemptyset(&set1);
|
||||
sigemptyset(&set2);
|
||||
sigaddset(&set1, SIGKILL);
|
||||
sigaddset(&set1, SIGSTOP);
|
||||
sigprocmask_return_val = sigprocmask(SIG_SETMASK, &set1, NULL);
|
||||
sigprocmask(SIG_SETMASK, NULL, &set2);
|
||||
|
||||
if (sigismember(&set2, SIGKILL)) {
|
||||
printf("FAIL: SIGKILL was added to the signal mask\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sigismember(&set2, SIGSTOP)) {
|
||||
printf("FAIL: SIGSTOP was added to the signal mask\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sigprocmask_return_val == -1) {
|
||||
printf("FAIL: sigprocmask returned -1. System should be able to enforce blocking un-ignorable signals without causing sigprocmask() to return -1.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int sigprocmask_block(int signum)
|
||||
{
|
||||
int defaultsig = SIGALRM;
|
||||
if (signum == SIGALRM) {
|
||||
defaultsig = SIGHUP;
|
||||
}
|
||||
struct sigaction act;
|
||||
sigset_t blocked_set1, blocked_set2, pending_set;
|
||||
sigemptyset(&blocked_set1);
|
||||
sigemptyset(&blocked_set2);
|
||||
sigaddset(&blocked_set1, signum);
|
||||
sigaddset(&blocked_set2, defaultsig);
|
||||
|
||||
act.sa_handler = sig_handler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
if (sigaction(signum, &act, 0) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
if (sigaction(defaultsig, &act, 0) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigprocmask(SIG_SETMASK, &blocked_set1, NULL) == -1) {
|
||||
perror("Unexpected error while attempting to use sigprocmask.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigprocmask(SIG_BLOCK, &blocked_set2, NULL) == -1) {
|
||||
perror("Unexpected error while attempting to use sigprocmask.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ((raise(signum) == -1) | (raise(defaultsig) == -1)) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (handler_called) {
|
||||
printf("FAIL: Signal was not blocked\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigpending(&pending_set) == -1) {
|
||||
perror("Unexpected error while attempting to use sigpending\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ((sigismember(&pending_set, signum) != 1) | (sigismember(&pending_set, defaultsig) != 1)) {
|
||||
perror("FAIL: sigismember did not return 1\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test PASSED: signal was added to the process's signal mask\n");
|
||||
act.sa_handler = SIG_IGN;
|
||||
sigaction(signum, &act, 0);
|
||||
sigaction(defaultsig, &act, 0);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
sigprocmask_block(i);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int sigprocmask_block(int signum)
|
||||
{
|
||||
int defaultsig = SIGALRM;
|
||||
(void) defaultsig;
|
||||
if (signum == SIGALRM) {
|
||||
defaultsig = SIGHUP;
|
||||
}
|
||||
struct sigaction act;
|
||||
sigset_t blocked_set, pending_set;
|
||||
sigemptyset(&blocked_set);
|
||||
sigaddset(&blocked_set, signum);
|
||||
|
||||
act.sa_handler = sig_handler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
if (sigaction(signum, &act, 0) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigprocmask(SIG_SETMASK, &blocked_set, NULL) == -1) {
|
||||
perror("Unexpected error while attempting to use sigprocmask.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (raise(signum) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (handler_called) {
|
||||
printf("FAIL: Signal was not blocked\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigpending(&pending_set) == -1) {
|
||||
perror("Unexpected error while attempting to use sigpending\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigismember(&pending_set, signum) != 1) {
|
||||
perror("FAIL: sigismember did not return 1\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Test PASSED: signal was added to the process's signal mask\n");
|
||||
act.sa_handler = SIG_IGN;
|
||||
sigaction(signum, &act, 0);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
sigprocmask_block(i);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
// The sigrelse() function shall remove sig from the signal mask of the calling process.
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
#define _XOPEN_SOURCE 700
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int sigrelse_test(int signum)
|
||||
{
|
||||
struct sigaction act;
|
||||
|
||||
act.sa_handler = sig_handler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
if (sigaction(signum, &act, 0) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sighold(signum);
|
||||
|
||||
if (raise(signum) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (handler_called) {
|
||||
printf("UNRESOLVED. possible problem in sigrelse\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigrelse(signum) == -1) {
|
||||
printf("UNRESOLVED. possible problem in sigrelse\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
if (handler_called) {
|
||||
printf("PASS: %d successfully removed from signal mask\n", signum);
|
||||
handler_called = 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
printf("FAIL\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
sigrelse_test(i);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#define _XOPEN_SOURCE 700
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
if ((int)sigrelse(SIGABRT) != 0) {
|
||||
perror("sigrelse failed -- returned -- test aborted");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("sigrelse passed\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#define _XOPEN_SOURCE 700
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
if ((int)sigrelse(100000) == -1) {
|
||||
|
||||
if (EINVAL == errno) {
|
||||
printf ("errno set to EINVAL\n");
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
printf ("errno not set to EINVAL\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
printf("SIGURG called. Inside handler\n");
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int sigset_test(int signum)
|
||||
{
|
||||
|
||||
struct sigaction act;
|
||||
act.sa_handler = sig_handler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
if (sigaction(signum, &act, 0) != 0) {
|
||||
perror("Unexpected error while using sigaction()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigset(signum,SIG_DFL) != sig_handler) {
|
||||
perror("Unexpected error while using signal()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
raise(signum);
|
||||
|
||||
if (handler_called == 1) {
|
||||
printf("Test FAILED: handler was called even though default was expected\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("test passed, the signal was ignored\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(){
|
||||
sigset_test(SIGURG);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
if (sigset(SIGKILL,SIG_IGN) == SIG_ERR) {
|
||||
if (errno != EINVAL) {
|
||||
printf("Test FAILED: sigset() returned SIG_ERR but didn't set errno to EINVAL\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
printf("Test FAILED: sigset() didn't return SIG_ERROR even though SIGKILL was passed to it\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("test passed: error was set successfully\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
printf("SIGUSR1 called. Inside handler\n");
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int sigset_test2(int signum)
|
||||
{
|
||||
struct sigaction act;
|
||||
act.sa_flags = 0;
|
||||
act.sa_handler = sig_handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
if (sigaction(signum, &act, 0) != 0) {
|
||||
perror("Unexpected error while using sigaction()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigset(signum,SIG_IGN) != sig_handler) {
|
||||
perror("Unexpected error while using signal()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
raise(signum);
|
||||
|
||||
if (handler_called == 1) {
|
||||
printf("Test FAILED: handler was called even though ignore was expected\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("test %d passed, the signal was ignored\n", signum);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
sigset_test2(i);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
// printf("SIGCHLD called. Inside handler\n");
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int sigset_test3(int signum)
|
||||
{
|
||||
if (sigset(signum, sig_handler) == SIG_ERR) {
|
||||
perror("Unexpected error while using sigset()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
raise(signum);
|
||||
|
||||
if (handler_called != 1) {
|
||||
printf("Test FAILED: handler wasn't called even though it was expected\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("test %d passed, handler was called\n", signum);
|
||||
handler_called = 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
sigset_test3(i);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
int signal_blocked = 0;
|
||||
int count = 1;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
// printf("SIGCHLD called. Inside handler\n");
|
||||
sigset_t mask;
|
||||
sigprocmask(SIG_SETMASK, NULL, &mask);
|
||||
if (count == SIGKILL || count == SIGSTOP){
|
||||
count++;
|
||||
}
|
||||
if(sigismember(&mask, count)) {
|
||||
signal_blocked = 1;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
int sigset_test4(int signum)
|
||||
{
|
||||
if (sigset(signum, sig_handler) == SIG_ERR) {
|
||||
perror("Unexpected error while using sigset()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
raise(signum);
|
||||
|
||||
if (signal_blocked != 1) {
|
||||
printf("Test FAILED: signal was not added to the mask before the handler was executed\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
signal_blocked = 0;
|
||||
printf("test %d passed: the singal was added to the mask before the handler was executed\n", signum);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
sigset_test4(i);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
#define NUMSIGNALS 26
|
||||
|
||||
int is_empty(sigset_t *set) {
|
||||
|
||||
int i;
|
||||
int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD,
|
||||
SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
|
||||
SIGPIPE, SIGQUIT, SIGSEGV,
|
||||
SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU,
|
||||
SIGUSR1, SIGUSR2, SIGPROF, SIGSYS,
|
||||
SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ };
|
||||
|
||||
for (i=0; i<NUMSIGNALS; i++) {
|
||||
if (sigismember(set, siglist[i]) != 0)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
printf("%d called. Inside handler\n", signo);
|
||||
}
|
||||
|
||||
int sigset_test5(int signum)
|
||||
{
|
||||
sigset_t mask;
|
||||
sigemptyset(&mask);
|
||||
|
||||
sigprocmask(SIG_SETMASK, &mask, NULL);
|
||||
|
||||
if (sigset(signum, sig_handler) == SIG_ERR) {
|
||||
perror("Unexpected error while using sigset()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
raise(signum);
|
||||
sigprocmask(SIG_SETMASK, NULL, &mask);
|
||||
|
||||
if (is_empty(&mask) != 1) {
|
||||
printf("Test FAILED: signal mask should be empty\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("sig %d was successfully removed from the mask when handler returned\n", signum);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
sigset_test5(i);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "signals_list.h"
|
||||
#include "../test_helpers.h"
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
(void) signo;
|
||||
printf("SIGUSR1 called. Inside handler\n");
|
||||
}
|
||||
|
||||
int sigset_test9(int signum)
|
||||
{
|
||||
struct sigaction act;
|
||||
act.sa_flags = 0;
|
||||
act.sa_handler = sig_handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
if (sigaction(signum, &act, 0) != 0) {
|
||||
perror("Unexpected error while using sigaction()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (sigset(signum,SIG_DFL) != sig_handler) {
|
||||
printf("Test FAILED: sigset didn't return myhandler even though it was SIGUSR1's original disposition\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("test %d passed \n", signum);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(){
|
||||
for (int i=1; i<N_SIGNALS; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP){
|
||||
continue;
|
||||
}
|
||||
sigset_test9(i);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user