Chromium Code Reviews| Index: native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc |
| diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc |
| index 1a0542c12d62f23628ee7add15ff3fe39c094aab..2fd43ebaf8ee67fc64e49c886c1d57f9a3c8e33b 100644 |
| --- a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc |
| +++ b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc |
| @@ -14,10 +14,12 @@ |
| #include <stdio.h> |
| #include <string.h> |
| #include <sys/time.h> |
| +#include <unistd.h> |
| #include <iterator> |
| #include <string> |
| +#include "nacl_io/dbgprint.h" |
| #include "nacl_io/host_resolver.h" |
| #include "nacl_io/kernel_handle.h" |
| #include "nacl_io/kernel_wrap_real.h" |
| @@ -45,7 +47,8 @@ |
| namespace nacl_io { |
| -KernelProxy::KernelProxy() : dev_(0), ppapi_(NULL) { |
| +KernelProxy::KernelProxy() : dev_(0), ppapi_(NULL), |
| + sigwinch_handler_(SIG_IGN) { |
| } |
| KernelProxy::~KernelProxy() { |
| @@ -710,6 +713,75 @@ int KernelProxy::tcsetattr(int fd, int optional_actions, |
| return 0; |
| } |
| +int KernelProxy::kill(pid_t pid, int sig) { |
| + // Currently we don't even pretend that other processes exist |
| + // so we can only send a signal to outselves. For kill(2) |
| + // pid 0 means the current process group and -1 means all the |
| + // processes we have permission to send signals to. |
| + if (pid != getpid() && pid != -1 && pid != 0) { |
| + errno = ESRCH; |
| + return -1; |
| + } |
| + |
| + switch (sig) { |
|
binji
2013/08/21 17:42:01
is there danger in calling default handlers if the
Sam Clegg
2013/08/22 03:32:45
I'm not sure what you mean.
binji
2013/08/22 18:09:36
I just mean, if we had a generic SignalHandler cla
|
| + case SIGWINCH: |
| + //dbgprintf("kill SIGWINCH handler=%p\n", sigwinch_handler_); |
| + if (sigwinch_handler_ != SIG_IGN) |
| + sigwinch_handler_(SIGWINCH); |
| + break; |
| + |
| + case SIGUSR1: |
| + case SIGUSR2: |
| + break; |
| + |
| + default: |
| + errno = EINVAL; |
| + return -1; |
| + } |
| + |
| + return 0; |
| +} |
| + |
| +sighandler_t KernelProxy::signal(int signum, sighandler_t handler) { |
| + return sigset(signum, handler); |
|
binji
2013/08/21 17:42:01
if sigset and signal are identical, I'd rather see
Sam Clegg
2013/08/22 03:32:45
They are not quite identical. But the differences
|
| +} |
| + |
| +sighandler_t KernelProxy::sigset(int signum, sighandler_t handler) { |
| + switch (signum) { |
| + // Handled signals. |
| + case SIGWINCH: { |
| + sighandler_t old_value = sigwinch_handler_; |
|
binji
2013/08/21 17:42:01
I know you're only handling SIGWINCH, but you migh
Sam Clegg
2013/08/22 03:32:45
KILL and STOP can never be handled, aside from tha
|
| + if (handler == SIG_DFL) |
| + handler = SIG_IGN; |
| + //dbgprintf("registering handler: %p\n", handler); |
|
binji
2013/08/21 17:42:01
remove
Sam Clegg
2013/08/22 03:32:45
Done.
|
| + sigwinch_handler_ = handler; |
| + return old_value; |
| + } |
| + |
| + // Known signals |
| + case SIGHUP: |
| + case SIGINT: |
| + case SIGKILL: |
| + case SIGPIPE: |
| + case SIGPOLL: |
| + case SIGPROF: |
| + case SIGTERM: |
| + case SIGCHLD: |
| + case SIGURG: |
| + case SIGFPE: |
| + case SIGILL: |
| + case SIGQUIT: |
| + case SIGSEGV: |
| + case SIGTRAP: |
| + if (handler == SIG_DFL) |
| + return SIG_DFL; |
| + break; |
| + } |
| + |
| + errno = EINVAL; |
| + return SIG_ERR; |
| +} |
| + |
| #ifdef PROVIDES_SOCKET_API |
| int KernelProxy::select(int nfds, fd_set* readfds, fd_set* writefds, |