Skip to content

Commit

Permalink
Merge pull request #1 from jonyesno/freebsd
Browse files Browse the repository at this point in the history
Add FreeBSD support
  • Loading branch information
robn authored Dec 5, 2022
2 parents 19bfb52 + 95088bd commit 7d65df5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pact.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
#ifdef __linux__
#include <sys/prctl.h>
#elif __FreeBSD__
#include <sys/procctl.h>
#endif
#include <sys/signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>

int do_ctl(int signo) {
#ifdef __linux__
return prctl(PR_SET_PDEATHSIG, signo, 0, 0, 0);
#elif __FreeBSD__
return procctl(P_PID, 0, PROC_PDEATHSIG_CTL, &signo);
#else
# no platform support
return -1
#endif
}

int main(int argc, char **argv) {
if(argc < 2)
return 1;
Expand All @@ -16,8 +32,8 @@ int main(int argc, char **argv) {
cmd = 2;
}
if (!signo)
signo = 15;
if (prctl(PR_SET_PDEATHSIG, signo, 0, 0, 0) < 0) {
signo = SIGTERM;
if (do_ctl(signo) < 0) {
perror("prctl");
return 1;
}
Expand Down

0 comments on commit 7d65df5

Please sign in to comment.