Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Do not fork pkg is we are being ptraced (FreeBSD only)
Baptiste Daroussin committed 9 years ago
commit 22dcc18a34e689be52b3e07818e2b893efcc03c0
parent 5bfb790
1 file changed +30 -1
modified src/main.c
@@ -40,6 +40,11 @@
#include <sys/sbuf.h>
#include <sys/types.h>
#include <sys/wait.h>
+
#ifdef __FreeBSD__
+
#include <sys/sysctl.h>
+
#include <sys/user.h>
+
#include <sys/proc.h>
+
#endif

#include <assert.h>
#include <ctype.h>
@@ -553,6 +558,30 @@ expand_aliases(int argc, char ***argv)
	return (newargc);
}

+
static
+
bool ptraced(void)
+
{
+
#if defined(__FreeBSD__)
+
	int                 mib[4];
+
	struct kinfo_proc   info;
+
	size_t              size;
+

+
	info.ki_flag = 0;
+

+
	mib[0] = CTL_KERN;
+
	mib[1] = KERN_PROC;
+
	mib[2] = KERN_PROC_PID;
+
	mib[3] = getpid();
+

+
	size = sizeof(info);
+
	sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
+

+
	return ((info.ki_flag & P_TRACED) != 0 );
+
#else
+
	return (true);
+
#endif
+
}
+

int
main(int argc, char **argv)
{
@@ -690,7 +719,7 @@ main(int argc, char **argv)
	optreset = 1;
	optind = 1;

-
	if (debug == 0 && version == 0)
+
	if (debug == 0 && version == 0 && !ptraced())
		start_process_worker(save_argv);

#ifdef HAVE_ARC4RANDOM_STIR