Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

OpenBSD support, EPROTO question #71

Closed
jirib opened this Issue Feb 12, 2016 · 3 comments

Comments

Projects
None yet
3 participants

jirib commented Feb 12, 2016

Hi,

I'm not really a developer so I'm asking before pull request? How to handle in better way EPROTO? It seems odd to have ifndef in couple of files?

(Otherwise with diffs below I could build pcp on OpenBSD. Just build, I have to learn how to use it :) )

diff --git a/configure b/configure
index 1ffeaa6..dbd1179 100755
--- a/configure
+++ b/configure
@@ -3099,6 +3099,15 @@ $as_echo "#define IS_NETBSD 1" >>confdefs.h
     export CFLAGS="-fPIC -fno-strict-aliasing -D_GNU_SOURCE -D_NETBSD_SOURCE"
     pcp_platform_paths='/usr/pkg/bin'
     pcp_ps_all_flags=auxww
+elif test $target_os = openbsd
+then
+    target_os=openbsd
+
+$as_echo "#define IS_OPENBSD 1" >>confdefs.h
+
+    export CFLAGS="-fPIC -fno-strict-aliasing -D_GNU_SOURCE"
+    pcp_platform_paths='/usr/local/bin'
+    pcp_ps_all_flags=auxww
 else
     echo
     echo "FATAL ERROR: need platform-specific customization for \"$target_os\""
diff --git a/configure.ac b/configure.ac
index ac47d8b..91f7cfd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -310,6 +310,13 @@ then
     export CFLAGS="-fPIC -fno-strict-aliasing -D_GNU_SOURCE -D_NETBSD_SOURCE"
     pcp_platform_paths='/usr/pkg/bin'
     pcp_ps_all_flags=auxww
+elif test $target_os = openbsd
+then
+    target_os=openbsd
+    AC_DEFINE(IS_OPENBSD, [1], [Platform is OpenBSD])
+    export CFLAGS="-fPIC -fno-strict-aliasing -D_GNU_SOURCE"
+    pcp_platform_paths='/usr/local/bin'
+    pcp_ps_all_flags=auxww
 else
     echo
     echo "FATAL ERROR: need platform-specific customization for \"$target_os\""
diff --git a/src/include/buildrules b/src/include/buildrules
index f4b552e..a92036c 100644
--- a/src/include/buildrules
+++ b/src/include/buildrules
@@ -40,7 +40,7 @@ endif
 .SUFFIXES: .cxx

 ifdef LIBTARGET
-ifneq (, $(filter linux freebsd kfreebsd netbsd mingw gnu, $(TARGET_OS)))
+ifneq (, $(filter linux freebsd kfreebsd netbsd openbsd mingw gnu, $(TARGET_OS)))
 _SHAREDOPTS    = -shared -Wl,-soname,$(LIBTARGET)
 endif
 ifeq ($(TARGET_OS), solaris)
diff --git a/src/include/pcp/config.h.in b/src/include/pcp/config.h.in
index 392a761..8964c2d 100644
--- a/src/include/pcp/config.h.in
+++ b/src/include/pcp/config.h.in
@@ -539,6 +539,9 @@ typedef void (*SIG_PF) (int);
 /* Determine if we are on a NetBSD box */
 #undef IS_NETBSD

+/* Determine if we are on a OpenBSD box */
+#undef IS_OPENBSD
+
 /* Determine if we are on a Mac OS X box */
 #undef IS_DARWIN
 #ifdef IS_DARWIN
diff --git a/src/include/pcp/impl.h b/src/include/pcp/impl.h
index ba781a3..369056b 100644
--- a/src/include/pcp/impl.h
+++ b/src/include/pcp/impl.h
@@ -39,6 +39,9 @@
 #ifdef HAVE_NETDB_H
 #include <netdb.h>
 #endif
+#if defined(IS_OPENBSD)
+#include <sys/select.h>
+#endif

 /*
  * Thread-safe support ... #define to enable thread-safe protection of
diff --git a/src/libpcp/src/auxserver.c b/src/libpcp/src/auxserver.c
index b7f75b1..892a33b 100644
--- a/src/libpcp/src/auxserver.c
+++ b/src/libpcp/src/auxserver.c
@@ -22,6 +22,11 @@
 #include <ucred.h>
 #endif

+/* OpenBSD doesn't have EPROTO */
+#ifndef EPROTO
+#define EPROTO EINTR
+#endif
+
 #define STRINGIFY(s)   #s
 #define TO_STRING(s)   STRINGIFY(s)

diff --git a/src/libpcp/src/pdubuf.c b/src/libpcp/src/pdubuf.c
index b222bf8..99fb3be 100644
--- a/src/libpcp/src/pdubuf.c
+++ b/src/libpcp/src/pdubuf.c
@@ -25,6 +25,10 @@
 #include <assert.h>
 #include <search.h>

+#ifdef IS_OPENBSD
+#include <sys/stdint.h>
+#endif
+
 typedef struct bufctl
 {
     int        bc_pincnt;
diff --git a/src/libpcp/src/util.c b/src/libpcp/src/util.c
index 039969a..64002e0 100644
--- a/src/libpcp/src/util.c
+++ b/src/libpcp/src/util.c
@@ -2138,7 +2138,7 @@ __pmProcessExists(pid_t pid)
        return 0;
     return (len > 0);
 }
-#elif defined(IS_FREEBSD)
+#elif defined(IS_FREEBSD) || defined(IS_OPENBSD)
 int 
 __pmProcessExists(pid_t pid)
 {
diff --git a/src/libpcp_gui/src/timeclient.c b/src/libpcp_gui/src/timeclient.c
index 1046e3f..0c101f7 100644
--- a/src/libpcp_gui/src/timeclient.c
+++ b/src/libpcp_gui/src/timeclient.c
@@ -16,6 +16,11 @@
 #include "impl.h"
 #include "pmtime.h"

+/* OpenBSD doesn't have EPROTO */
+#ifndef EPROTO
+#define EPROTO EINTR
+#endif
+
 static int
 pmServerExec(int fd, int livemode)
 {
diff --git a/src/perl/MMV/GNUmakefile b/src/perl/MMV/GNUmakefile
index 1fc485d..239377d 100644
--- a/src/perl/MMV/GNUmakefile
+++ b/src/perl/MMV/GNUmakefile
@@ -55,7 +55,7 @@ include $(BUILDRULES)
 install: default
 ifneq "$(PACKAGE_DISTRIBUTION)" "debian"
    $(call PERL_GET_FILELIST,$(TOPDIR)/perl-pcp-mmv.list,MMV)
-   find $$DIST_ROOT -name server.pl -exec chmod 755 '{}' ';'
+#  find $$DIST_ROOT -name server.pl -exec chmod 755 '{}' ';'
 endif

 install_perl:
diff --git a/src/pmdas/pmcd/src/pmcd.c b/src/pmdas/pmcd/src/pmcd.c
index 2271d16..b6e36c2 100644
--- a/src/pmdas/pmcd/src/pmcd.c
+++ b/src/pmdas/pmcd/src/pmcd.c
@@ -1022,7 +1022,7 @@ simabi()
     } else {
    return abi;
     }
-#elif defined(IS_FREEBSD) || defined(IS_NETBSD)
+#elif defined(IS_FREEBSD) || defined(IS_NETBSD) || defined(IS_OPENBSD)
     return "elf";
 #elif defined(IS_DARWIN)
     return "Mach-O " SIM_ABI;
diff --git a/src/pmdas/root/root.c b/src/pmdas/root/root.c
index 0be0af2..48b152f 100644
--- a/src/pmdas/root/root.c
+++ b/src/pmdas/root/root.c
@@ -32,6 +32,11 @@
 #define S_IRWXU 0700
 #endif

+/* OpenBSD doesn't have EPROTO */
+#ifndef EPROTO
+#define EPROTO EINTR
+#endif
+
 static char socket_path[MAXPATHLEN];
 static __pmSockAddr *socket_addr;
 static int socket_fd = -1;
diff --git a/src/pmdas/shping/shping.c b/src/pmdas/shping/shping.c
index f14be03..a184b6b 100644
--- a/src/pmdas/shping/shping.c
+++ b/src/pmdas/shping/shping.c
@@ -210,7 +210,7 @@ refresh(void *dummy)
     prctl(PR_TERMCHILD);           /* SIGHUP when the parent dies */
 #elif defined (PR_SET_PDEATHSIG)
     prctl(PR_SET_PDEATHSIG, SIGTERM);
-#elif defined(IS_SOLARIS) || defined(IS_DARWIN) || defined(IS_MINGW) || defined(IS_AIX) || defined(IS_FREEBSD) || defined(IS_GNU) || defined(IS_NETBSD)
+#elif defined(IS_SOLARIS) || defined(IS_DARWIN) || defined(IS_MINGW) || defined(IS_AIX) || defined(IS_FREEBSD) || defined(IS_GNU) || defined(IS_NETBSD) || defined(IS_OPENBSD)
     /* no signals here for child exit */
 #else
 !bozo: cant decide between PR_TERMCHILD and PR_SET_PDEATHSIG
Contributor

natoscott commented Feb 15, 2016

I'm not really a developer so I'm asking before pull request? How to handle in better way EPROTO? > It seems odd to have ifndef in couple of files?

@jirib defining it in src/include/pcp/config.h.in is the way to go - for example, see the EHOSTDOWN/ENODATA missing-error-code definitions there for Windows.

From scanning the available error codes here:
http://fxr.watson.org/fxr/source/sys/errno.h?v=OPENBSD

and looking at the places EPROTO is used, I'd suggest a better match (than EINTR) would be:
#define ENOPROTOOPT 42 /* Protocol not available */

| (Otherwise with diffs below I could build pcp on OpenBSD. Just build, I have to learn how to use it :) )

Good stuff! You might find the quick reference guide useful for getting a quick, practical introduction:
http://www.pcp.io/docs/guide.html

Contributor

kmcdonell commented Feb 16, 2016

Just a status update. The patches above are a start for an OpenBSD port, but they're not the whole story ... I have code base building now for OpenBSD and will post commits within a day or so.

Contributor

kmcdonell commented Feb 19, 2016

Latest commits resolve not only the EPROTO issue but a bunch of other porting issues that enable PCP to now build and run on OpenBSD ... so closing this issue.

@kmcdonell kmcdonell closed this Feb 19, 2016

@kpcyrd kpcyrd referenced this issue in erickt/rust-zmq Mar 12, 2017

Closed

Fail to build on openbsd #170

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment