erlang and freebsd [large]

Jimmy Olgeni <>
Sat Mar 16 21:08:54 CET 2002


Hello everybody.

I made some patches to update the Erlang port in the FreeBSD ports
collection to R8B. Some of them may be useful outside FreeBSD too, or
maybe they can be integrated in the official release to avoid having
lots of small patches to update at every release.

Lots of these patches where already in the Erlang port. If I remember
correctly, FreeBSD support for os_mon came from Samuel Tardieu. Some
other stuff came from previous maintainers :o)



The following patches add support for INSTALL_SCRIPT, to be used for
installing scripts. INSTALL_PROGRAM causes install to "strip" the script
like an executable, and fail. I don't know if this applies to other OSs
too.

=== patch-ab ===

--- lib/inets/priv/Makefile.orig	Tue Nov 28 20:38:31 2000
+++ lib/inets/priv/Makefile	Tue Nov 28 20:38:38 2000
@@ -57,7 +57,7 @@

 release_spec: opt
 	$(INSTALL_DIR) $(RELSYSDIR)/priv/bin
-	$(INSTALL_PROGRAM) $(EXECUTABLES) $(RELSYSDIR)/priv/bin
+	$(INSTALL_SCRIPT) $(EXECUTABLES) $(RELSYSDIR)/priv/bin

 release_docs_spec:

# End



=== patch-ac ===

--- erts/etc/common/Makefile.in.orig	Tue Nov 28 20:41:14 2000
+++ erts/etc/common/Makefile.in	Tue Nov 28 20:46:05 2000
@@ -65,6 +65,7 @@
 INSTALL         = @INSTALL@
 INSTALL_DIR     = $(INSTALL) -d
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT  = @INSTALL_SCRIPT@
 INSTALL_DATA    = @INSTALL_DATA@

 ifeq ($(findstring solaris,$(TARGET)),solaris)
@@ -238,13 +239,13 @@
 endif
 	$(INSTALL_DIR) $(RELEASE_PATH)/erts-$(VSN)/bin
 ifneq ($(findstring vxworks,$(TARGET)), vxworks)
-	$(INSTALL_PROGRAM) erl.src $(RELEASE_PATH)/erts-$(VSN)/bin
+	$(INSTALL_SCRIPT) erl.src $(RELEASE_PATH)/erts-$(VSN)/bin
 endif
 	$(INSTALL_PROGRAM) $(INSTALL_PROGS) $(RELEASE_PATH)/erts-$(VSN)/bin
-	$(INSTALL_PROGRAM) $(INSTALL_TOP) $(RELEASE_PATH)
+	$(INSTALL_SCRIPT) $(INSTALL_TOP) $(RELEASE_PATH)
 ifneq ($(INSTALL_MISC),)
 	$(INSTALL_DIR) $(RELEASE_PATH)/misc
-	$(INSTALL_PROGRAM) $(INSTALL_MISC) $(RELEASE_PATH)/misc
+	$(INSTALL_SCRIPT) $(INSTALL_MISC) $(RELEASE_PATH)/misc
 endif
 ifneq ($(INSTALL_SRC),)
 	$(INSTALL_DIR) $(RELEASE_PATH)/erts-$(VSN)/src



=== patch-ak ===

--- lib/inets/examples/Makefile.orig	Tue Nov 28 20:35:48 2000
+++ lib/inets/examples/Makefile	Tue Nov 28 20:36:24 2000
@@ -176,7 +176,7 @@
 	$(INSTALL_DIR) $(RELSYSDIR)/examples/server_root/auth
 	$(INSTALL_DATA) $(AUTH_FILES) $(RELSYSDIR)/examples/server_root/auth
 	$(INSTALL_DIR) $(RELSYSDIR)/examples/server_root/cgi-bin
-	$(INSTALL_PROGRAM) $(CGI_FILES) $(RELSYSDIR)/examples/server_root/cgi-bin
+	$(INSTALL_SCRIPT) $(CGI_FILES) $(RELSYSDIR)/examples/server_root/cgi-bin
 	$(INSTALL_DIR) $(RELSYSDIR)/examples/server_root/conf
 	$(INSTALL_DATA) $(CONF_FILES) $(RELSYSDIR)/examples/server_root/conf
 	$(INSTALL_DIR) $(RELSYSDIR)/examples/server_root/htdocs/open



=== patch-am ===

--- lib/mnesia/examples/Makefile.orig	Sun Dec  2 19:00:59 2001
+++ lib/mnesia/examples/Makefile	Sun Dec  2 19:01:32 2001
@@ -95,7 +95,7 @@
           bench.config6 \
           bench.config7 \
           $(RELSYSDIR)/examples/bench)
-	(cd bench; $(INSTALL_PROGRAM) bench.sh $(RELSYSDIR)/examples/bench)
+	(cd bench; $(INSTALL_SCRIPT) bench.sh $(RELSYSDIR)/examples/bench)

 release_docs_spec:



=== patch-ao ===

--- make/otp.mk.in.orig	Fri Dec  7 17:59:22 2001
+++ make/otp.mk.in	Fri Dec  7 17:59:32 2001
@@ -41,6 +41,7 @@
 INSTALL = @INSTALL@
 INSTALL_DIR = @INSTALL_DIR@
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_DATA = @INSTALL_DATA@

 CC = @CC@



These patches add FreeBSD support to os_mon.

=== patch-af ===

--- lib/os_mon/c_src/Makefile.in.orig	Tue Nov 23 16:14:47 1999
+++ lib/os_mon/c_src/Makefile.in	Sat Dec  2 22:35:09 2000
@@ -53,6 +53,7 @@
 PROGRAMS = \
 	memsup @os_mon_programs@
 C_FILES= $(PROGRAMS:%=%.c)
+LKSTAT=	@os_mon_kstat@
 endif

 TARGET_FILES= $(PROGRAMS:%=$(BINDIR)/%)
@@ -97,7 +98,7 @@
 	$(LD) $(LDFLAGS) -o $@ $<

 $(BINDIR)/cpu_sup: $(OBJDIR)/cpu_sup.o
-	$(LD) $(LDFLAGS) -o $@ $< -lkstat
+	$(LD) $(LDFLAGS) -o $@ $< $(LKSTAT)

 $(OBJDIR)/%.o: %.c
 	$(CC) -c -o $@ $(ALL_CFLAGS) $<



=== patch-ag ===

--- lib/os_mon/c_src/memsup.c.orig	Mon Sep 20 23:05:24 1999
+++ lib/os_mon/c_src/memsup.c	Sat Dec  2 22:23:25 2000
@@ -89,6 +89,12 @@
 #include <ioLib.h>
 #include <memLib.h>
 #endif
+#ifdef __FreeBSD__
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/vmmeter.h>
+#include <vm/vm_param.h>
+#endif

 /* commands */
 #include "memsup.h"
@@ -172,6 +178,16 @@
     load_statistics();
     *tot = (latest.numBytesFree + latest.numBytesAlloc) >> shiftleft;
     *used = latest.numBytesAlloc >> shiftleft;
+#elif defined(__FreeBSD__)
+    int mib[2];
+    size_t len;
+    struct vmtotal memory;
+    mib[0] = CTL_VM;
+    mib[1] = VM_METER;
+    len = sizeof memory;
+    sysctl(mib, 2, &memory, &len, NULL, 0);
+    *tot = memory.t_vm >> shiftleft;
+    *used = memory.t_avm >> shiftleft;
 #elif defined(_SC_AVPHYS_PAGES)	/* Does this exist on others than Solaris2? */
     unsigned long avPhys, phys, pgSz;

# End



=== patch-ah ===

--- lib/os_mon/c_src/cpu_sup.c.orig	Sat Dec  2 22:12:38 2000
+++ lib/os_mon/c_src/cpu_sup.c	Sat Dec  2 22:47:11 2000
@@ -26,7 +26,14 @@
  */

 #include<stdio.h>
+#ifdef __FreeBSD__
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/param.h>
+#include <sys/user.h>
+#else
 #include<kstat.h>
+#endif

 #define FD_IN    0
 #define FD_OUT   1
@@ -45,20 +52,23 @@
 static void send(unsigned int data);
 static void error(char* err_msg);

+#ifndef __FreeBSD__
 static kstat_ctl_t *kc;
 static kstat_t *ks;
+#endif

 int main(int argc, char** argv) {
-  kid_t kid;
   char cmd;
   int rc;
+#ifndef __FreeBSD__
+  kid_t kid;

   kc = kstat_open();
   if(!kc) error("Can't open header kstat");

   ks = kstat_lookup(kc,"unix",0,"system_misc");
   if(!ks) error("Can't open system_misc kstat");
-
+#endif

   while(1) {
     rc = read(FD_IN, &cmd, sizeof(cmd));
@@ -79,6 +89,32 @@
 }

 static unsigned int measure(char* name) {
+#ifdef __FreeBSD__
+  size_t len;
+  int mib[3];
+  if (!strcmp (name, "nproc")) {
+    mib[0] = CTL_KERN;
+    mib[1] = KERN_PROC;
+    mib[2] = KERN_PROC_ALL;
+    sysctl(mib, 3, NULL, &len, NULL, 0);
+    return len/sizeof(struct kinfo_proc);
+  } else {
+    struct loadavg load;
+    mib[0] = CTL_VM;
+    mib[1] = VM_LOADAVG;
+    len = sizeof load;
+    sysctl(mib, 2, &load, &len, NULL, 0);
+    if (!strcmp (name, "avenrun_1min")) {
+      return load.ldavg[0] * 256 / load.fscale;
+    } else if (!strcmp (name, "avenrun_5min")) {
+      return load.ldavg[1] * 256 / load.fscale;
+    } else if (!strcmp (name, "avenrun_15min")) {
+      return load.ldavg[2] * 256 / load.fscale;
+    } else {
+      return -1;
+    }
+  }
+#else
   kstat_named_t* entry;

   kstat_read(kc,ks,NULL);
@@ -90,6 +126,7 @@
     return -1;

   return entry->value.ul;
+#endif
 }

 static void send(unsigned int data) {



=== patch-ai ===

--- lib/os_mon/c_src/ferrule.c.orig	Sat Dec  2 22:13:49 2000
+++ lib/os_mon/c_src/ferrule.c	Sat Dec  2 22:14:03 2000
@@ -17,7 +17,9 @@
  */
 #include 	<stdio.h>
 #include 	<string.h>
+#ifndef __FreeBSD__
 #include 	<stropts.h>
+#endif
 #include 	<poll.h>
 #include 	<unistd.h>
 #include 	<sys/types.h>


This will also detect strerror_r, which is now present in FreeBSD and must
not be defined.

=== patch-an ===

--- erts/configure.in.orig	Mon Oct  8 10:36:08 2001
+++ erts/configure.in	Sun Jan 20 16:06:23 2002
@@ -436,7 +436,7 @@
 dnl ----------------------------------------------------------------------

 AC_CHECK_FUNCS([ieee_handler fpsetmask finite res_gethostbyname dlopen \
-		poll pread pwrite writev memmove strerror strncasecmp \
+		poll pread pwrite writev memmove strerror strerror_r strncasecmp \
 		gethrtime localtime_r gmtime_r mremap memcpy mallopt])
 AC_FUNC_SETVBUF_REVERSED
 AC_FUNC_VFORK
@@ -886,10 +886,13 @@
 # Os mon stuff.
 #--------------------------------------------------------------------
 AC_SUBST(os_mon_programs)
-AC_CHECK_LIB(kstat, kstat_open, [os_mon_programs="$os_mon_programs cpu_sup"])
+AC_SUBST(os_mon_kstat)
+AC_CHECK_LIB(kstat, kstat_open, [os_mon_kstat="-lkstat", os_mon_programs="$os_mon_programs cpu_sup"])
 case $host_os in
 	solaris2*)
 		os_mon_programs="$os_mon_programs ferrule mod_syslog" ;;
+	freebsd*)
+		os_mon_programs="$os_mon_programs cpu_sup ferrule mod_syslog" ;;
 esac


This fixes a bug in the configuration script. Due to a ./configure
recursion bug, Erlang tries to install using INSTALL=../../../../../...,
which will fail :o)

This used to be a bug in older autoconf releases (at least google said so).

=== post-patch-configure ===

--- configure.orig	Fri Dec  7 16:13:39 2001
+++ configure	Fri Dec  7 16:19:33 2001
@@ -1081,6 +1081,7 @@
       *) # Relative path.
         ac_sub_cache_file="$ac_dots$cache_file" ;;
       esac
+  ac_given_INSTALL="$INSTALL"
   case "$ac_given_INSTALL" in
         [/$]*) INSTALL="$ac_given_INSTALL" ;;
         *) INSTALL="$ac_dots$ac_given_INSTALL" ;;

This one fixes a syntax error when there's more than one lib/sasl*
directory.

=== patch-aj ===

--- ./erts/etc/unix/Install.src.orig	Wed Jan 17 17:18:57 2001
+++ ./erts/etc/unix/Install.src	Wed Jan 17 17:35:40 2001
@@ -97,7 +97,8 @@
   chmod 755 start_erl
 fi

-if [ -d $ERL_ROOT/lib/sasl* ]
+set $ERL_ROOT/lib/sasl*
+if [ -d $1 ]
 then
     (cd $ERL_ROOT/releases
      echo %I_VSN% %I_SYSTEM_VSN% > start_erl.data)
@@ -171,4 +172,4 @@
     ./misc/format_man_pages $ERL_ROOT
 fi

-
+exit 0


If you have any questions just drop me a note, I don't have a clue but I'll
try to help :o)

--
jimmy






More information about the erlang-questions mailing list