summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Jones <thj@freebsd.org>2024-02-08 14:55:36 +0000
committerDamjan Marion <dmarion@0xa5.net>2024-04-24 12:30:01 +0000
commit154e19c09a914ef715080104a5e80e7bde3c70c3 (patch)
tree377291e701ae4c7544f34a76751af80804455e7b
parentabd6a7b2b560ea370b5561f53ec3a243910ae4fe (diff)
fateshare: Add FreeBSD specific API for controlling processes
Type: improvement Change-Id: I7ea8b5505a2663d6751208f0001e4b9ba2deb150 Signed-off-by: Tom Jones <thj@freebsd.org>
-rw-r--r--src/plugins/fateshare/fateshare.c15
-rw-r--r--src/plugins/fateshare/vpp_fateshare_monitor.c28
2 files changed, 43 insertions, 0 deletions
diff --git a/src/plugins/fateshare/fateshare.c b/src/plugins/fateshare/fateshare.c
index 37cd0300ab7..971d32303db 100644
--- a/src/plugins/fateshare/fateshare.c
+++ b/src/plugins/fateshare/fateshare.c
@@ -27,7 +27,11 @@
#include <sys/types.h>
#include <sys/wait.h>
+#ifdef __linux__
#include <sys/prctl.h> // prctl(), PR_SET_PDEATHSIG
+#else
+#include <sys/procctl.h>
+#endif /* __linux__ */
#include <limits.h>
fateshare_main_t fateshare_main;
@@ -87,12 +91,23 @@ launch_monitor (fateshare_main_t *kmp)
{
dup2 (logfd, 1);
dup2 (logfd, 2);
+#ifdef __linux__
int r = prctl (PR_SET_PDEATHSIG, SIGTERM);
if (r == -1)
{
perror (0);
exit (1);
}
+#else
+ int r, s = SIGTERM;
+
+ r = procctl (P_PID, 0, PROC_PDEATHSIG_CTL, &s);
+ if (r == -1)
+ {
+ perror (0);
+ exit (1);
+ }
+#endif /* __linux__ */
pid_t current_ppid = getppid ();
if (current_ppid != ppid_before_fork)
{
diff --git a/src/plugins/fateshare/vpp_fateshare_monitor.c b/src/plugins/fateshare/vpp_fateshare_monitor.c
index 7b203884c4e..7af451ccffe 100644
--- a/src/plugins/fateshare/vpp_fateshare_monitor.c
+++ b/src/plugins/fateshare/vpp_fateshare_monitor.c
@@ -4,7 +4,12 @@
#include <sys/types.h>
#include <sys/wait.h>
+#ifdef __linux__
#include <sys/prctl.h> // prctl(), PR_SET_PDEATHSIG
+#else
+#include <signal.h>
+#include <sys/procctl.h>
+#endif /* __linux__ */
#include <sys/stat.h>
#include <fcntl.h>
@@ -82,6 +87,7 @@ launch_command (char *scmd, char *logname_base)
}
/* child */
+#ifdef __linux__
int r = prctl (PR_SET_PDEATHSIG, SIGTERM);
if (r == -1)
{
@@ -89,6 +95,17 @@ launch_command (char *scmd, char *logname_base)
sleep (5);
exit (1);
}
+#else
+ int r, s = SIGTERM;
+
+ r = procctl (P_PID, 0, PROC_PDEATHSIG_CTL, &s);
+ if (r == -1)
+ {
+ perror ("procctl");
+ exit (1);
+ }
+#endif /* __linux__ */
+
if (getppid () != ppid_before_fork)
{
sleep (5);
@@ -180,12 +197,23 @@ main (int argc, char **argv)
exit (2);
}
+#ifdef __linux__
int r = prctl (PR_SET_PDEATHSIG, SIGTERM);
if (r == -1)
{
perror (0);
exit (1);
}
+#else
+ int r, s = SIGTERM;
+
+ r = procctl (P_PID, 0, PROC_PDEATHSIG_CTL, &s);
+ if (r == -1)
+ {
+ perror ("procctl");
+ exit (1);
+ }
+#endif /* __linux__ */
/* Establish handler. */
struct sigaction sa;