From f0dd9c9ddb4ab5ebc8f0dd1ba1e1b65dd843b4d6 Mon Sep 17 00:00:00 2001
From: Alex Shinn <ashinn@users.noreply.github.com>
Date: Thu, 26 Jul 2012 09:55:00 +0900
Subject: [PATCH] patch for clean NetBSD and OpenBSD builds from v krishnakumar

---
 Makefile.detect    | 15 +++++++++++++++
 lib/chibi/signal.c |  6 +++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/Makefile.detect b/Makefile.detect
index eb47c99e..00236460 100644
--- a/Makefile.detect
+++ b/Makefile.detect
@@ -10,6 +10,12 @@ else
 ifeq ($(shell uname),FreeBSD)
 PLATFORM=bsd
 else
+ifeq ($(shell uname),NetBSD)
+PLATFORM=bsd
+else
+ifeq ($(shell uname),OpenBSD)
+PLATFORM=bsd
+else
 ifeq ($(shell uname),DragonFly)
 PLATFORM=bsd
 else
@@ -33,6 +39,8 @@ endif
 endif
 endif
 endif
+endif
+endif
 
 ########################################################################
 # Set default variables for the platform.
@@ -45,6 +53,12 @@ EXE =
 CLIBFLAGS = -dynamiclib
 STATICFLAGS = -static-libgcc -DSEXP_USE_DL=0
 else
+ifeq ($(PLATFORM),bsd)
+SO  = .so
+EXE =
+CLIBFLAGS = -fPIC -shared
+LIBDL = 
+else
 ifeq ($(PLATFORM),mingw)
 SO  = .dll
 EXE = .exe
@@ -75,6 +89,7 @@ endif
 endif
 endif
 endif
+endif
 
 ifeq ($(PLATFORM),unix)
 #RLDFLAGS=-rpath $(LIBDIR)
diff --git a/lib/chibi/signal.c b/lib/chibi/signal.c
index 379728fa..c82cf16b 100644
--- a/lib/chibi/signal.c
+++ b/lib/chibi/signal.c
@@ -62,6 +62,8 @@ static sexp sexp_set_signal_action (sexp ctx, sexp self, sexp signum, sexp newac
 
 #include <sys/time.h>
 #ifndef __DragonFly__
+#include <sys/param.h>
+#include <sys/sysctl.h>
 #include <sys/proc.h>
 #endif
 #include <sys/sysctl.h>
@@ -72,8 +74,10 @@ static sexp sexp_pid_cmdline (sexp ctx, int pid) {
   struct kinfo_proc res;
   int name[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
   if (sysctl(name, 4, &res, &reslen, NULL, 0) >= 0) {
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__NetBSD__)
     return sexp_c_string(ctx, res.kp_proc.p_comm, -1);
+#elif __OpenBSD__
+    return sexp_c_string(ctx, res.p_comm, -1);
 #elif __DragonFly__
     return sexp_c_string(ctx, res.kp_comm, -1);
 #else