jehanne: fix kill and signal trampoline
The function __newlib_kill is a kludge to avoid type conflicts.
This commit is contained in:
parent
76d7e7039c
commit
a5c4fadacf
|
@ -77,11 +77,14 @@ struct Dir {
|
|||
#define ORCLOSE 0x10 /* or'ed in, remove on close */
|
||||
#define OTRUNC 0x0100 /* or'ed in (except for exec), truncate file first */
|
||||
|
||||
extern void jehanne_sysfatal(const char*, ...);
|
||||
|
||||
#include <posix.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/signal.h>
|
||||
#define __CYGWIN__ /* needed for O_ACCMODE */
|
||||
#include <fcntl.h>
|
||||
#undef __CYGWIN__
|
||||
|
@ -104,6 +107,95 @@ __stat_reader(struct stat *s, const Dir *d)
|
|||
return 0;
|
||||
}
|
||||
|
||||
PosixSignalDisposition
|
||||
default_signal_disposition(int signal)
|
||||
{
|
||||
// see http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html
|
||||
switch(signal){
|
||||
default:
|
||||
return TerminateTheProcess;
|
||||
|
||||
case SIGABRT:
|
||||
return TerminateTheProcessAndCoreDump;
|
||||
case SIGALRM:
|
||||
return TerminateTheProcess;
|
||||
case SIGBUS:
|
||||
return TerminateTheProcessAndCoreDump;
|
||||
case SIGCHLD:
|
||||
return SignalHandled;
|
||||
case SIGCONT:
|
||||
return ResumeTheProcess;
|
||||
case SIGFPE:
|
||||
return TerminateTheProcessAndCoreDump;
|
||||
case SIGHUP:
|
||||
return TerminateTheProcess;
|
||||
case SIGILL:
|
||||
return TerminateTheProcessAndCoreDump;
|
||||
case SIGINT:
|
||||
return TerminateTheProcess;
|
||||
case SIGKILL:
|
||||
return TerminateTheProcess;
|
||||
case SIGPIPE:
|
||||
return TerminateTheProcess;
|
||||
case SIGQUIT:
|
||||
return TerminateTheProcessAndCoreDump;
|
||||
case SIGSEGV:
|
||||
return TerminateTheProcessAndCoreDump;
|
||||
case SIGSTOP:
|
||||
return StopTheProcess;
|
||||
case SIGTERM:
|
||||
return TerminateTheProcess;
|
||||
case SIGTSTP:
|
||||
return StopTheProcess;
|
||||
case SIGTTIN:
|
||||
return StopTheProcess;
|
||||
case SIGTTOU:
|
||||
return StopTheProcess;
|
||||
case SIGUSR1:
|
||||
return TerminateTheProcess;
|
||||
case SIGUSR2:
|
||||
return TerminateTheProcess;
|
||||
case SIGPOLL:
|
||||
return TerminateTheProcess;
|
||||
case SIGPROF:
|
||||
return TerminateTheProcess;
|
||||
case SIGSYS:
|
||||
return TerminateTheProcessAndCoreDump;
|
||||
case SIGTRAP:
|
||||
return TerminateTheProcessAndCoreDump;
|
||||
case SIGURG:
|
||||
return SignalHandled;
|
||||
case SIGVTALRM:
|
||||
return TerminateTheProcess;
|
||||
case SIGXCPU:
|
||||
return TerminateTheProcessAndCoreDump;
|
||||
case SIGXFSZ:
|
||||
return TerminateTheProcessAndCoreDump;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
__newlib_kill(int *errnop, int pid, int sig,
|
||||
int (*killer)(int *errnop, int pid, int sig),
|
||||
int (*disposer)(int sig, PosixSignalDisposition action, int pid))
|
||||
{
|
||||
switch(sig){
|
||||
default:
|
||||
return killer(errnop, pid, sig);
|
||||
|
||||
/* control signals follow */
|
||||
case SIGKILL:
|
||||
return disposer(sig, TerminateTheProcess, pid);
|
||||
case SIGSTOP:
|
||||
case SIGTSTP:
|
||||
case SIGTTIN:
|
||||
case SIGTTOU:
|
||||
return disposer(sig, StopTheProcess, pid);
|
||||
case SIGCONT:
|
||||
return disposer(sig, ResumeTheProcess, pid);
|
||||
}
|
||||
}
|
||||
|
||||
static PosixError
|
||||
stat_reader(void *statp, const Dir *dir)
|
||||
{
|
||||
|
@ -158,10 +250,22 @@ default_error_translator(char* error, uintptr_t caller)
|
|||
return PosixEINVAL;
|
||||
}
|
||||
|
||||
static int
|
||||
static PosixSignalDisposition
|
||||
signal_trampoline(int signal)
|
||||
{
|
||||
return __sigtramp(signal) != -1;
|
||||
switch(__sigtramp(signal)){
|
||||
case -1: // unknown signal or uninitialized signals
|
||||
jehanne_sysfatal("newlib: error handling signal %d or unknown signal", signal);
|
||||
case 0: // handle
|
||||
case 3: // ignore
|
||||
return SignalHandled;
|
||||
case 1: // default
|
||||
return default_signal_disposition(signal);
|
||||
case 2: // error
|
||||
return TerminateTheProcessAndCoreDump;
|
||||
default:
|
||||
jehanne_sysfatal("newlib: unexpected disposition from signal trampoline");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -105,8 +105,11 @@ _isatty_r(struct _reent *r, int file)
|
|||
int
|
||||
_kill_r(struct _reent *r, int pid, int sig)
|
||||
{
|
||||
extern int __newlib_kill(int *errnop, int pid, int sig,
|
||||
int (*killer)(int *errnop, int pid, int sig),
|
||||
int (*disposer)(int sig, PosixSignalDisposition action, int pid));
|
||||
int *errnop = &r->_errno;
|
||||
return POSIX_kill(errnop, pid, sig);
|
||||
return __newlib_kill(errnop, pid, sig, POSIX_kill, POSIX_signal_execute);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Reference in New Issue