Welcome to The Fiwix Project
A UNIX-like kernel for the i386 architecture
1 /* 2 * fiwix/kernel/syscalls/sigaction.c 3 * 4 * Copyright 2018, Jordi Sanfeliu. All rights reserved. 5 * Distributed under the terms of the Fiwix License. 6 */ 7 8 #include <fiwix/fs.h> 9 #include <fiwix/signal.h> 10 #include <fiwix/errno.h> 11 12 #ifdef __DEBUG__ 13 #include <fiwix/stdio.h> 14 #include <fiwix/process.h> 15 #endif /*__DEBUG__ */ 16 17 int sys_sigaction(__sigset_t signum, const struct sigaction *newaction, struct sigaction *oldaction) 18 { 19 int errno; 20 21 #ifdef __DEBUG__ 22 printk("(pid %d) sys_sigaction(%d, 0x%08x, 0x%08x)\n", current->pid, signum, (unsigned int)newaction, (unsigned int)oldaction); 23 #endif /*__DEBUG__ */ 24 25 if(signum < 1 || signum > NSIG) { 26 return -EINVAL; 27 } 28 if(signum == SIGKILL || signum == SIGSTOP) { 29 return -EINVAL; 30 } 31 if(oldaction) { 32 if((errno = check_user_area(VERIFY_WRITE, oldaction, sizeof(struct sigaction)))) { 33 return errno; 34 } 35 *oldaction = current->sigaction[signum - 1]; 36 } 37 if(newaction) { 38 if((errno = check_user_area(VERIFY_READ, newaction, sizeof(struct sigaction)))) { 39 return errno; 40 } 41 current->sigaction[signum - 1] = *newaction; 42 if(current->sigaction[signum - 1].sa_handler == SIG_IGN) { 43 if(signum != SIGCHLD) { 44 current->sigpending &= SIG_MASK(signum); 45 } 46 } 47 if(current->sigaction[signum - 1].sa_handler == SIG_DFL) { 48 if(signum != SIGCHLD) { 49 current->sigpending &= SIG_MASK(signum); 50 } 51 } 52 } 53 return 0; 54 }