Pārlūkot izejas kodu

Implement signal() via sigaction() and get rid of sys$signal().

Andreas Kling 6 gadi atpakaļ
vecāks
revīzija
464a16afa2
5 mainītis faili ar 9 papildinājumiem un 19 dzēšanām
  1. 0 9
      Kernel/Process.cpp
  2. 0 1
      Kernel/Process.h
  3. 0 2
      Kernel/Syscall.cpp
  4. 0 1
      Kernel/Syscall.h
  5. 9 6
      LibC/signal.cpp

+ 0 - 9
Kernel/Process.cpp

@@ -1660,15 +1660,6 @@ int Process::sys$dup2(int old_fd, int new_fd)
     return new_fd;
 }
 
-Unix::sighandler_t Process::sys$signal(int signum, Unix::sighandler_t handler)
-{
-    // FIXME: Fail with -EINVAL if attepmting to catch or ignore SIGKILL or SIGSTOP.
-    if (signum < 1 || signum >= 32)
-        return (Unix::sighandler_t)-EINVAL;
-    dbgprintf("sys$signal: %d => L%x\n", signum, handler);
-    return nullptr;
-}
-
 int Process::sys$sigprocmask(int how, const Unix::sigset_t* set, Unix::sigset_t* old_set)
 {
     if (old_set) {

+ 0 - 1
Kernel/Process.h

@@ -154,7 +154,6 @@ public:
     int sys$ttyname_r(int fd, char*, size_t);
     pid_t sys$fork(RegisterDump&);
     int sys$execve(const char* filename, const char** argv, const char** envp);
-    Unix::sighandler_t sys$signal(int signum, Unix::sighandler_t);
     int sys$isatty(int fd);
     int sys$getdtablesize();
     int sys$dup(int oldfd);

+ 0 - 2
Kernel/Syscall.cpp

@@ -133,8 +133,6 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2,
         return current->sys$geteuid();
     case Syscall::SC_getegid:
         return current->sys$getegid();
-    case Syscall::SC_signal:
-        return (dword)current->sys$signal((int)arg1, (Unix::sighandler_t)arg2);
     case Syscall::SC_isatty:
         return current->sys$isatty((int)arg1);
     case Syscall::SC_getdtablesize:

+ 0 - 1
Kernel/Syscall.h

@@ -41,7 +41,6 @@
     __ENUMERATE_SYSCALL(execve) \
     __ENUMERATE_SYSCALL(geteuid) \
     __ENUMERATE_SYSCALL(getegid) \
-    __ENUMERATE_SYSCALL(signal) \
     __ENUMERATE_SYSCALL(isatty) \
     __ENUMERATE_SYSCALL(getdtablesize) \
     __ENUMERATE_SYSCALL(dup) \

+ 9 - 6
LibC/signal.cpp

@@ -20,13 +20,16 @@ int killpg(int pgrp, int sig)
 
 sighandler_t signal(int signum, sighandler_t handler)
 {
-    sighandler_t old_handler = (sighandler_t)Syscall::invoke(Syscall::SC_signal, (dword)signum, (dword)handler);
-    if (old_handler == SIG_ERR) {
-        errno = EINVAL;
+    struct sigaction new_act;
+    struct sigaction old_act;
+    new_act.sa_handler = handler;
+    new_act.sa_flags = 0;
+    new_act.sa_mask = 0;
+    new_act.sa_restorer = nullptr;
+    int rc = sigaction(signum, &new_act, &old_act);
+    if (rc < 0)
         return SIG_ERR;
-    }
-    errno = 0;
-    return old_handler;
+    return old_act.sa_handler;
 }
 
 int sigaction(int signum, const struct sigaction* act, struct sigaction* old_act)