X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=beos%2Fbeos.c;h=755ce993c86a8525db3e6d8693e39cb5bbb9ca7a;hb=98225a64488c895097b3ce3f7ac9c94f464be86b;hp=7e799caf54662539e7e88e009cba4dad37db1fbb;hpb=dff18f87b95b47b2b3dc9fa1769bd282a2d85916;p=p5sagit%2Fp5-mst-13.2.git diff --git a/beos/beos.c b/beos/beos.c index 7e799ca..755ce99 100644 --- a/beos/beos.c +++ b/beos/beos.c @@ -1,9 +1,18 @@ #include "beos/beosish.h" #undef waitpid +#undef kill +#undef sigaction +#include +#include +#include +#include +#include #include +#include + /* In BeOS 5.0 the waitpid() seems to misbehave in that the status * has the upper and lower bytes swapped compared with the usual * POSIX/UNIX implementations. To undo the surpise effect to the @@ -18,3 +27,41 @@ pid_t beos_waitpid(pid_t process_id, int *status_location, int options) { (*status_location & 0xFF00) >> 8; return got; } + + +/* BeOS kill() doesn't like the combination of the pseudo-signal 0 and + * specifying a process group (i.e. pid < -1 || pid == 0). We work around + * by changing pid to the respective process group leader. That should work + * well enough in most cases. */ + +int beos_kill(pid_t pid, int sig) +{ + if (sig == 0) { + if (pid == 0) { + /* it's our process group */ + pid = getpgrp(); + } else if (pid < -1) { + /* just address the process group leader */ + pid = -pid; + } + } + + return kill(pid, sig); +} + +/* sigaction() should fail, if trying to ignore or install a signal handler + * for a signal that cannot be caught or ignored. The BeOS R5 sigaction() + * doesn't return an error, though. */ +int beos_sigaction(int sig, const struct sigaction *act, + struct sigaction *oact) +{ + int result = sigaction(sig, act, oact); + + if (result == 0 && act && act->sa_handler != SIG_DFL + && act->sa_handler != SIG_ERR && (sig == SIGKILL || sig == SIGSTOP)) { + result = -1; + errno = EINVAL; + } + + return result; +}