| 1 | #include "beos/beosish.h"
|
|---|
| 2 |
|
|---|
| 3 | #undef waitpid
|
|---|
| 4 | #undef kill
|
|---|
| 5 | #undef sigaction
|
|---|
| 6 |
|
|---|
| 7 | #include <errno.h>
|
|---|
| 8 | #include <signal.h>
|
|---|
| 9 | #include <stdio.h>
|
|---|
| 10 | #include <stdlib.h>
|
|---|
| 11 | #include <unistd.h>
|
|---|
| 12 | #include <sys/wait.h>
|
|---|
| 13 |
|
|---|
| 14 | #include <OS.h>
|
|---|
| 15 |
|
|---|
| 16 | /* In BeOS 5.0 the waitpid() seems to misbehave in that the status
|
|---|
| 17 | * has the upper and lower bytes swapped compared with the usual
|
|---|
| 18 | * POSIX/UNIX implementations. To undo the surpise effect to the
|
|---|
| 19 | * rest of Perl we need this wrapper. (The rest of BeOS might be
|
|---|
| 20 | * surprised because of this, though.) */
|
|---|
| 21 |
|
|---|
| 22 | pid_t beos_waitpid(pid_t process_id, int *status_location, int options) {
|
|---|
| 23 | pid_t got = waitpid(process_id, status_location, options);
|
|---|
| 24 | if (status_location)
|
|---|
| 25 | *status_location =
|
|---|
| 26 | (*status_location & 0x00FF) << 8 |
|
|---|
| 27 | (*status_location & 0xFF00) >> 8;
|
|---|
| 28 | return got;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | /* BeOS kill() doesn't like the combination of the pseudo-signal 0 and
|
|---|
| 33 | * specifying a process group (i.e. pid < -1 || pid == 0). We work around
|
|---|
| 34 | * by changing pid to the respective process group leader. That should work
|
|---|
| 35 | * well enough in most cases. */
|
|---|
| 36 |
|
|---|
| 37 | int beos_kill(pid_t pid, int sig)
|
|---|
| 38 | {
|
|---|
| 39 | if (sig == 0) {
|
|---|
| 40 | if (pid == 0) {
|
|---|
| 41 | /* it's our process group */
|
|---|
| 42 | pid = getpgrp();
|
|---|
| 43 | } else if (pid < -1) {
|
|---|
| 44 | /* just address the process group leader */
|
|---|
| 45 | pid = -pid;
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | return kill(pid, sig);
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | /* sigaction() should fail, if trying to ignore or install a signal handler
|
|---|
| 53 | * for a signal that cannot be caught or ignored. The BeOS R5 sigaction()
|
|---|
| 54 | * doesn't return an error, though. */
|
|---|
| 55 | int beos_sigaction(int sig, const struct sigaction *act,
|
|---|
| 56 | struct sigaction *oact)
|
|---|
| 57 | {
|
|---|
| 58 | int result = sigaction(sig, act, oact);
|
|---|
| 59 |
|
|---|
| 60 | if (result == 0 && act && act->sa_handler != SIG_DFL
|
|---|
| 61 | && act->sa_handler != SIG_ERR && (sig == SIGKILL || sig == SIGSTOP)) {
|
|---|
| 62 | result = -1;
|
|---|
| 63 | errno = EINVAL;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | return result;
|
|---|
| 67 | }
|
|---|